Files
finit/test/start-stop-serv.sh
T
Joachim Wiberg c926160853 Issue #223: add type:forking service option, with updated docs
- Add `type:forking` service option to trigger guessing pidfile to
   watch for, instead of `pid:!foo` option, which is not intuitive.
   This option may likely also survive into the new file format :)
 - Update docs and add examples
 - Update start-stop-serv.sh test case with this new variant

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-04 19:13:28 +02:00

69 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
set -eu
TEST_DIR=$(dirname "$0")
test_setup()
{
say "Test start $(date)"
cp "$TENV_ROOT"/../common/serv "$TENV_ROOT"/test_assets/
}
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/serv
}
test_one()
{
pidfn=$1
service=$2
say "Add service stanza '$service' to $FINIT_CONF ..."
texec sh -c "echo '$service' > $FINIT_CONF"
say 'Reload Finit'
#texec sh -c "initctl debug"
texec sh -c "initctl reload"
#texec sh -c "initctl status"
#texec sh -c "ps"
#texec sh -c "initctl status"
#texec sh -c "ps"
#texec sh -c "initctl status serv"
retry 'assert_num_children 1 serv'
retry "assert_pidfile $pidfn" 1
say 'Stop the service'
texec sh -c "initctl stop serv"
retry 'assert_num_children 0 serv'
say 'Start the service again'
texec sh -c "initctl start serv"
retry 'assert_num_children 1 serv'
say "Done, drop service from $FINIT_CONF ..."
texec sh -c "rm $FINIT_CONF"
texec sh -c "initctl reload"
}
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_one "/run/serv.pid" "service pid:!/run/serv.pid /test_assets/serv -- Forking service, type 1"
test_one "/run/serv.pid" "service type:forking /test_assets/serv -- Forking service, type 2"
# This one could never be started by and monitored by Finit: it forks to
# background and does not create a PID file. Essentially it's lost to
# Finit, and any other sane process monitor.
#test_one "/run/serv.pid" "service pid:/run/serv.pid /test_assets/serv -p -- Forking service w/o PID file"
test_one "/run/serv.pid" "service pid:/run/serv.pid /test_assets/serv -n -- Foreground service w/o PID file"
test_one "/run/serv.pid" "service /test_assets/serv -n -p -- Foreground service w/ PID file"
test_one "/run/servy.pid" "service pid:/run/servy.pid /test_assets/serv -n -p -P /run/servy.pid -- Foreground service w/ custom PID file"