]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/units/testsuite-41.sh
scope: on unified, make sure to unwatch all PIDs once they've been moved to the cgrou...
[thirdparty/systemd.git] / test / units / testsuite-41.sh
CommitLineData
ff12a795 1#!/usr/bin/env bash
10e72727
CZ
2set -ex
3set -o pipefail
4
dfec314d
DS
5# wait this many secs for each test service to succeed in what is being tested
6MAX_SECS=60
7
10e72727
CZ
8systemd-analyze log-level debug
9systemd-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 14for ((secs=0; secs<$MAX_SECS; secs++)); do
5522e628 15 [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break
dfec314d
DS
16 sleep 1
17done
5522e628 18if [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]]; then
10e72727
CZ
19 exit 1
20fi
21
0ac5dbf3 22TMP_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
31for ((secs=0; secs<$MAX_SECS; secs++)); do
32 [[ $(cat $TMP_FILE) != "aaa" ]] || break
33 sleep 1
34done
35if [[ $(cat $TMP_FILE) != "aaa" ]]; then
36 exit 1
37fi
10e72727 38
dfec314d
DS
39# wait for 5 more seconds to make sure there aren't excess restarts
40sleep 5
10e72727
CZ
41if [[ $(cat $TMP_FILE) != "aaa" ]]; then
42 exit 1
43fi
44
45systemd-analyze log-level info
46
47echo OK > /testok
48
49exit 0