File: clamav-daemon.init.in

package info (click to toggle)
clamav 0.101.4+dfsg-0+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 29,564 kB
  • sloc: ansic: 158,978; sh: 8,178; cpp: 5,173; makefile: 2,088; yacc: 1,351; lex: 714; python: 120; perl: 17
file content (183 lines) | stat: -rw-r--r-- 5,084 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#! /bin/sh
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#               Clamav version by Magnus Ekdahl <magnus@debian.org>
#               Heavily reworked by Stephen Gran <sgran@debian.org>
#
### BEGIN INIT INFO
# Provides:          clamav-daemon
# Required-Start:    $remote_fs $syslog
# Should-Start:      
# Required-Stop:     $remote_fs $syslog
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: ClamAV daemon
# Description:       Clam AntiVirus userspace daemon
### END INIT INFO

# The exit status codes should comply with LSB.
# https://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/clamd
NAME="clamd"
DESC="ClamAV daemon"
CLAMAVCONF=/etc/clamav/clamd.conf
SUPERVISOR=/usr/bin/daemon
SUPERVISORNAME=daemon
SUPERVISORPIDFILE="/var/run/clamav/daemon-clamd.pid"
SUPERVISORARGS="--name=$NAME --respawn $DAEMON -F $SUPERVISORPIDFILE"
DATABASEDIR="/var/lib/clamav"

# required by Debian policy 9.3.2
[ -x "$DAEMON" ] || exit 0
[ -r /etc/default/clamav-daemon ] && . /etc/default/clamav-daemon

#COMMON-FUNCTIONS#

. /lib/lsb/init-functions

if [ ! -f "$CLAMAVCONF" ]; then
  log_failure_msg "There is no configuration file for Clamav."
  log_failure_msg "Please either dpkg-reconfigure $DESC, or copy the example from"
  log_failure_msg "/usr/share/doc/clamav-base/examples/ to $CLAMAVCONF and run"
  log_failure_msg "'/etc/init.d/clamav-daemon start'"
  if [ "$1" = "status" ]; then
    # program or service status is unknown
    exit 4;
  else
    # program is not configured
    exit 6;
  fi
fi

slurp_config "$CLAMAVCONF"

if [ -n "$Example" ]; then
  log_failure_msg "Clamav is not configured."
  log_failure_msg "Please edit $CLAMAVCONF and run  '/etc/init.d/clamav-daemon start'"
  if [ "$1" = "status" ]; then
    # program or service status is unknown
    exit 4;
  else
    # program is not configured
    exit 6;
  fi
fi

if is_true "$Foreground"; then
  if [ ! -x "$SUPERVISOR" ] ; then
     log_failure_msg "Foreground specified, but $SUPERVISORNAME not found"
    if [ "$1" = "status" ]; then
      # program or service status is unknown
      exit 4;
    else
      # program is not configured correctly
      exit 6;
    fi
  else
     RUN_SUPERVISED=1
  fi
fi

[ -n "$User" ] || User=clamav
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav

make_dir "$DataBaseDirectory"
make_dir $(dirname "$SUPERVISORPIDFILE")

if [ -z "$RUN_SUPERVISED" ]; then
	THEPIDFILE="$PidFile"
	THEDAEMON="$NAME"
	RELOAD="1"
else
	THEPIDFILE="$SUPERVISORPIDFILE"
	THEDAEMON="$SUPERVISORNAME"
	RELOAD="0"
fi

if [ -z "$THEPIDFILE" ]
then
  # Set the default PidFile.
  THEPIDFILE='/run/clamav/clamd.pid'
fi

make_dir $(dirname "$THEPIDFILE")
chown $User $(dirname "$THEPIDFILE")


case "$1" in
  start)
  # Check for database existence (start will fail if it's missing)
  for db in main daily; do
    if [ ! -e "$DATABASEDIR"/"$db".cvd ] && [ ! -d "$DATABASEDIR"/"$db".inc ] && [ ! -e "$DATABASEDIR"/"$db".cld ]; then
      log_failure_msg "Clamav signatures not found in $DATABASEDIR"
      log_failure_msg "Please retrieve them using freshclam"
      log_failure_msg "Then run '/etc/init.d/clamav-daemon start'"
      # this is expected on a fresh installation
      exit 0
    fi
  done
  if [ -z "$RUN_SUPERVISED" ] ; then
    log_daemon_msg "Starting $DESC" "$NAME "
    start-stop-daemon --start --oknodo -c $User --exec $DAEMON --pidfile $THEPIDFILE --quiet -- -c $CLAMAVCONF --pid=$THEPIDFILE
    ret=$?
  else 
    log_daemon_msg "Starting $DESC" "$NAME (supervised) "
    $SUPERVISOR $SUPERVISORARGS
    ret=$?
  fi
  log_end_msg $ret
  ;;
  stop)
  log_daemon_msg "Stopping $DESC" "$NAME"
  start-stop-daemon --stop --oknodo --name $THEDAEMON --pidfile $THEPIDFILE --quiet --retry TERM/30/KILL/5
  log_end_msg $?
  ;;
  status)
  start-stop-daemon --status --name $THEDAEMON --pidfile $THEPIDFILE
  # start-stop-daemon returns LSB compliant exit status codes
  ret=$?
  if [ "$ret" = 0 ]; then
      log_success_msg "$NAME is running"
  else
      log_failure_msg "$NAME is not running"
      exit "$ret"
  fi
  ;;
  restart|force-reload)
  $0 stop
  $0 start
  ;;
  reload-database)
  if [ "$RELOAD" = "1" ]; then
    log_daemon_msg "Reloading database for $DESC" "$NAME"
    pkill -USR2 -F $THEPIDFILE $THEDAEMON 2>/dev/null
    log_end_msg $?
  else
    log_failure_msg "reload-database does not work in supervised mode."
    # unimplemented feature
    exit 3
  fi
  ;;
  reload-log)
  if [ "$RELOAD" = "1" ]; then
    log_daemon_msg "Reloading log file for $DESC" "$NAME"
    pkill -HUP -F $THEPIDFILE $THEDAEMON 2>/dev/null
  else
    log_failure_msg "reload-log does not work in supervised mode."
    # unimplemented feature
    exit 3
  fi
  log_end_msg $?
  ;;
  *)
  log_action_msg "Usage: $0 {start|stop|restart|force-reload|reload-log|reload-database|status}" >&2
  # invalid arguments
  exit 2
  ;;
esac

exit 0