]>
Commit | Line | Data |
---|---|---|
f209d8f5 | 1 | #!/usr/bin/env bash |
7b3cec95 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
f209d8f5 PM |
3 | set -eux |
4 | set -o pipefail | |
5 | ||
6 | fail () { | |
7 | systemd-analyze log-level info | |
8 | exit 1 | |
9 | } | |
10 | ||
11 | # Wait for a service to enter a state within a timeout period, if it doesn't | |
12 | # enter the desired state within the timeout period then this function will | |
13 | # exit the test case with a non zero exit code. | |
14 | wait_on_state_or_fail () { | |
15 | service=$1 | |
16 | expected_state=$2 | |
17 | timeout=$3 | |
18 | ||
19 | state=$(systemctl show "$service" --property=ActiveState --value) | |
20 | while [ "$state" != "$expected_state" ]; do | |
21 | if [ "$timeout" = "0" ]; then | |
22 | fail | |
23 | fi | |
24 | timeout=$((timeout - 1)) | |
25 | sleep 1 | |
26 | state=$(systemctl show "$service" --property=ActiveState --value) | |
27 | done | |
28 | } | |
29 | ||
30 | systemd-analyze log-level debug | |
31 | systemd-analyze log-target console | |
32 | ||
33 | ||
34 | cat >/run/systemd/system/testservice-fail-59.service <<EOF | |
35 | [Unit] | |
36 | Description=TEST-59-RELOADING-RESTART Normal exit | |
37 | ||
38 | [Service] | |
39 | Type=notify | |
40 | ExecStart=/bin/bash -c "systemd-notify --ready; systemd-notify RELOADING=1; sleep 1; exit 1" | |
41 | EOF | |
42 | ||
43 | cat >/run/systemd/system/testservice-fail-restart-59.service <<EOF | |
44 | [Unit] | |
45 | Description=TEST-59-RELOADING-RESTART Restart=on-failure | |
46 | ||
47 | [Service] | |
48 | Type=notify | |
49 | ExecStart=/bin/bash -c "systemd-notify --ready; systemd-notify RELOADING=1; sleep 1; exit 1" | |
50 | Restart=on-failure | |
51 | StartLimitBurst=1 | |
52 | EOF | |
53 | ||
54 | ||
55 | cat >/run/systemd/system/testservice-abort-restart-59.service <<EOF | |
56 | [Unit] | |
57 | Description=TEST-59-RELOADING-RESTART Restart=on-abort | |
58 | ||
59 | [Service] | |
60 | Type=notify | |
61 | ExecStart=/bin/bash -c "systemd-notify --ready; systemd-notify RELOADING=1; sleep 5; exit 1" | |
62 | Restart=on-abort | |
63 | EOF | |
64 | ||
65 | systemctl daemon-reload | |
66 | ||
67 | # This service sends a RELOADING=1 message then exits before it sends a | |
68 | # READY=1. Ensure it enters failed state and does not linger in reloading | |
69 | # state. | |
70 | systemctl start testservice-fail-59.service | |
71 | wait_on_state_or_fail "testservice-fail-59.service" "failed" "30" | |
72 | ||
73 | # This service sends a RELOADING=1 message then exits before it sends a | |
74 | # READY=1. It should automatically restart on failure. Ensure it enters failed | |
75 | # state and does not linger in reloading state. | |
76 | systemctl start testservice-fail-restart-59.service | |
77 | wait_on_state_or_fail "testservice-fail-restart-59.service" "failed" "30" | |
78 | ||
79 | # This service sends a RELOADING=1 message then exits before it sends a | |
80 | # READY=1. It should automatically restart on abort. It will sleep for 5s | |
81 | # to allow us to send it a SIGABRT. Ensure the service enters the failed state | |
82 | # and does not linger in reloading state. | |
83 | systemctl start testservice-abort-restart-59.service | |
84 | systemctl --signal=SIGABRT kill testservice-abort-restart-59.service | |
85 | wait_on_state_or_fail "testservice-abort-restart-59.service" "failed" "30" | |
86 | ||
87 | systemd-analyze log-level info | |
88 | ||
89 | echo OK >/testok | |
90 | ||
91 | exit 0 |