From 4e7e16252670533a7eed9568b660e6fdd574e5e1 Mon Sep 17 00:00:00 2001 From: Hendrik Jäger Date: Sun, 22 May 2022 19:26:25 +0200 Subject: feat: a proper initscript allows proper handling of the processes, especially stopping --- files/etc/init.d/s6 | 75 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/files/etc/init.d/s6 b/files/etc/init.d/s6 index 59de3fa..ef577a0 100644 --- a/files/etc/init.d/s6 +++ b/files/etc/init.d/s6 @@ -1,4 +1,4 @@ -#!/usr/bin/env /lib/init/init-d-script +#!/bin/sh ### BEGIN INIT INFO # Provides: s6 @@ -10,9 +10,74 @@ # Description: Start s6 service supervision suite ### END INIT INFO +NAME="s6" +DESC="s6 system service supervision suite" DAEMON="/usr/local/bin/s6-svscanboot" -DAEMON_ARGS="/etc/s6-services" +SCANDIR="/etc/s6-services/" +DAEMON_ARGS=${SCANDIR} +PIDFILE="/var/run/s6.pid" +SCRIPTNAME="/etc/init.d/${NAME}" -do_stop_cmd_override() { - /usr/bin/s6-svscanctl -t /etc/s6-services/ -} +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 \ + --chdir "${SCANDIR}" \ + --startas "${DAEMON}" \ + --background \ + --make-pidfile \ + --pidfile "${PIDFILE}" \ + -- "${DAEMON_ARGS}" + log_end_msg $? + fi + ;; + stop) + log_daemon_msg "Stopping ${DESC}" "${NAME}" + /sbin/start-stop-daemon \ + --stop \ + --oknodo \ + --retry TERM/60/QUIT/60 \ + --remove-pidfile \ + --pidfile "${PIDFILE}" + if test $? = 2; then + /sbin/start-stop-daemon \ + --stop \ + --oknodo \ + --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 + log_end_msg $? + ;; + force-reload|restart) + $0 stop + $0 start + ;; + status) + status_of_proc -p ${PIDFILE} ${DAEMON} s6 && exit 0 || exit $? + ;; + *) + echo "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload|status}" + exit 1 + ;; +esac + +exit 0 -- cgit v1.2.3