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