diff --git a/test/Makefile.am b/test/Makefile.am index 51f18baf..6adc82d8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -38,6 +38,7 @@ EXTRA_DIST += restart-self.sh EXTRA_DIST += runlevel.sh EXTRA_DIST += run-restart-forever.sh EXTRA_DIST += run-task-tricks.sh +EXTRA_DIST += runparts.sh EXTRA_DIST += start-stop-service.sh EXTRA_DIST += start-stop-service-sub-config.sh EXTRA_DIST += start-kill-service.sh @@ -79,6 +80,7 @@ TESTS += restart-self.sh TESTS += runlevel.sh TESTS += run-restart-forever.sh TESTS += run-task-tricks.sh +TESTS += runparts.sh TESTS += start-stop-service.sh TESTS += start-stop-service-sub-config.sh TESTS += start-kill-service.sh diff --git a/test/lib/setup.sh b/test/lib/setup.sh index 85be8756..eca4877b 100755 --- a/test/lib/setup.sh +++ b/test/lib/setup.sh @@ -305,6 +305,15 @@ if [ -n "$BOOTSTRAP" ]; then say "Setting up bootstrap tasks ..." echo "$BOOTSTRAP" >> "$SYSROOT$FINIT_CONF" fi + +if [ -n "$RUNPARTS" ]; then + say "Setting up runparts task ..." + echo "runparts /etc/rc.d" >> "$SYSROOT$FINIT_CONF" + mkdir "$SYSROOT/etc/rc.d" + echo "$RUNPARTS" > "$SYSROOT/etc/rc.d/start.sh" + chmod +x "$SYSROOT/etc/rc.d/start.sh" +fi + if [ -n "$RCLOCAL" ]; then while [ -f "$SYSROOT/etc/rc.local" ]; do echo "$SYSROOT/etc/rc.local busy ... waiting ..." diff --git a/test/runparts.sh b/test/runparts.sh new file mode 100755 index 00000000..44d5f06c --- /dev/null +++ b/test/runparts.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Verifies basic runparts behavior: to run all scripts in a directory at +# the end of system bootstrap, right before calling /etc/rc.local: +# +# - only executable scripts should be called +# - always in alphabetical order +# - SNNfoo should be called with a 'start' argument +# - KNNfoo should be called with a 'stop' argument +# + +TEST_DIR=$(dirname "$0") +#DEBUG=1 + +# shellcheck disable=SC2034 +BOOTSTRAP="runparts /etc/rc.d" + +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + +test_setup() +{ + say "Test start $(date)" + } + +test_teardown() +{ + say "Test done $(date)" +} + +while true; do + lvl=$(texec initctl runlevel) + say "Current runlevel $lvl" + if [ "$lvl" = "N 2" ]; then + break; + fi + sleep 1 +done + +texec diff -u /usr/share/runlevel/ref.log /tmp/runparts.log +texec cmp /usr/share/runlevel/ref.log /tmp/runparts.log || fail "runparts in wrong order" diff --git a/test/skel/etc/rc.d/S01abc.sh b/test/skel/etc/rc.d/S01abc.sh new file mode 100755 index 00000000..609428a2 --- /dev/null +++ b/test/skel/etc/rc.d/S01abc.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "$0 $*" >> /tmp/runparts.log diff --git a/test/skel/etc/rc.d/S02def.sh b/test/skel/etc/rc.d/S02def.sh new file mode 120000 index 00000000..21643413 --- /dev/null +++ b/test/skel/etc/rc.d/S02def.sh @@ -0,0 +1 @@ +S01abc.sh \ No newline at end of file diff --git a/test/skel/etc/rc.d/foo.sh b/test/skel/etc/rc.d/foo.sh new file mode 100755 index 00000000..3752cd1f --- /dev/null +++ b/test/skel/etc/rc.d/foo.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "$0" >> /tmp/runparts.log diff --git a/test/skel/etc/rc.d/test.sh b/test/skel/etc/rc.d/test.sh new file mode 100755 index 00000000..3752cd1f --- /dev/null +++ b/test/skel/etc/rc.d/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "$0" >> /tmp/runparts.log