summaryrefslogtreecommitdiff
blob: 7db43eb242660db1dde05df5cbcb8a3bb75ae9b3 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/sbin/openrc-run
# This script is based on the one created by Phil (bug #255329).

depend() {
	need logger
}

SWATCHDOG_BINARY=${SWATCHDOG_BINARY:-/usr/bin/swatchdog}
SWATCHDOGRC=${SWATCHDOGRC:-/etc/swatchdogrc}
SWATCHDOG_TAILFILE=${SWATCHDOG_TAILFILE:-/var/log/syslog}
SWATCHDOG_LOGFILE=${SWATCHDOG_LOGFILE:-/var/log/swatchdog.log}
SWATCHDOG_ERRFILE=${SWATCHDOG_ERRFILE:-/var/log/swatchdog-err.log}
SWATCHDOG_SCRIPT=${SWATCHDOG_SCRIPT:-/run/swatchdog/swatchdog_script.pl}

gen_script() {
	local tailargs=""
	if [ "${SWATCHDOG_TAILARGS}" ]; then
		tailargs="--tail-args=\"${SWATCHDOG_TAILARGS}\""
	fi
	ebegin "Generating swatchdog script from config"
	${SWATCHDOG_BINARY} --dump-script="${SWATCHDOG_SCRIPT}" \
		--use-cpan-file-tail ${tailargs} \
		--config-file "${SWATCHDOGRC}" $1 "${SWATCHDOG_TAILFILE}"
	eend $?
}

parse_full() {
	gen_script --examine
	ebegin "Parsing complete file once"
	/usr/bin/perl ${SWATCHDOG_SCRIPT} 1>/dev/null
	eend $?
}

start() {
	checkpath -d -q -m 0750 -o root:root /run/swatchdog
	if [ "${PARSE_FULL}" == "YES" ]; then
		parse_full
	fi
	gen_script --tail-file
	ebegin "Starting swatchdog"
	start-stop-daemon --start --quiet --background \
		--make-pidfile --pidfile /run/swatchdog/swatchdog.pid \
		--stdout ${SWATCHDOG_LOGFILE} --stderr ${SWATCHDOG_ERRFILE} \
		--exec /usr/bin/perl -- ${SWATCHDOG_SCRIPT}
	eend $?
}

stop() {
	ebegin "Stopping swatchdog"
	start-stop-daemon --stop --exec /usr/bin/perl \
		--pidfile /run/swatchdog/swatchdog.pid --quiet
	eend $?
}