6 # name init.d/script user ps name for pgrep -f pidfile, relative to /var/run num-fds last-fd-name
8 clamd clamav-daemon clamav /usr/sbin/clamd clamav/clamd.pid 5 clamav.log
9 amavis amavis.amavisd-new amavis amavisd \\(master\\) amavis/amavisd.pid 5 socket
10 milter amavisd-new-milter amavis /usr/sbin/amavis-milter amavis/amavisd-new-milter.pid 5 socket
12 # note: pgrep -f takes a regexp, and this is shell expanded once, hence \\
15 local daemon IFSOLD name script user psname pidfile num fdname
19 read name script user psname pidfile num fdname <<-EOPTS
20 $(echo "$options" | sed 's/ */ /g' | grep ^$daemon)
23 /etc/init.d/$script start
24 wait_for_fds "$daemon"
28 local daemon IFSOLD name script user psname pidfile num fdname
33 read name script user psname pidfile num fdname <<-EOPTS
34 $(echo "$options" | sed 's/ */ /g' | grep ^$daemon)
37 /etc/init.d/$script stop
38 pkill -u $user -f "$psname" > /dev/null || true
39 while pgrep -u $user -f "$psname" > /dev/null && [ "$n" -gt 0 ]
44 pkill -9 -u $user -f "$psname" > /dev/null || true
45 #pkill -9 -u $user -x "$daemon"
46 if pgrep -u $user -f "$psname" > /dev/null; then # still there?
52 # wait until process shows some I/O readiness :)
53 local name IFSOLD num sleep maxtry script user psname pidfile fdname
55 [ -z "$name" ] && return 1
58 read name script user psname pidfile num fdname <<-EOPTS
59 $(echo "$options" | sed 's/ */ /g' | grep ^$name)
65 if [ -n "$pidfile" ]; then
66 pidfile=/var/run/$pidfile
67 findpid="[ -f $pidfile ] && cat $pidfile || true"
69 findpid="pgrep -u $user -f \"$psname\" -P 1 | head -1"
72 # loop the loop the loop
76 sleep $sleep # 1st, give it a chance to run
77 pid=`eval $findpid` # 2nd: find it
78 [ -z "$pid" ] && return 1 # not running at all
79 count=`ls -1 /proc/$pid/fd 2>/dev/null| wc -l` # 3rd: count all it's worth
80 [ "$count" -ge "$num" ] && ls -l /proc/$pid/fd | grep -q $fdname \
81 && return # success -- release
83 [ "0$try" -ge "0$maxtry" ] && return 1 # no luck this time
87 # if we're called as amavisd-cn or amavis with start argument,
88 # act like one; otherwise, pass the call down
89 case "$(basename $0)" in
94 if [ "$1" = start ]; then
105 # If there's no diversion, play possum
106 [ -x /etc/init.d/amavis.amavisd-new ] || exit 0
108 if [ -x /etc/init.d/postfix -a -x /usr/lib/postfix/master ]; then
115 start|stop|restart|reload|force-reload)
116 /etc/init.d/amavis.amavisd-new "$arg"
122 [ $mta = sendmail ] && start milter
123 /etc/init.d/$mta start
127 /etc/init.d/$mta stop
128 [ $mta = sendmail ] && stop milter
133 irestart|ireload|iforce-reload)
140 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2