aboutsummaryrefslogtreecommitdiffstats
path: root/main/clamav/clamd.initd
blob: d3b9155572d758489cf7278f9e6c8aa5d80b27d3 (plain) (blame)
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
#!/sbin/runscript

opts="logfix reload"
NAME=clamd
CONF=/etc/clamav/clamd.conf

depend() {
	need net
	provide antivirus
}

start() {
	local clamd_socket=$(awk '$1 == "LocalSocket" { print $2 }' $CONF)

	logfix

	if [ -S "${clamd_socket:=/tmp/clamd}" ]; then
		rm -f ${clamd_socket}
	fi
	ebegin "Starting ${NAME}"
	start-stop-daemon --start --quiet \
		--nicelevel ${CLAMD_NICELEVEL:-0} \
		--exec /usr/sbin/clamd
	eend $? "Failed to start ${NAME}"
}

stop() {
	ebegin "Stopping ${NAME}"
	start-stop-daemon --stop --quiet --exec /usr/sbin/clamd
	eend $?
}

reload() {
	ebegin "Reloading ${NAME}"
	if ! service_started "${NAME}" ; then
		eend 1 "${NAME} is not started"
		return 1
	fi
	start-stop-daemon --stop --oknodo --signal HUP \
		--exec /usr/sbin/clamd
	eend $?
}

logfix() {
	# fix clamd log permissions
	# (might be clobbered by logrotate or something)
	local logfile=`awk '$1 == "LogFile" { print $2 }' $CONF`
	local clamav_user=`awk '$1 == "User" { print $2 }' $CONF`
	if [ -n "${logfile}" ] && [ -n "${clamav_user}" ]; then
		if [ ! -f "${logfile}" ]; then
			touch ${logfile}
		fi
		chown ${clamav_user} ${logfile}
		chmod 640 ${logfile}
	fi
}