File: clamav-freshclam.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 (111 lines) | stat: -rw-r--r-- 3,213 bytes parent folder | download | duplicates (5)
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
#!/bin/sh

### BEGIN INIT INFO
# Provides:          clamav-freshclam
# Required-Start:    $remote_fs $syslog
# Should-Start:      clamav-daemon
# Required-Stop:     $remote_fs $syslog
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: ClamAV virus database updater
# Description:       Clam AntiVirus virus database updater
### 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

DAEMON=/usr/bin/freshclam
NAME=freshclam
DESC="ClamAV virus database updater"

# required by Debian policy 9.3.2
[ -x $DAEMON ] || exit 0

CLAMAV_CONF_FILE=/etc/clamav/clamd.conf
FRESHCLAM_CONF_FILE=/etc/clamav/freshclam.conf

#COMMON-FUNCTIONS#

. /lib/lsb/init-functions

slurp_config "$FRESHCLAM_CONF_FILE"

if [ -z "$PidFile" ]
then
  # Set the default PidFile.
  PidFile='/run/clamav/freshclam.pid'
fi
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav

make_dir "$DataBaseDirectory"
make_dir $(dirname "$PidFile")

[ -z "$UpdateLogFile" ] && UpdateLogFile=/var/log/clamav/freshclam.log
[ -z "$DatabaseDirectory" ] && DatabaseDirectory=/var/lib/clamav/
[ -n "$DatabaseOwner" ] || DatabaseOwner=clamav

case "$1" in
  no-daemon)
  su "$DatabaseOwner" -p -s /bin/sh -c "freshclam -l $UpdateLogFile --datadir $DatabaseDirectory"
  ;;
  start)
  if [ ! -f "$PidFile" ]; then
    # If clamd is run under a different UID than freshclam then we need
    # to make sure the PidFile can be written or else we won't be able to
    # kill it.
    touch $PidFile
    chown $DatabaseOwner $PidFile
  fi
  # If user wants it run from cron, we only accept no-daemon and stop
  if [ -f /etc/cron.d/clamav-freshclam ]; then
    log_warning_msg "Not starting $NAME - cron option selected"
    log_warning_msg "Run the init script with the 'no-daemon' option"
    # this is similar to the daemon already running
    exit 0
  fi
  log_daemon_msg "Starting $DESC" "$NAME"
  start-stop-daemon --start --oknodo -c "$DatabaseOwner" --exec $DAEMON --pidfile $PidFile --quiet -- -d --quiet --config-file=$FRESHCLAM_CONF_FILE --pid=$PidFile
  log_end_msg $?
  ;;
  stop)
  log_daemon_msg "Stopping $DESC" "$NAME"
  start-stop-daemon --stop --oknodo --name $NAME --pidfile $PidFile --quiet --retry TERM/30/KILL/5
  log_end_msg $?
  ;;
  restart|force-reload)
  $0 stop
  $0 start
  ;;
  reload-log)
  # If user wants it run from cron, we only accept no-daemon and stop
  if [ -f /etc/cron.d/clamav-freshclam ]; then
    log_warning_msg "Not reloading log for $NAME - cron option selected"
    # log-reloading is not needed, because freshclam is not run as daemon
    exit 0
  fi
  log_daemon_msg "Reloading $DESC" "$NAME"
  pkill -HUP -F $PidFile $NAME
  log_end_msg $?
  ;;
  skip)
  ;;
  status)
  start-stop-daemon --status --name $NAME --pidfile $PidFile
  ret="$?"
   if [ "$ret" = 0 ]; then
     log_success_msg "$NAME is running"
     exit 0
   else
     log_failure_msg "$NAME is not running"
     exit "$ret"
  fi
  ;;
  *)
  log_action_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2
  # invalid arguments
  exit 2
  ;;
esac

exit 0