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

« back to all changes in this revision

Viewing changes to debian/clamav-daemon.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:
17
17
# Description:       Clam AntiVirus userspace daemon
18
18
### END INIT INFO
19
19
 
 
20
# The exit status codes should comply with LSB.
 
21
# https://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
 
22
 
20
23
PATH=/sbin:/bin:/usr/sbin:/usr/bin
21
24
DAEMON=/usr/sbin/clamd
22
25
NAME="clamd"
28
31
SUPERVISORARGS="--name=$NAME --respawn $DAEMON -F $SUPERVISORPIDFILE"
29
32
DATABASEDIR="/var/lib/clamav"
30
33
 
 
34
# required by Debian policy 9.3.2
31
35
[ -x "$DAEMON" ] || exit 0
32
36
[ -r /etc/default/clamav-daemon ] && . /etc/default/clamav-daemon
33
37
 
40
44
  log_failure_msg "Please either dpkg-reconfigure $DESC, or copy the example from"
41
45
  log_failure_msg "/usr/share/doc/clamav-base/examples/ to $CLAMAVCONF and run"
42
46
  log_failure_msg "'/etc/init.d/clamav-daemon start'"
43
 
  exit 1;
 
47
  if [ "$1" = "status" ]; then
 
48
    # program or service status is unknown
 
49
    exit 4;
 
50
  else
 
51
    # program is not configured
 
52
    exit 6;
 
53
  fi
44
54
fi
45
55
 
46
56
slurp_config "$CLAMAVCONF"
48
58
if [ -n "$Example" ]; then
49
59
  log_failure_msg "Clamav is not configured."
50
60
  log_failure_msg "Please edit $CLAMAVCONF and run  '/etc/init.d/clamav-daemon start'"
51
 
  exit 0
 
61
  if [ "$1" = "status" ]; then
 
62
    # program or service status is unknown
 
63
    exit 4;
 
64
  else
 
65
    # program is not configured
 
66
    exit 6;
 
67
  fi
52
68
fi
53
69
 
54
70
if is_true "$Foreground"; then
55
71
  if [ ! -x "$SUPERVISOR" ] ; then
56
72
     log_failure_msg "Foreground specified, but $SUPERVISORNAME not found"
57
 
     exit 0
 
73
    if [ "$1" = "status" ]; then
 
74
      # program or service status is unknown
 
75
      exit 4;
 
76
    else
 
77
      # program is not configured correctly
 
78
      exit 6;
 
79
    fi
58
80
  else
59
81
     RUN_SUPERVISED=1
60
82
  fi
66
88
make_dir "$DataBaseDirectory"
67
89
make_dir $(dirname "$SUPERVISORPIDFILE")
68
90
 
69
 
THEPIDFILE="`grep ^PidFile $CLAMAVCONF | awk '{print $2}'`"
70
 
[ -n "$THEPIDFILE" ] || THEPIDFILE='/var/run/clamav/clamd.pid'
 
91
if [ -z "$RUN_SUPERVISED" ]; then
 
92
        THEPIDFILE="$PidFile"
 
93
        THEDAEMON="$NAME"
 
94
        RELOAD="1"
 
95
else
 
96
        THEPIDFILE="$SUPERVISORPIDFILE"
 
97
        THEDAEMON="$SUPERVISORNAME"
 
98
        RELOAD="0"
 
99
fi
 
100
 
 
101
if [ -z "$THEPIDFILE" ]
 
102
then
 
103
  log_failure_msg "$NAME: Can not continue with PidFile not set"
 
104
  if [ "$1" = "status" ]; then
 
105
    # program or service status is unknown
 
106
    exit 4;
 
107
  else
 
108
    # program is not configured correctly
 
109
    exit 6;
 
110
  fi
 
111
fi
 
112
 
71
113
make_dir $(dirname "$THEPIDFILE")
72
114
chown $User $(dirname "$THEPIDFILE")
73
115
 
74
 
if [ -f "$THEPIDFILE" ]; then
75
 
  CLAMDPID=`pidofproc -p $THEPIDFILE $DAEMON`
76
 
  RUNNING=$?
77
 
else
78
 
  CLAMDPID=`pidofproc $DAEMON`
79
 
  RUNNING=$?
80
 
fi
81
 
 
82
 
if [ -z "$RUN_SUPERVISED" ]; then
83
 
  PID="$CLAMDPID"
84
 
else
85
 
  [ -e "$SUPERVISORPIDFILE" ] && PID=`cat $SUPERVISORPIDFILE`
86
 
fi
87
 
 
88
 
[ "$PID" = '1' ] && unset PID
89
116
 
90
117
case "$1" in
91
118
  start)
92
 
  OPTIND=1
93
119
  # Check for database existance (start will fail if it's missing)
94
120
  for db in main daily; do
95
121
    if [ ! -e "$DATABASEDIR"/"$db".cvd ] && [ ! -d "$DATABASEDIR"/"$db".inc ] && [ ! -e "$DATABASEDIR"/"$db".cld ]; then
