]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/units/testsuite-41.sh
test: drop whitespace after shell redirection operators
[thirdparty/systemd.git] / test / units / testsuite-41.sh
CommitLineData
ff12a795 1#!/usr/bin/env bash
7b3cec95 2# SPDX-License-Identifier: LGPL-2.1-or-later
084575ff 3set -eux
10e72727
CZ
4set -o pipefail
5
dfec314d
DS
6# wait this many secs for each test service to succeed in what is being tested
7MAX_SECS=60
8
10e72727 9systemd-analyze log-level debug
10e72727 10
dfec314d 11# test one: Restart=on-failure should restart the service
4e20fe27
ZJS
12systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" \
13 && { echo 'unexpected success'; exit 1; }
10e72727 14
f7940983 15for ((secs = 0; secs < MAX_SECS; secs++)); do
5522e628 16 [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break
dfec314d
DS
17 sleep 1
18done
5522e628 19if [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]]; then
10e72727
CZ
20 exit 1
21fi
22
0ac5dbf3 23TMP_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
29systemd-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 38for ((secs = 0; secs < MAX_SECS; secs++)); do
dfec314d
DS
39 [[ $(cat $TMP_FILE) != "aaa" ]] || break
40 sleep 1
41done
42if [[ $(cat $TMP_FILE) != "aaa" ]]; then
43 exit 1
44fi
10e72727 45
dfec314d
DS
46# wait for 5 more seconds to make sure there aren't excess restarts
47sleep 5
10e72727
CZ
48if [[ $(cat $TMP_FILE) != "aaa" ]]; then
49 exit 1
50fi
51
52systemd-analyze log-level info
53
0ee99483 54echo OK >/testok
10e72727
CZ
55
56exit 0