File clamav-rcfreshclam of Package clamav
x
1
#! /bin/sh
2
# Copyright (c) 1995-2003 SuSE Linux AG, Nuernberg, Germany.
3
# All rights reserved.
4
#
5
# Author: Kurt Garloff
6
# Please send feedback to http://www.suse.de/feedback/
7
#
8
# /etc/init.d/freshclam
9
# and its symbolic link
10
# /(usr/)sbin/rcfreshclam
11
#
12
#
13
# LSB compatible service control script; see http://www.linuxbase.org/spec/
14
#
15
# Note: This template uses functions rc_XXX defined in /etc/rc.status on
16
# UnitedLinux (UL) based Linux distributions. If you want to base your
17
# script on this template and ensure that it works on non UL based LSB
18
# compliant Linux distributions, you either have to provide the rc.status
19
# functions from UL or change the script to work without them.
20
#
21
### BEGIN INIT INFO
22
# Provides: freshclam
23
# Required-Start: $syslog $remote_fs
24
# X-UnitedLinux-Should-Start: $time ypbind sendmail
25
# Required-Stop: $syslog $remote_fs
26
# X-UnitedLinux-Should-Stop: $time ypbind sendmail
27
# Default-Start: 3 5
28
# Default-Stop: 0 1 2 6
29
# Short-Description: virus scanner daemon
30
# Description: Start the freshclam virus database update daemon
31
### END INIT INFO
32
#
33
# Any extensions to the keywords given above should be preceeded by
34
# X-VendorTag- (X-UnitedLinux- for us) according to LSB.
35
#
36
# Notes on Required-Start/X-UnitedLinux-Should-Start:
37
# * There are two different issues that are solved by Required-Start
38
# and X-UnitedLinux-Should-Start
39
# (a) Hard dependencies: This is used by the runlevel editor to determine
40
# which services absolutely need to be started to make the start of
41
# this service make sense. Example: nfsserver should have
42
# Required-Start: $portmap
43
# Also, required services are started before the dependent ones.
44
# The runlevel editor will warn about such missing hard dependencies
45
# and suggest enabling. During system startup, you may expect an error,
46
# if the dependency is not fulfilled.
47
# (b) Specifying the init script ordering, not real (hard) dependencies.
48
# This is needed by insserv to determine which service should be
49
# started first (and at a later stage what services can be started
50
# in parallel). The tag X-UnitedLinux-Should-Start: is used for this.
51
# It tells, that if a service is available, it should be started
52
# before. If not, never mind.
53
# * When specifying hard dependencies or ordering requirements, you can
54
# use names of services (contents of their Provides: section)
55
# or pseudo names starting with a $. The following ones are available
56
# according to LSB (1.1):
57
# $local_fs all local file systems are mounted
58
# (most services should need this!)
59
# $remote_fs all remote file systems are mounted
60
# (note that /usr may be remote, so
61
# many services should Require this!)
62
# $syslog system logging facility up
63
# $network low level networking (eth card, ...)
64
# $named hostname resolution available
65
# $netdaemons all network daemons are running
66
# The $netdaemons pseudo service has been removed in LSB 1.2.
67
# For now, we still offer it for backward compatibility.
68
# These are new (LSB 1.2):
69
# $time the system time has been set correctly
70
# $portmap SunRPC portmapping service available
71
# UnitedLinux extensions:
72
# $ALL indicates that a script should be inserted
73
# at the end
74
# * The services specified in the stop tags
75
# (Required-Stop/X-UnitedLinux-Should-Stop)
76
# specify which services need to be still running when this service
77
# is shut down. Often the entries there are just copies or a subset
78
# from the respective start tag.
79
# * X-UnitedLinux-Should-Start/Stop are not part of LSB (as of 1.3)
80
# but official Should-Start/Stop tags are in discussion (1.9).
81
# insserv does support these as well.
82
# * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
83
# (%fillup_and_insserv macro in %post of many RPMs) to specify whether
84
# a startup script should default to be enabled after installation.
85
# It's not used by insserv.
86
#
87
# Note on runlevels:
88
# 0 - halt/poweroff 6 - reboot
89
# 1 - single user 2 - multiuser without network exported
90
# 3 - multiuser w/ network (text mode) 5 - multiuser w/ network and X11 (xdm)
91
#
92
# Note on script names:
93
# http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
94
# A registry has been set up to manage the init script namespace.
95
# http://www.lanana.org/
96
# Please use the names already registered or register one or use a
97
# vendor prefix.
98
99
100
# Check for missing binaries (stale symlinks should not happen)
101
# Note: Special treatment of stop for LSB conformance
102
FRESHCLAM_BIN=/usr/bin/freshclam
103
test -x $FRESHCLAM_BIN || {
104
echo "$FRESHCLAM_BIN not installed";
105
if [ "$1" = "stop" ]; then exit 0;
106
else exit 5; fi;
107
}
108
109
FRESHCLAM_PIDFILE=/var/lib/clamav/freshclam.pid
110
111
# Source LSB init functions
112
# providing start_daemon, killproc, pidofproc,
113
# log_success_msg, log_failure_msg and log_warning_msg.
114
# This is currently not used by UnitedLinux based distributions and
115
# not needed for init scripts for UnitedLinux only. If it is used,
116
# the functions from rc.status should not be sourced or used.
117
#. /lib/lsb/init-functions
118
119
# Shell functions sourced from /etc/rc.status:
120
# rc_check check and set local and overall rc status
121
# rc_status check and set local and overall rc status
122
# rc_status -v be verbose in local rc status and clear it afterwards
123
# rc_status -v -r ditto and clear both the local and overall rc status
124
# rc_status -s display "skipped" and exit with status 3
125
# rc_status -u display "unused" and exit with status 3
126
# rc_failed set local and overall rc status to failed
127
# rc_failed <num> set local and overall rc status to <num>
128
# rc_reset clear both the local and overall rc status
129
# rc_exit exit appropriate to overall rc status
130
# rc_active checks whether a service is activated by symlinks
131
# rc_splash arg sets the boot splash screen to arg (if active)
132
. /etc/rc.status
133
134
# Reset status of this service
135
rc_reset
136
137
# Return values acc. to LSB for all commands but status:
138
# 0 - success
139
# 1 - generic or unspecified error
140
# 2 - invalid or excess argument(s)
141
# 3 - unimplemented feature (e.g. "reload")
142
# 4 - user had insufficient privileges
143
# 5 - program is not installed
144
# 6 - program is not configured
145
# 7 - program is not running
146
# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
147
#
148
# Note that starting an already running service, stopping
149
# or restarting a not-running service as well as the restart
150
# with force-reload (in case signaling is not supported) are
151
# considered a success.
152
153
case "$1" in
154
start)
155
echo -n "Starting Clam AntiVirus database update daemon "
156
# Check if there is a virus definition file
157
startproc -p $FRESHCLAM_PIDFILE $FRESHCLAM_BIN -d
158
159
# Remember status and be verbose
160
rc_status -v
161
;;
162
stop)
163
echo -n "Shutting down Clam AntiVirus database update daemon "
164
## Stop daemon with killproc(8) and if this fails
165
## killproc sets the return value according to LSB.
166
killproc -p $FRESHCLAM_PIDFILE -TERM $FRESHCLAM_BIN
167
168
# Remember status and be verbose
169
rc_status -v
170
;;
171
try-restart | condrestart)
172
## Do a restart only if the service was active before.
173
## Note: try-restart is now part of LSB (as of 1.9).
174
## RH has a similar command named condrestart.
175
if test "$1" = "condrestart"; then
176
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
177
fi
178
$0 status
179
if test $? = 0; then
180
$0 restart
181
else
182
rc_reset # Not running is not a failure.
183
fi
184
# Remember status and be quiet
185
rc_status
186
;;
187
restart)
188
## Stop the service and regardless of whether it was
189
## running or not, start it again.
190
$0 stop
191
$0 start
192
193
# Remember status and be quiet
194
rc_status
195
;;
196
reload | force-reload)
197
## Signal the daemon to reload its config.
198
echo -n "Reloading Clam AntiVirus database update daemon "
199
checkproc -p $FRESHCLAM_PIDFILE $FRESHCLAM_BIN &&
200
killproc -p $FRESHCLAM_PIDFILE -HUP $FRESHCLAM_BIN
201
rc_status -v
202
;;
203
status)
204
echo -n "Checking for Clam AntiVirus database update daemon "
205
## Check status with checkproc(8), if process is running
206
## checkproc will return with exit status 0.
207
208
# Return value is slightly different for the status command:
209
# 0 - service up and running
210
# 1 - service dead, but /var/run/ pid file exists
211
# 2 - service dead, but /var/lock/ lock file exists
212
# 3 - service not running (unused)
213
# 4 - service status unknown :-(
214
# 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
215
216
# NOTE: checkproc returns LSB compliant status values.
217
checkproc -p $FRESHCLAM_PIDFILE $FRESHCLAM_BIN
218
# NOTE: rc_status knows that we called this init script with
219
# "status" option and adapts its messages accordingly.
220
rc_status -v
221
;;
222
*)
223
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
224
exit 1
225
;;
226
esac
227
rc_exit
228