summaryrefslogtreecommitdiff
path: root/network/webhook/webhook.init
blob: 7b809260ae449650584678bd583df5d82819b378 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# Start/stop/restart webhook.

. /etc/default/webhook

__start() {
	if [ -z "$PIDFILE" ]; then
		echo "WebHook will start but please set PIDFILE in /etc/default/webhook"
	else
		if [ -f "$PIDFILE" ]; then
			echo "WebHook daemon is already running as PID $(< ${PIDFILE}) " >&2
			exit 3
		fi
	fi

	if [ -x /usr/sbin/webhook-wrapper.sh ]; then
		echo "Starting WebHook daemon:  /usr/sbin/webhook-wrapper.sh &"

		if [ -z "$LOG" ]; then
			/usr/sbin/webhook-wrapper.sh > /dev/null 2>&1 &
		else
			/usr/sbin/webhook-wrapper.sh >> "$LOG" 2>&1 &
		fi
	fi
}

__stop() {
	if [ -f "$PIDFILE" ]; then
		kill "$(< ${PIDFILE})"
		rm -f "${PIDFILE}"
	else
		if [ -z "$PIDFILE" ]; then
			killall -9 webhook-wrapper.sh
			killall -9 webhook
		else
			echo "Webhook is not running"
		fi
	fi
}

__restart() {
	__stop
	if [ -z "$PIDFILE" ]; then
		sleep 1
	else
		while [ -f "$PIDFILE" ]; do
			sleep 1
		done
	fi
	__start
}


case "$1" in
	'start')
		__start
		;;
	'stop')
		__stop
		;;
	'restart')
		__restart
		;;
	*)
		echo "usage $0 start|stop|restart"
		exit 2
esac

# vim: ft=sh noet ai ts=4 sw=4 sts=4: