~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

Viewing changes to debian/clamav-milter.init.in

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-07-15 01:08:10 UTC
  • mfrom: (0.35.47 sid)
  • Revision ID: package-import@ubuntu.com-20140715010810-ru66ek4fun2iseba
Tags: 0.98.4+dfsg-2~ubuntu13.10.1
No-change backport to saucy (LP: #1341962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
# Description:       Clam AntiVirus milter interface
12
12
### END INIT INFO
13
13
 
 
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
 
16
 
14
17
PATH=/sbin:/bin:/usr/sbin:/usr/bin
15
18
DAEMON=/usr/sbin/clamav-milter
16
19
DESC="Sendmail milter plugin for ClamAV"
17
20
NAME=clamav-milter
18
21
CLAMAVCONF=/etc/clamav/clamav-milter.conf
19
22
SUPERVISOR=/usr/bin/daemon
 
23
SUPERVISORNAME=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"
23
26
 
 
27
# required by Debian policy 9.3.2
24
28
[ -x "$DAEMON" ] || exit 0
25
29
 
26
30
#COMMON-FUNCTIONS#
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'"
37
 
  exit 0
 
41
  if [ "$1" = "status" ]; then
 
42
    # program or service status is unknown
 
43
    exit 4;
 
44
  else
 
45
    # program is not configured
 
46
    exit 6;
 
47
  fi
38
48
fi
39
49
 
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'"
46
 
  exit 0
47
 
fi
48
 
 
49
 
if [ -z "$PidFile" ]; then
50
 
  PIDFILE=/var/run/clamav/clamav-milter.pid
51
 
else
52
 
  PIDFILE="$PidFile"
53
 
fi
54
 
 
55
 
if [ -z "$MilterSocket" ]; then
56
 
  SOCKET=local:/var/run/clamav/clamav-milter.ctl
57
 
else
58
 
  SOCKET="$MilterSocket"
 
56
  if [ "$1" = "status" ]; then
 
57
    # program or service status is unknown
 
58
    exit 4;
 
59
  else
 
60
    # program is not configured
 
61
    exit 6;
 
62
  fi
 
63
fi
 
64
 
 
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
 
70
      exit 4;
 
71
    else
 
72
      # program is not configured correctly
 
73
      exit 6;
 
74
    fi
 
75
  else
 
76
     RUN_SUPERVISED=1
 
77
  fi
 
78
fi
 
79
 
 
80
 
 
81
if [ -z "$RUN_SUPERVISED" ]; then
 
82
        THEPIDFILE="$PidFile"
 
83
        THEDAEMON="$NAME"
 
84
        RELOAD="1"
 
85
else
 
86
        THEPIDFILE="$SUPERVISORPIDFILE"
 
87
        THEDAEMON="$SUPERVISORNAME"
 
88
        RELOAD="0"
 
89
fi
 
90
 
 
91
if [ -z "$THEPIDFILE" ]
 
92
then
 
93
  log_failure_msg "$NAME: Can not continue with PidFile not set"
 
94
  if [ "$1" = "status" ]; then
 
95
    # program or service status is unknown
 
96
    exit 4;
 
97
  else
 
98
    # program is not configured correctly
 
99
    exit 6;
 
100
  fi
 
101
fi
 
102
 
 
103
if [ -z "$MilterSocket" ]
 
104
then
 
105
  log_failure_msg "$NAME: Can not continue with MilterSocket not set"
 
106
  if [ "$1" = "status" ]; then
 
107
    # program or service status is unknown
 
108
    exit 4;
 
109
  else
 
110
    # program is not configured correctly
 
111
    exit 6;
 
112
  fi
 
113
fi
 
114
 
 
115
if [ ! -f "$THEPIDFILE" ]
 
116
then
 
117
        touch "$THEPIDFILE"
 
118
        chown $User "$THEPIDFILE"
59
119
fi
60
120
 
61
121
wait_for_socket()
88
148
  fi
89
149
}
90
150
 
91
 
case "$SOCKET" in
 
