1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -eux
4set -o pipefail
5
6systemd-analyze log-level debug
7systemd-analyze log-target console
8
9export SYSTEMD_PAGER=
10SERVICE_PATH="$(mktemp /etc/systemd/system/execreloadXXX.service)"
11SERVICE_NAME="${SERVICE_PATH##*/}"
12
13echo "[#1] Failing ExecReload= should not kill the service"
14cat >"$SERVICE_PATH" <<EOF
15[Service]
16ExecStart=/bin/sleep infinity
17ExecReload=/bin/false
18EOF
19
20systemctl daemon-reload
21systemctl start "$SERVICE_NAME"
22systemctl status "$SERVICE_NAME"
23# The reload SHOULD fail but SHOULD NOT affect the service state
24systemctl reload "$SERVICE_NAME" && { echo 'unexpected success'; exit 1; }
25systemctl status "$SERVICE_NAME"
26systemctl stop "$SERVICE_NAME"
27
28
29echo "[#2] Failing ExecReload= should not kill the service (multiple ExecReload=)"
30cat >"$SERVICE_PATH" <<EOF
31[Service]
32ExecStart=/bin/sleep infinity
33ExecReload=/bin/true
34ExecReload=/bin/false
35ExecReload=/bin/true
36EOF
37
38systemctl daemon-reload
39systemctl start "$SERVICE_NAME"
40systemctl status "$SERVICE_NAME"
41# The reload SHOULD fail but SHOULD NOT affect the service state
42systemctl reload "$SERVICE_NAME" && { echo 'unexpected success'; exit 1; }
43systemctl status "$SERVICE_NAME"
44systemctl stop "$SERVICE_NAME"
45
46echo "[#3] Failing ExecReload=- should not affect reload's exit code"
47cat >"$SERVICE_PATH" <<EOF
48[Service]
49ExecStart=/bin/sleep infinity
50ExecReload=-/bin/false
51EOF
52
53systemctl daemon-reload
54systemctl start "$SERVICE_NAME"
55systemctl status "$SERVICE_NAME"
56systemctl reload "$SERVICE_NAME"
57systemctl status "$SERVICE_NAME"
58systemctl stop "$SERVICE_NAME"
59
60systemd-analyze log-level info
61
62echo OK >/testok
63
64exit 0
65