From 9deb685cc0588440c17368e3f1ffa7235fd265ff Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 7 Jan 2022 22:55:15 +0000 Subject: [PATCH] When restarting the service - wait until the old proc has been killed before attempting to start it again. Prevents messages about the usuage of kill in the log. Remove old comment Signed-off-by: Adam Warner --- .../etc/services.d/pihole-FTL/finish | 2 +- s6/service | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/s6/debian-root/etc/services.d/pihole-FTL/finish b/s6/debian-root/etc/services.d/pihole-FTL/finish index 22f0212..6beaaf5 100644 --- a/s6/debian-root/etc/services.d/pihole-FTL/finish +++ b/s6/debian-root/etc/services.d/pihole-FTL/finish @@ -1,4 +1,4 @@ #!/usr/bin/with-contenv bash s6-echo "Stopping pihole-FTL" -kill -15 $(pgrep pihole-FTL) # TODO: REVISIT THIS SO AS TO NOT kill -9 +kill -15 $(pgrep pihole-FTL) diff --git a/s6/service b/s6/service index 10ab8df..c09e5ad 100755 --- a/s6/service +++ b/s6/service @@ -2,29 +2,49 @@ # This script patches all service commands into the appropriate s6- commands # pi-hole upstream scripts need a 'service' interface. why not systemd? docker said so. start() { - s6-svc -wU -u -T2500 /var/run/s6/services/$service + s6-svc -wU -u -T2500 /var/run/s6/services/$service } stop() { - s6-svc -wD -d -T2500 /var/run/s6/services/$service + s6-svc -wD -d -T2500 /var/run/s6/services/$service } restart() { + local pid + + # Get the PID of the service we are asking to restart + pid=$(pgrep $service) + + # Only attempt to stop the service if it is already running + if [ -n "$pid" ]; then stop + + # Loop until we are certain that the process has been stopped + while test -d /proc/$pid; do + sleep 0.2 + done + fi + + # Check it hasn't been started by something else in the meantime + pid=$(pgrep $service) + + # Only attempt to start the service if it is not already running + if [ -z "$pid" ]; then start - #s6-svc -t -wR -T5000 /var/run/s6/services/$service + fi + } status() { - s6-svstat /var/run/s6/services/$service + s6-svstat /var/run/s6/services/$service } service="$1" command="$2" if [[ ! -d "/var/run/s6/services/$service" ]] ; then - echo "s6 service not found for $service, exiting..." - exit + echo "s6 service not found for $service, exiting..." + exit fi; ${command} "${service}"