151
case "$MilterSocket" in
92
152
  /*)
93
 
  SOCKET_PATH="$SOCKET"
 
153
  SOCKET_PATH="$MilterSocket"
94
154
  SOCKET_TYPE="local"
95
155
  ;;
96
156
  *)
97
 
  SOCKET_PATH="${SOCKET#*:}"
98
 
  SOCKET_TYPE="${SOCKET%%:*}"
 
157
  SOCKET_PATH="${MilterSocket#*:}"
 
158
  SOCKET_TYPE="${MilterSocket%%:*}"
99
159
  ;;
100
160
esac
101
161
SOCKET_TYPE="${SOCKET_TYPE:-local}"
102
162
SOCKET="${SOCKET_TYPE}:${SOCKET_PATH}"
103
163
 
104
 
if is_true "$Foreground"; then
105
 
  if [ ! -x "$SUPERVISOR" ] ; then
106
 
     log_failure_msg "Foreground specified, but $SUPERVISOR not found"
107
 
     exit 0
108
 
  else
109
 
     RUN_SUPERVISED=1
110
 
     SUPERVISOR_EXEC="$DAEMON $OPTIONS"
111
 
  fi
112
 
fi
113
 
 
114
 
if [ -z "$RUN_SUPERVISED" ] ; then
115
 
  if [ -f "$PIDFILE" ]; then
116
 
    PID=`pidofproc -p $PIDFILE $DAEMON`
117
 
    RUNNING=$?
118
 
  else
119
 
    PID=`pidofproc $DAEMON`
120
 
    RUNNING=$?
121
 
  fi
122
 
else
123
 
  [ -e "$SUPERVISORPIDFILE" ] && PID=`sed 's/[^0-9]//g' $SUPERVISORPIDFILE`
124
 
fi
125
 
 
126
 
[ "$PID" = '1' ] && unset PID
127
164
[ -n "$User" ] || User=clamav
128
165
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav
129
166
 
133
170
  chown $User $(dirname "$SOCKET_PATH")
134
171
fi
135
172
 
136
 
make_dir $(dirname "$PIDFILE")
137
 
chown $User $(dirname "$PIDFILE")
 
173
make_dir $(dirname "$THEPIDFILE")
 
174
if [ ! -f "$THEPIDFILE" ]
 
175
then
 
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
 
178
        # able to kill it.
 
179
        touch $THEPIDFILE
 
180
        chown $User $THEPIDFILE
 
181
fi
138
182
 
139
183
case "$1" in
140
184
  start)
141
 
  OPTIND=1
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"
146
 
      exit 1
147
 
    fi
148
 
  fi
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"
152
 
    exit 0
153
 
  fi
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
157
188
    ret=$?
158
189
  else
159
190
    log_daemon_msg "Starting $DESC" "$NAME (supervised)"
160
 
    $SUPERVISOR $SUPERVISORARGS -X "$SUPERVISOR_EXEC"
 
191
    $SUPERVISOR $SUPERVISORARGS
161
192
    ret=$?
162
193
  fi
163
194
 
167
198
  log_end_msg $ret
168
199
  ;;
169
200
  stop)
170
 
  OPTIND=1
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
175
 
    ret=$?
176
 
    sleep 2
177
 
    if kill -0 "$PID" 2>/dev/null; then 
178
 
      ret=$?
179
 
      log_progress_msg "Waiting . "
180
 
      cnt=0
181
 
      while kill -0 "$PID" 2>/dev/null; do
182
 
        ret=$?
183
 
        cnt=`expr "$cnt" + 1`
184
 
        if [ "$cnt" -gt 15 ]; then
185
 
          kill -9 -"$PID"
186
 
          ret=$?
187
 
          break
188
 
        fi
189
 
        sleep 2
190
 
        log_progress_msg ". "
191
 
      done
192
 
    fi
193
 
  else
194
 
    if [ -z "$RUN_SUPERVISED" ] ; then
195
 
      killproc -p $PIDFILE $DAEMON
196
 
      ret=$?
197
 
    else
198
 
      killproc -p $SUPERVISORPIDFILE
199
 
      ret=$?
200
 
    fi
201
 
  fi
202
 
  if [ -n "$ret" ]; then
203
 
    log_end_msg $ret
204
 
  else
205
 
    log_end_msg $?
206
 
  fi
 
202
  start-stop-daemon --stop --oknodo --name $THEDAEMON --pidfile $THEPIDFILE --retry TERM/30/KILL/5
 
203
  log_end_msg $?
207
204
  [ -e "$SOCKET_PATH" ] && rm -f $SOCKET_PATH
208
 
  [ -e "$PIDFILE" ] && rm -f $PIDFILE
209
205
  ;;
210
206
  force-reload | restart)
211
207
  $0 stop
213
209
  $0 start
214
210
  ;;
215
211
  status)
216
 
  status_of_proc "$DAEMON" "$NAME"
217
 
  ret=$?
218
 
  if [ $ret = 0 ] && [ ! -S $SOCKET_PATH ] ; then
219
 
    log_failure_msg "$NAME is running but socket is missing"
220
 
    exit 4
 
212
  start-stop-daemon --status --name $THEDAEMON --pidfile $THEPIDFILE
 
213
  # start-stop-daemon returns LSB compliant exit status codes
 
214
  ret="$?"
 
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
 
219
                exit 4
 
220
        fi
 
221
        log_success_msg "$NAME is running"
 
222
  else
 
223
        log_failure_msg "$NAME is not running"
 
224
        exit "$ret"
221
225
  fi
222
 
  exit $ret
223
226
  ;;
224
227
  *)
225
 
  log_failure_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2
226
 
  exit 1
 
228
  log_action_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2
 
229
  # invalid arguments
 
230
  exit 2
227
231
  ;;
228
232
esac
229
233