Logoj0ke.net Open Build Service > Projects > oldschool > clamav > clamav-rcclamd
Sign Up | Log In

File clamav-rcclamd 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/clamd
9
#   and its symbolic link
10
# /(usr/)sbin/rcclamd
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:          clamd
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 clamd virus scanner 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
CLAMD_BIN=/usr/sbin/clamd
103
test -x $CLAMD_BIN || { echo "$CLAMD_BIN not installed"; 
104
    if [ "$1" = "stop" ]; then exit 0;
105
    else exit 5; fi; }
106
107
CLAMD_DB=/var/lib/clamav/main.cvd
108
CLAMD_PIDFILE=/var/lib/clamav/clamd.pid
109
110
# Source LSB init functions
111
# providing start_daemon, killproc, pidofproc, 
112
# log_success_msg, log_failure_msg and log_warning_msg.
113
# This is currently not used by UnitedLinux based distributions and
114
# not needed for init scripts for UnitedLinux only. If it is used,
115
# the functions from rc.status should not be sourced or used.
116
#. /lib/lsb/init-functions
117
118
# Shell functions sourced from /etc/rc.status:
119
#      rc_check         check and set local and overall rc status
120
#      rc_status        check and set local and overall rc status
121
#      rc_status -v     be verbose in local rc status and clear it afterwards
122
#      rc_status -v -r  ditto and clear both the local and overall rc status
123
#      rc_status -s     display "skipped" and exit with status 3
124
#      rc_status -u     display "unused" and exit with status 3
125
#      rc_failed        set local and overall rc status to failed
126
#      rc_failed <num>  set local and overall rc status to <num>
127
#      rc_reset         clear both the local and overall rc status
128
#      rc_exit          exit appropriate to overall rc status
129
#      rc_active        checks whether a service is activated by symlinks
130
#      rc_splash arg    sets the boot splash screen to arg (if active)
131
. /etc/rc.status
132
133
# Reset status of this service
134
rc_reset
135
136
# Return values acc. to LSB for all commands but status:
137
# 0   - success
138
# 1       - generic or unspecified error
139
# 2       - invalid or excess argument(s)
140
# 3       - unimplemented feature (e.g. "reload")
141
# 4       - user had insufficient privileges
142
# 5       - program is not installed
143
# 6       - program is not configured
144
# 7       - program is not running
145
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
146
# 
147
# Note that starting an already running service, stopping
148
# or restarting a not-running service as well as the restart
149
# with force-reload (in case signaling is not supported) are
150
# considered a success.
151
152
case "$1" in
153
    start)
154
    echo -n "Starting Clam AntiVirus daemon "
155
    # Check if there is a virus definition file
156
    if ! test -f $CLAMD_DB ; then 
157
        echo ""
158
        echo "  Virus definition file $CLAMD_DB is missing."
159
        echo "  Either install the clamav-db package or run freshclam "
160
        echo -n "  to get the virus definitions."
161
        rc_failed 6
162
    else
163
        ## Start daemon with startproc(8). If this fails
164
        ## the return value is set appropriately by startproc.
165
        startproc -q -p $CLAMD_PIDFILE $CLAMD_BIN
166
    fi
167
    # Remember status and be verbose
168
    rc_status -v
169
    ;;
170
    stop)
171
    echo -n "Shutting down Clam AntiVirus daemon "
172
    ## Stop daemon with killproc(8) and if this fails
173
    ## killproc sets the return value according to LSB.
174
175
    killproc -p $CLAMD_PIDFILE -TERM $CLAMD_BIN
176
177
    # Remember status and be verbose
178
    rc_status -v
179
    ;;
180
    try-restart | condrestart)
181
    ## Do a restart only if the service was active before.
182
    ## Note: try-restart is now part of LSB (as of 1.9).
183
    ## RH has a similar command named condrestart.
184
    if test "$1" = "condrestart"; then
185
        echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
186
    fi
187
    $0 status
188
    if test $? = 0; then
189
        $0 restart
190
    else
191
        rc_reset    # Not running is not a failure.
192
    fi
193
    # Remember status and be quiet
194
    rc_status
195
    ;;
196
    restart)
197
    ## Stop the service and regardless of whether it was
198
    ## running or not, start it again.
199
    $0 stop
200
    $0 start
201
202
    # Remember status and be quiet
203
    rc_status
204
    ;;
205
    reload | force-reload)
206
    ## Signal the daemon to reload its config.
207
    echo -n "Reloading Clam AntiVirus daemon "
208
    checkproc -p $CLAMD_PIDFILE $CLAMD_BIN && echo RELOAD > /dev/tcp/127.0.0.1/3310
209
    rc_status -v
210
    ;;
211
    status)
212
    echo -n "Checking for Clam AntiVirus daemon "
213
    ## Check status with checkproc(8), if process is running
214
    ## checkproc will return with exit status 0.
215
216
    # Return value is slightly different for the status command:
217
    # 0 - service up and running
218
    # 1 - service dead, but /var/run/  pid  file exists
219
    # 2 - service dead, but /var/lock/ lock file exists
220
    # 3 - service not running (unused)
221
    # 4 - service status unknown :-(
222
    # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
223
    
224
    # NOTE: checkproc returns LSB compliant status values.
225
    checkproc -p $CLAMD_PIDFILE $CLAMD_BIN
226
    # NOTE: rc_status knows that we called this init script with
227
    # "status" option and adapts its messages accordingly.
228
    rc_status -v
229
    ;;
230
    *)
231
    echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
232
    exit 1
233
    ;;
234
esac
235
rc_exit
236