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
11 # note: pgrep -f takes a regexp, and this is shell expanded once, hence \\
14 local daemon IFSOLD name script user psname pidfile num fdname
18 read name script user psname pidfile num fdname <<-EOPTS
19 $(echo "$options" | sed 's/ */ /g' | grep ^$daemon)
22 /etc/init.d/$script start
23 wait_for_fds "$daemon"
27 local daemon IFSOLD name script user psname pidfile num fdname
32 read name script user psname pidfile num fdname <<-EOPTS
33 $(echo "$options" | sed 's/ */ /g' | grep ^$daemon)
36 /etc/init.d/$script stop
37 pkill -u $user -f "$psname" > /dev/null || true
38 while pgrep -u $user -f "$psname" > /dev/null && [ "$n" -gt 0 ]
43 pkill -9 -u $user -f "$psname" > /dev/null || true
44 #pkill -9 -u $user -x "$daemon"
45 if pgrep -u $user -f "$psname" > /dev/null; then # still there?
51 # wait until process shows some I/O readiness :)
52 local name IFSOLD num sleep maxtry script user psname pidfile fdname
54 [ -z "$name" ] && return 1
57 read name script user psname pidfile num fdname <<-EOPTS
58 $(echo "$options" | sed 's/ */ /g' | grep ^$name)
64 if [ -n "$pidfile" ]; then
65 pidfile=/var/run/$pidfile
66 findpid="[ -f $pidfile ] && cat $pidfile || true"
68 findpid="pgrep -u $user -f \"$psname\" -P 1 | head -1"
71 # loop the loop the loop
75 sleep $sleep # 1st, give it a chance to run
76 pid=`eval $findpid` # 2nd: find it
77 if [ ! -z "$pid" ]; then
78 count=`ls -1 /proc/$pid/fd 2>/dev/null| wc -l` # 3rd: count all it's worth
79 [ "$count" -ge "$num" ] && ls -l /proc/$pid/fd | grep -q $fdname \
80 && 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
111 start|stop|restart|reload|force-reload|debug)
112 /etc/init.d/amavis.amavisd-new "$arg"
118 /etc/init.d/$mta start
122 /etc/init.d/$mta stop
127 irestart|ireload|iforce-reload)
134 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2