11
11
# Description: Clam AntiVirus milter interface
14
# The exit status codes should comply with LSB.
15
# https://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
14
17
PATH=/sbin:/bin:/usr/sbin:/usr/bin
15
18
DAEMON=/usr/sbin/clamav-milter
16
19
DESC="Sendmail milter plugin for ClamAV"
18
21
CLAMAVCONF=/etc/clamav/clamav-milter.conf
19
22
SUPERVISOR=/usr/bin/daemon
20
24
SUPERVISORPIDFILE="/var/run/clamav/daemon-clamav-milter.pid"
21
SUPERVISORARGS="-F $SUPERVISORPIDFILE --name=$NAME --respawn"
22
CLAMAVDAEMONUPGRADE="/var/run/clamav-daemon-being-upgraded"
25
SUPERVISORARGS="--name=$NAME --respawn $DAEMON -F $SUPERVISORPIDFILE"
27
# required by Debian policy 9.3.2
24
28
[ -x "$DAEMON" ] || exit 0
34
38
log_failure_msg "Please either dpkg-reconfigure $DESC, or copy the example from"
35
39
log_failure_msg "/usr/share/doc/clamav-milter/examples/ to $CLAMAVCONF and run"
36
40
log_failure_msg "'/etc/init.d/clamav-milter start'"
41
if [ "$1" = "status" ]; then
42
# program or service status is unknown
45
# program is not configured
40
50
slurp_config "$CLAMAVCONF"
43
53
if [ -n "$Example" ]; then
44
54
log_failure_msg "$DESC is not configured."
45
55
log_failure_msg "Please edit $CLAMAVCONF and run '/etc/init.d/clamav-milter start'"
49
if [ -z "$PidFile" ]; then
50
PIDFILE=/var/run/clamav/clamav-milter.pid
55
if [ -z "$MilterSocket" ]; then
56
SOCKET=local:/var/run/clamav/clamav-milter.ctl
58
SOCKET="$MilterSocket"
56
if [ "$1" = "status" ]; then
57
# program or service status is unknown
60
# program is not configured
65
if is_true "$Foreground"; then
66
if [ ! -x "$SUPERVISOR" ] ; then
67
log_failure_msg "Foreground specified, but $SUPERVISOR not found"
68
if [ "$1" = "status" ]; then
69
# program or service status is unknown
72
# program is not configured correctly
81
if [ -z "$RUN_SUPERVISED" ]; then
86
THEPIDFILE="$SUPERVISORPIDFILE"
87
THEDAEMON="$SUPERVISORNAME"
91
if [ -z "$THEPIDFILE" ]
93
log_failure_msg "$NAME: Can not continue with PidFile not set"
94
if [ "$1" = "status" ]; then
95
# program or service status is unknown
98
# program is not configured correctly
103
if [ -z "$MilterSocket" ]
105
log_failure_msg "$NAME: Can not continue with MilterSocket not set"
106
if [ "$1" = "status" ]; then
107
# program or service status is unknown
110
# program is not configured correctly
115
if [ ! -f "$THEPIDFILE" ]
118
chown $User "$THEPIDFILE"
151
case "$MilterSocket" in
153
SOCKET_PATH="$MilterSocket"
94
154
SOCKET_TYPE="local"
97
SOCKET_PATH="${SOCKET#*:}"
98
SOCKET_TYPE="${SOCKET%%:*}"
157
SOCKET_PATH="${MilterSocket#*:}"
158
SOCKET_TYPE="${MilterSocket%%:*}"
101
161
SOCKET_TYPE="${SOCKET_TYPE:-local}"
102
162
SOCKET="${SOCKET_TYPE}:${SOCKET_PATH}"
104
if is_true "$Foreground"; then
105
if [ ! -x "$SUPERVISOR" ] ; then
106
log_failure_msg "Foreground specified, but $SUPERVISOR not found"
110
SUPERVISOR_EXEC="$DAEMON $OPTIONS"
114
if [ -z "$RUN_SUPERVISED" ] ; then
115
if [ -f "$PIDFILE" ]; then
116
PID=`pidofproc -p $PIDFILE $DAEMON`
119
PID=`pidofproc $DAEMON`
123
[ -e "$SUPERVISORPIDFILE" ] && PID=`sed 's/[^0-9]//g' $SUPERVISORPIDFILE`
126
[ "$PID" = '1' ] && unset PID
127
164
[ -n "$User" ] || User=clamav
128
165
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav
133
170
chown $User $(dirname "$SOCKET_PATH")
136
make_dir $(dirname "$PIDFILE")
137
chown $User $(dirname "$PIDFILE")
173
make_dir $(dirname "$THEPIDFILE")
174
if [ ! -f "$THEPIDFILE" ]
176
# If clam is run under a different UID than milter then we need
177
# to make sure the THEPIDFILE can be written or else we won't be
180
chown $User $THEPIDFILE
142
if [ -n "$PID" ]; then
143
PID=`echo $PID | sed 's/[^0-9]//g'`
144
if kill -0 $PID; then
145
log_failure_msg "$DAEMON already running"
149
if [ -e "$CLAMAVDAEMONUPGRADE" ] && [ "$RESTART_AFTER_CLAMD" = 'yes' ]; then
150
touch $CLAMAVDAEMONUPGRADE.milter-restart
151
log_warning_msg "clamd may be required to run $DAEMON, clamav-milter will be restarted by clamav-daemon"
154
185
if [ -z "$RUN_SUPERVISED" ] ; then
155
186
log_daemon_msg "Starting $DESC" "$NAME"
156
start-stop-daemon --start -o -c $User --exec $DAEMON
187
start-stop-daemon --start --oknodo -c $User --exec $DAEMON --pidfile $THEPIDFILE -- --config-file=$CLAMAVCONF
159
190
log_daemon_msg "Starting $DESC" "$NAME (supervised)"
160
$SUPERVISOR $SUPERVISORARGS -X "$SUPERVISOR_EXEC"
191
$SUPERVISOR $SUPERVISORARGS
171
201
log_daemon_msg "Stopping $DESC" "$NAME"
172
if [ -n "$PID" ]; then
173
PID=`echo $PID | sed 's/[^0-9]//g'`
174
kill -15 -"$PID" 2>/dev/null || true
177
if kill -0 "$PID" 2>/dev/null; then
179
log_progress_msg "Waiting . "
181
while kill -0 "$PID" 2>/dev/null; do
183
cnt=`expr "$cnt" + 1`
184
if [ "$cnt" -gt 15 ]; then
190
log_progress_msg ". "
194
if [ -z "$RUN_SUPERVISED" ] ; then
195
killproc -p $PIDFILE $DAEMON
198
killproc -p $SUPERVISORPIDFILE
202
if [ -n "$ret" ]; then
202
start-stop-daemon --stop --oknodo --name $THEDAEMON --pidfile $THEPIDFILE --retry TERM/30/KILL/5
207
204
[ -e "$SOCKET_PATH" ] && rm -f $SOCKET_PATH
208
[ -e "$PIDFILE" ] && rm -f $PIDFILE
210
206
force-reload | restart)
216
status_of_proc "$DAEMON" "$NAME"
218
if [ $ret = 0 ] && [ ! -S $SOCKET_PATH ] ; then
219
log_failure_msg "$NAME is running but socket is missing"
212
start-stop-daemon --status --name $THEDAEMON --pidfile $THEPIDFILE
213
# start-stop-daemon returns LSB compliant exit status codes
215
if [ "$ret" = 0 ]; then
216
if [ "$SOCKET_TYPE" = "local" ] && [ ! -S $SOCKET_PATH ] ; then
217
log_failure_msg "$NAME is running but socket is missing"
218
# service status is unknown
221
log_success_msg "$NAME is running"
223
log_failure_msg "$NAME is not running"
225
log_failure_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2
228
log_action_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2