git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/usr/local/sbin/freshclamd
blob: a3bc2b3924a80dfa7d15447bde808ecc51a48ee1 (plain)
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
#!/bin/sh
FCPIDF="/run/freshclam/freshclam.pid"

fresh_start() {
	/usr/bin/freshclam --daemon --checks=4 --pid="/run/freshclam/freshclam.pid"
}

fresh_stop() {
	if [ ! -e "$FCPIDF" ];then
		pidof "$(which freshclam)" >/dev/null
		[ "$?" -eq 0 ]&&exit 1
	else
		FCPID="$(cat "$FCPIDF")"
		[ -z "$FCPID" ]&&exit 2
		ps -p "$FCPID" >/dev/null 2>&1
		if [ "$?" -ne 0 ];then
			rm -f "$FCPIDF" >/dev/null 2>&1
			[ "$?" -ne 0 ]&&exit 3
		else
			kill "$FCPID" >/dev/null 2>&1
			sleep 1
			ps -p "$FCPID" >/dev/null 2>&1||exit 0
			sleep 10
			kill -9 "$FCPID" >/dev/null 2>&1
			sleep 2
			ps -p "$FCPID" >/dev/null 2>&1&&exit 4||exit 0
		fi
	fi
}

case "$1" in
	"start") fresh_start;;
	"stop") fresh_stop;;
	"restart") fresh_stop&&fresh_start;;
	*) echo "USAGE: $(basename "$0") start|stop|restart" >&2&&exit 1;;
esac