read pids into an array in case of multiple instances of FTL running. Wait til they are all closed (stop calls killall) and then start another one
Additionally, move the logic from start() into the end of restart(), and have start() call restart, ensures multiple calls of start cannot start multple processes Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
509ca4b39a
commit
b0878f1750
19
s6/service
19
s6/service
|
@ -1,8 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# This script patches all service commands into the appropriate s6- commands
|
# 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.
|
# pi-hole upstream scripts need a 'service' interface. why not systemd? docker said so.
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
s6-svc -wu -u -T2500 /var/run/s6/services/$service
|
restart
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
@ -12,16 +13,18 @@ stop() {
|
||||||
restart() {
|
restart() {
|
||||||
local pid
|
local pid
|
||||||
|
|
||||||
# Get the PID of the service we are asking to restart
|
# Get the PID(s) of the service we are asking to restart
|
||||||
pid=$(pgrep $service)
|
mapfile -t pids < <(pgrep $service)
|
||||||
|
|
||||||
# Only attempt to stop the service if it is already running
|
# Only attempt to stop the service if it is already running
|
||||||
if [ -n "$pid" ]; then
|
if [ "${#pids[@]}" -gt 0 ]; then
|
||||||
stop
|
stop
|
||||||
|
|
||||||
# Loop until we are certain that the process has been stopped
|
for pid in "${pids[@]}"; do
|
||||||
while test -d /proc/$pid; do
|
# Loop until we are certain that the process has been stopped
|
||||||
sleep 0.2
|
while test -d /proc/$pid; do
|
||||||
|
sleep 0.2
|
||||||
|
done
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -30,7 +33,7 @@ restart() {
|
||||||
|
|
||||||
# Only attempt to start the service if it is not already running
|
# Only attempt to start the service if it is not already running
|
||||||
if [ -z "$pid" ]; then
|
if [ -z "$pid" ]; then
|
||||||
start
|
s6-svc -wu -u -T2500 /var/run/s6/services/$service
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue