mirror of
https://github.com/troglobit/finit.git
synced 2026-10-20 11:19:35 +00:00
test: new test, verify SysV start/stop daemon support
Install start-stop-daemon in test root. Add S01-service.sh, which uses start-stop-daemon to start service.sh. Modify service.sh to respect signals, and not exit immediately when sleep exits due to SIGTERM. Remove PID file in signal callback and make sure to exit OK The test itself is basically a copy of the start-stop-service.sh test. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
2002157032
commit
4755e5206b
5 files changed
+103
-6
No files matched your search
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/sh
|
||||
# SysV style start script for service.sh
|
||||
|
||||
DAEMON="/test_assets/service.sh"
|
||||
PIDFILE="/var/run/service.pid"
|
||||
|
||||
start() {
|
||||
printf 'Starting %s: ' "$DAEMON"
|
||||
start-stop-daemon -S -b -q -p "$PIDFILE" -x "$DAEMON"
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
stop() {
|
||||
printf 'Stopping %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -q -p "$PIDFILE"
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start|stop|restart)
|
||||
"$1";;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}, got $0 $1"
|
||||
exit 1
|
||||
esac
|
||||
+14
-5
@@ -1,15 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
cleanup()
|
||||
{
|
||||
echo "Got signal, stopping ..."
|
||||
rm -f /run/service.pid
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Hook SIGUSR1 and dump trace to file system
|
||||
# shellcheck disable=SC2172
|
||||
trap 'echo USR1 > /tmp/usr1.log' 10
|
||||
trap 'echo USR1 > /tmp/usr1.log' USR1
|
||||
trap cleanup INT
|
||||
trap cleanup TERM
|
||||
trap cleanup QUIT
|
||||
trap cleanup EXIT
|
||||
|
||||
echo $$ > /run/service.pid
|
||||
|
||||
# sleep may exit on known signal, so
|
||||
# we cannot use 'set -e'
|
||||
while true; do
|
||||
sleep 5
|
||||
sleep 1
|
||||
done
|
||||
|
||||
rm /run/service.pid
|
||||
Reference in new issue
Block a user