diff options
author | Anita Zhang <the.anitazha@gmail.com> | 2019-10-16 14:21:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-16 14:21:59 -0700 |
commit | d727acb6505743098aa1c8bb1c4c473b5fab1379 (patch) | |
tree | 074be77989dd0b414784c055ac2eb5e5ae91810d /test | |
parent | f19ede681437b33a675ff93625312b50f59f2c05 (diff) | |
parent | 10e72727eeeeb1a495303ec406fa8d1e1a83dc6e (diff) | |
download | systemd-d727acb6505743098aa1c8bb1c4c473b5fab1379.tar.gz systemd-d727acb6505743098aa1c8bb1c4c473b5fab1379.tar.bz2 systemd-d727acb6505743098aa1c8bb1c4c473b5fab1379.zip |
Merge pull request #13754 from claudiozz/master
Allow restart for oneshot units
Diffstat (limited to 'test')
-rw-r--r-- | test/TEST-41-ONESHOT-RESTART/Makefile | 9 | ||||
-rwxr-xr-x | test/TEST-41-ONESHOT-RESTART/test.sh | 32 | ||||
-rwxr-xr-x | test/TEST-41-ONESHOT-RESTART/testsuite.sh | 33 |
3 files changed, 74 insertions, 0 deletions
diff --git a/test/TEST-41-ONESHOT-RESTART/Makefile b/test/TEST-41-ONESHOT-RESTART/Makefile new file mode 100644 index 0000000000..45e9bfc67c --- /dev/null +++ b/test/TEST-41-ONESHOT-RESTART/Makefile @@ -0,0 +1,9 @@ +BUILD_DIR=$(shell ../../tools/find-build-dir.sh) + +all setup run: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ + +clean clean-again: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --clean + +.PHONY: all setup run clean clean-again diff --git a/test/TEST-41-ONESHOT-RESTART/test.sh b/test/TEST-41-ONESHOT-RESTART/test.sh new file mode 100755 index 0000000000..96c21da642 --- /dev/null +++ b/test/TEST-41-ONESHOT-RESTART/test.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e +TEST_DESCRIPTION="Test oneshot unit restart on failure" +. $TEST_BASE_DIR/test-functions + +test_setup() { + create_empty_image_rootdir + + ( + LOG_LEVEL=5 + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + setup_basic_environment + mask_supporting_services + + # setup the testsuite service + cat >$initdir/etc/systemd/system/testsuite.service <<EOF +[Unit] +Description=Testsuite service + +[Service] +ExecStart=/testsuite.sh +Type=oneshot +EOF + cp testsuite.sh $initdir/ + + setup_testsuite + ) + setup_nspawn_root +} + +do_test "$@" diff --git a/test/TEST-41-ONESHOT-RESTART/testsuite.sh b/test/TEST-41-ONESHOT-RESTART/testsuite.sh new file mode 100755 index 0000000000..f7423dbf9a --- /dev/null +++ b/test/TEST-41-ONESHOT-RESTART/testsuite.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -ex +set -o pipefail + +systemd-analyze log-level debug +systemd-analyze log-target console + +# These three commands should succeed. +! systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" + +sleep 5 + +if [[ "$(systemctl show one.service -p NRestarts --value)" -le 0 ]]; then + exit 1 +fi + +TMP_FILE="/test-41-oneshot-restart-test" + +touch $TMP_FILE + +! systemd-run --unit=two -p StartLimitBurst=3 -p Type=oneshot -p Restart=on-failure -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" + +sleep 5 + +if [[ $(cat $TMP_FILE) != "aaa" ]]; then + exit 1 +fi + +systemd-analyze log-level info + +echo OK > /testok + +exit 0 |