96
122
      log_failure_msg "Clamav signatures not found in $DATABASEDIR"
97
123
      log_failure_msg "Please retrieve them using freshclam"
98
124
      log_failure_msg "Then run '/etc/init.d/clamav-daemon start'"
 
125
      # this is expected on a fresh installation
99
126
      exit 0
100
127
    fi
101
128
  done
102
129
  if [ -z "$RUN_SUPERVISED" ] ; then
103
130
    log_daemon_msg "Starting $DESC" "$NAME "
104
 
    start-stop-daemon --start -o -c $User --exec $DAEMON
 
131
    start-stop-daemon --start --oknodo -c $User --exec $DAEMON --pidfile $THEPIDFILE -- -c $CLAMAVCONF
105
132
    ret=$?
106
133
  else 
107
134
    log_daemon_msg "Starting $DESC" "$NAME (supervised) "
112
139
  ;;
113
140
  stop)
114
141
  log_daemon_msg "Stopping $DESC" "$NAME"
115
 
  OPTIND=1
116
 
  if [ -n "$PID" ]; then
117
 
    kill -15 -"$PID"
118
 
    ret=$?
119
 
    sleep 1
120
 
    if kill -0 "$PID" 2>/dev/null; then
121
 
      ret=$?
122
 
      log_progress_msg "Waiting . "
123
 
      cnt=0
124
 
      while kill -0 "$PID" 2>/dev/null; do
125
 
        ret=$?
126
 
        cnt=`expr "$cnt" + 1`
127
 
        if [ "$cnt" -gt 15 ]; then
128
 
          kill -9 -"$PID"
129
 
          break
130
 
        fi
131
 
        sleep 2
132
 
        log_progress_msg ". "
133
 
      done
134
 
    fi
135
 
  else
136
 
    if [ -z "$RUN_SUPERVISED" ] ; then
137
 
      killproc -p $THEPIDFILE
138
 
      ret=$?
139
 
    else
140
 
      killproc -p $SUPERVISORPIDFILE
141
 
      ret=$?
142
 
    fi
143
 
  fi
144
 
  if [ -n "$ret" ]; then
145
 
    log_end_msg $ret
146
 
  else
147
 
    log_end_msg $?
148
 
  fi
 
142
  start-stop-daemon --stop --oknodo --name $THEDAEMON --pidfile $THEPIDFILE --retry TERM/30/KILL/5
 
143
  log_end_msg $?
149
144
  ;;
150
145
  status)
151
 
  status_of_proc "$DAEMON" "$NAME"
152
 
  exit $?
 
146
  start-stop-daemon --status --name $THEDAEMON --pidfile $THEPIDFILE
 
147
  # start-stop-daemon returns LSB compliant exit status codes
 
148
  ret=$?
 
149
  if [ "$ret" = 0 ]; then
 
150
      log_success_msg "$NAME is running"
 
151
  else
 
152
      log_failure_msg "$NAME is not running"
 
153
      exit "$ret"
 
154
  fi
153
155
  ;;
154
156
  restart|force-reload)
155
157
  $0 stop
156
158
  $0 start
157
159
  ;;
158
160
  reload-database)
159
 
  OPTIND=1
160
 
  log_daemon_msg "Reloading database for $DESC" "$NAME"
161
 
  if [ "$RUNNING" = 0 ] && [ -n "$CLAMDPID" ]; then
162
 
    kill -USR2 $CLAMDPID
 
161
  if [ "$RELOAD" = "1" ]; then
 
162
    log_daemon_msg "Reloading database for $DESC" "$NAME"
 
163
    pkill -USR2 -F $THEPIDFILE $THEDAEMON 2>/dev/null
 
164
    log_end_msg $?
 
165
  else
 
166
    log_failure_msg "reload-database does not work in supervised mode."
 
167
    # unimplemented feature
 
168
    exit 3
163
169
  fi
164
 
  log_end_msg $?
165
170
  ;;
166
171
  reload-log)
167
 
  OPTIND=1
168
 
  log_daemon_msg "Reloading log file for $DESC" "$NAME"
169
 
  if [ "$RUNNING" = 0 ] && [ -n "$CLAMDPID" ]; then
170
 
    kill -HUP $CLAMDPID
 
172
  if [ "$RELOAD" = "1" ]; then
 
173
    log_daemon_msg "Reloading log file for $DESC" "$NAME"
 
174
    pkill -HUP -F $THEPIDFILE $THEDAEMON 2>/dev/null
 
175
  else
 
176
    log_failure_msg "reload-log does not work in supervised mode."
 
177
    # unimplemented feature
 
178
    exit 3
171
179
  fi
172
180
  log_end_msg $?
173
181
  ;;
174
182
  *)
175
 
  log_failure_msg "Usage: $0 {start|stop|restart|force-reload|reload-log|reload-database|status}" >&2
176
 
  exit 1
 
183
  log_action_msg "Usage: $0 {start|stop|restart|force-reload|reload-log|reload-database|status}" >&2
 
184
  # invalid arguments
 
185
  exit 2
177
186
  ;;
178
187
esac
179
188