diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fecaf930..f430f237 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: | sudo apt-get -y update - sudo apt-get -y install pkg-config tree + sudo apt-get -y install pkg-config tree jq wget https://github.com/troglobit/libuev/releases/download/v2.3.2/libuev-2.3.2.tar.xz wget https://github.com/troglobit/libite/releases/download/v2.5.2/libite-2.5.2.tar.gz tar xf libuev-2.3.2.tar.xz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fcda5f91..4b83a8d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,7 +42,7 @@ jobs: - name: Installing dependencies run: | sudo apt-get -y update - sudo apt-get -y install pkg-config + sudo apt-get -y install pkg-config jq wget https://github.com/troglobit/libuev/releases/download/v2.3.2/libuev-2.3.2.tar.xz wget https://github.com/troglobit/libite/releases/download/v2.5.2/libite-2.5.2.tar.gz tar xf libuev-2.3.2.tar.xz diff --git a/test/Makefile.am b/test/Makefile.am index ff57c599..824728ef 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -33,6 +33,7 @@ EXTRA_DIST += runlevel.sh EXTRA_DIST += start-stop-service.sh EXTRA_DIST += start-stop-service-sub-config.sh EXTRA_DIST += start-kill-service.sh +EXTRA_DIST += start-kill-stop.sh EXTRA_DIST += start-stop-sysv.sh EXTRA_DIST += start-stop-serv.sh EXTRA_DIST += signal-service.sh @@ -65,6 +66,7 @@ TESTS += runlevel.sh TESTS += start-stop-service.sh TESTS += start-stop-service-sub-config.sh TESTS += start-kill-service.sh +TESTS += start-kill-stop.sh TESTS += start-stop-sysv.sh TESTS += start-stop-serv.sh TESTS += signal-service.sh diff --git a/test/start-kill-stop.sh b/test/start-kill-stop.sh new file mode 100755 index 00000000..3976c645 --- /dev/null +++ b/test/start-kill-stop.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# Regression test for Finit bug #313: +# - services get the 'forking' flag on initctl reload +# - stopping a crashing task while its restart callback is pending +# causes state 'running' with pid:0 (i.e., not running at all.) +# + +set -eu + +TEST_DIR=$(dirname "$0") + +# shellcheck source=/dev/null +. "$TEST_DIR/tenv/lib.sh" + +test_teardown() +{ +# texec sh -c "initctl status -j serv" + say "Test done $(date)" + say "Running test teardown." + + texec rm -f "$FINIT_CONF" +} + +say "Check deps ..." +check_dep jq +check_dep fozza + + +say "Test start $(date)" +rm -f "$TENV_ROOT"/oldpid + +say "Add service stanza in $FINIT_CONF" +texec sh -c "echo 'service [2345] log:stderr serv -np -- Test service' > $FINIT_CONF" + +say 'Reload Finit' +texec sh -c "initctl reload" + +say 'Verify serv is running ...' +retry 'assert_num_children 1 serv' + +say 'Verify reload does not change forking type of service' +#texec sh -c "initctl status -j serv" +texec sh -c "initctl reload" +#texec sh -c "initctl status -j serv" +assert_forking serv false + +say 'Simulate service crash (kill -9 ..)' +texec sh -c "initctl debug" +i=0 +laps=7 +while [ $i -lt $laps ]; do + i=$((i + 1)) + say "Lap $i/$laps, killing service ..." # we have this, no sleep needed + texec sh -c "slay serv" +done + +say 'Verify stopping service actually stops it' +sleep 1 +texec sh -c "initctl stop serv" +sleep 5 +#texec sh -c "initctl status serv" +assert_status serv stopped + +say 'Verify restarting service actually starts it' +texec sh -c "initctl start serv" +retry 'assert_num_children 1 serv' diff --git a/test/tenv/lib.sh b/test/tenv/lib.sh index 63cbb588..b07168a1 100755 --- a/test/tenv/lib.sh +++ b/test/tenv/lib.sh @@ -36,6 +36,16 @@ assert_num_services() assert "$1 services are loaded" "$(texec initctl -t status "$2" | wc -l)" -eq "$1" } +assert_forking() +{ + assert "service $1 forking:$2" "$(texec initctl -j status "$1" | jq -M .forking)" = "$2" +} + +assert_nopid() +{ + assert "service $1 pid:0" "$(texec initctl -j status "$1" | jq -M .pid)" -eq 0 +} + # shellcheck disable=SC2086 assert_new_pid() {