3 # amavisd-cn /etc/init.d/ initscript wrapper for CARNetized amavisd-new
5 # Start and stop Amavis, ClamAV and Postfix/Sendmail
9 # Required-Start: $local_fs $remote_fs $syslog $named $network $time
10 # Required-Stop: $local_fs $remote_fs $syslog $named $network
13 # Default-Start: 2 3 4 5
15 # Short-Description: start and stop Amavis, ClamAV and Postfix/Sendmail
16 # Description: wrapper for starting/stopping MTA and related services
21 # options for daemons:
22 # name init.d/script user ps name for pgrep -f pidfile, relative to /var/run num-fds last-fd-name
24 clamd clamav-daemon clamav /usr/sbin/clamd clamav/clamd.pid 5 clamav.log
25 amavis amavis.amavisd-new amavis amavisd \\(master\\) amavis/amavisd.pid 5 socket
27 # note: pgrep -f takes a regexp, and this is shell expanded once, hence \\
30 local daemon IFSOLD name script user psname pidfile num fdname
34 read name script user psname pidfile num fdname <<-EOPTS
35 $(echo "$options" | sed 's/ */ /g' | grep ^$daemon)
38 /etc/init.d/$script start
39 wait_for_fds "$daemon"
43 local daemon IFSOLD name script user psname pidfile num fdname
48 read name script user psname pidfile num fdname <<-EOPTS
49 $(echo "$options" | sed 's/ */ /g' | grep ^$daemon)
52 /etc/init.d/$script stop
53 pkill -u $user -f "$psname" > /dev/null || true
54 while pgrep -u $user -f "$psname" > /dev/null && [ "$n" -gt 0 ]
59 pkill -9 -u $user -f "$psname" > /dev/null || true
60 #pkill -9 -u $user -x "$daemon"
61 if pgrep -u $user -f "$psname" > /dev/null; then # still there?
67 # wait until process shows some I/O readiness :)
68 local name IFSOLD num sleep maxtry script user psname pidfile fdname
70 [ -z "$name" ] && return 1
73 read name script user psname pidfile num fdname <<-EOPTS
74 $(echo "$options" | sed 's/ */ /g' | grep ^$name)
80 if [ -n "$pidfile" ]; then
81 pidfile=/var/run/$pidfile
82 findpid="[ -f $pidfile ] && cat $pidfile || true"
84 findpid="pgrep -u $user -f \"$psname\" -P 1 | head -1"
87 # loop the loop the loop
91 sleep $sleep # 1st, give it a chance to run
92 pid=`eval $findpid` # 2nd: find it
93 if [ ! -z "$pid" ]; then
94 count=`ls -1 /proc/$pid/fd 2>/dev/null| wc -l` # 3rd: count all it's worth
95 [ "$count" -ge "$num" ] && ls -l /proc/$pid/fd | grep -q $fdname \
96 && return # success -- release
99 [ "0$try" -ge "0$maxtry" ] && return 1 # no luck this time
103 # if we're called as amavisd-cn or amavis with start argument,
104 # act like one; otherwise, pass the call down
105 case "$(basename $0)" in
110 if [ "$1" = start ]; then
121 # If there's no diversion, play possum
122 [ -x /etc/init.d/amavis.amavisd-new ] || exit 0
127 start|stop|restart|reload|force-reload|debug)
128 /etc/init.d/amavis.amavisd-new "$arg"
134 if [ -x "/etc/init.d/$mta" ]; then
135 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
136 invoke-rc.d $mta start
138 /etc/init.d/$mta start
144 if [ -x "/etc/init.d/$mta" ]; then
145 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
146 invoke-rc.d $mta stop
148 /etc/init.d/$mta stop
155 irestart|ireload|iforce-reload)
162 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2