]>
Commit | Line | Data |
---|---|---|
ff12a795 | 1 | #!/usr/bin/env bash |
10e72727 CZ |
2 | set -ex |
3 | set -o pipefail | |
4 | ||
dfec314d DS |
5 | # wait this many secs for each test service to succeed in what is being tested |
6 | MAX_SECS=60 | |
7 | ||
10e72727 CZ |
8 | systemd-analyze log-level debug |
9 | systemd-analyze log-target console | |
10 | ||
dfec314d | 11 | # test one: Restart=on-failure should restart the service |
10e72727 CZ |
12 | ! systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" |
13 | ||
dfec314d | 14 | for ((secs=0; secs<$MAX_SECS; secs++)); do |
5522e628 | 15 | [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break |
dfec314d DS |
16 | sleep 1 |
17 | done | |
5522e628 | 18 | if [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]]; then |
10e72727 CZ |
19 | exit 1 |
20 | fi | |
21 | ||
0ac5dbf3 | 22 | TMP_FILE="/tmp/test-41-oneshot-restart-test" |
10e72727 | 23 | |
0ac5dbf3 | 24 | : >$TMP_FILE |
10e72727 | 25 | |
dfec314d DS |
26 | # test two: make sure StartLimitBurst correctly limits the number of restarts |
27 | # and restarts execution of the unit from the first ExecStart= | |
28 | ! systemd-run --unit=two -p StartLimitIntervalSec=120 -p StartLimitBurst=3 -p Type=oneshot -p Restart=on-failure -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" | |
10e72727 | 29 | |
dfec314d DS |
30 | # wait for at least 3 restarts |
31 | for ((secs=0; secs<$MAX_SECS; secs++)); do | |
32 | [[ $(cat $TMP_FILE) != "aaa" ]] || break | |
33 | sleep 1 | |
34 | done | |
35 | if [[ $(cat $TMP_FILE) != "aaa" ]]; then | |
36 | exit 1 | |
37 | fi | |
10e72727 | 38 | |
dfec314d DS |
39 | # wait for 5 more seconds to make sure there aren't excess restarts |
40 | sleep 5 | |
10e72727 CZ |
41 | if [[ $(cat $TMP_FILE) != "aaa" ]]; then |
42 | exit 1 | |
43 | fi | |
44 | ||
45 | systemd-analyze log-level info | |
46 | ||
47 | echo OK > /testok | |
48 | ||
49 | exit 0 |