summaryrefslogtreecommitdiff
path: root/files/etc/init.d/s6
blob: 0694a4ce957daf9e4a049abb9811991c4b51fc49 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh

### BEGIN INIT INFO
# Provides:          s6
# Required-Start:    $remote_fs $syslog nftables
# Required-Stop:     $remote_fs $syslog nftables
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start s6 service supervision suite
# Description:       Start s6 service supervision suite
### END INIT INFO

NAME="s6"
DESC="s6 system service supervision suite"
DAEMON="/usr/local/bin/s6-svscanboot"
SCANDIR="/etc/s6-scandir/"
DAEMON_ARGS=${SCANDIR}
SCRIPTNAME="/etc/init.d/${NAME}"

test -x $DAEMON || exit 0

if test -f /etc/default/${NAME}; then
	. /etc/default/${NAME}
fi

. /lib/init/vars.sh
. /lib/lsb/init-functions

case "$1" in
	start)
		if $0 status > /dev/null ; then
			log_success_msg "$NAME is already running"
		else
			log_daemon_msg "Starting ${DESC}" "${NAME}"
			/sbin/start-stop-daemon \
				--start \
				--oknodo \
				--make-pidfile \
				--pidfile /run/s6-svscan.pid \
				--background \
				--chdir "${SCANDIR}" \
				--exec "${DAEMON}" \
				-- "${DAEMON_ARGS}"
			log_end_msg $?
		fi
		;;
	stop)
		log_daemon_msg "Stopping ${DESC}" "${NAME}"
		/usr/bin/s6-svscanctl -t "${SCANDIR}"
		if test $? = 111; then
			/sbin/start-stop-daemon \
				--stop \
				--oknodo \
				--remove-pidfile \
				--pidfile /run/s6-svscan.pid \
				--retry TERM/60/KILL/10 \
				--exec /usr/bin/s6-svscan
			/sbin/start-stop-daemon \
				--stop \
				--oknodo \
				--retry TERM/60 \
				--exec /usr/bin/s6-supervise
		fi
		while $0 status
		do
			sleep 0.1
		done
		log_end_msg $?
		;;
	force-reload|restart)
		$0 stop
		$0 start
		;;
	status)
		/usr/bin/s6-svscanctl "${SCANDIR}"
		exitcode=$?
		case "$exitcode" in
			0)
				log_success_msg "$NAME is running"
				return ${exitcode}
				;;
			100)
				log_failure_msg "$NAME is not running"
				return ${exitcode}
				;;
			*)
				log_failure_msg "$NAME has some problem, exit code was ${exitcode}"
				return ${exitcode}
				;;
		esac
		;;
	*)
		echo "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload|status}"
		exit 1
		;;
esac

exit 0