summaryrefslogtreecommitdiffstats
path: root/testing/swatch/swatch.initd
blob: ec625e402684ac728dc14e0b1b74293a226a783f (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
#!/sbin/runscript

# swatch init.d file for alpine linux.

name=swatch
daemon=/usr/bin/$name
configfile=/etc/${name}/swatchrc
tailfile=/var/log/messages

SVC="${SVCNAME#*.}"
if [ -n "${SVC}" ] && [ "${SVCNAME}" != "${name}" ]; then
	SVCPID="${name}.${SVC}.pid"
	configfile="${configfile}.${SVC}"
	tailfile=$(find /var/log -name "${SVC}" | head -1)
	[ ! "${tailfile}" ] && tailfile="/var/log/${SVC}"
else
	SVCPID="${name}.pid"
fi

depend() {
#	need net
	after syslog
}

start() {
	ebegin "Starting ${name}"
		einfo "Preparing to monitor ${tailfile}"
		if [ ! -e "${tailfile}" ]; then
			eerror "${tailfile} does not exist"
			return 1
		fi
		if [ ! -e "${configfile}" ]; then
			eerror "Configfile ${configfile} is missing"
			return 1
		fi
		mkdir -p "${scriptdir}"
		start-stop-daemon --start --quiet --background \
			--make-pidfile --pidfile /var/run/${SVCPID} \
			--exec ${daemon} -- \
			--config-file="${configfile}" --script-dir="${scriptdir}" \
			--tail-file="${tailfile}" --tail-args="${tailargs}"
	eend $?
}

stop() {
	ebegin "Stopping ${name}"
		kill $(ps | grep .swatch_script.$(cat /var/run/${SVCPID}) | grep -v 'grep' | awk '{ print $1}')
	eend $?
}