2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2019-08-10 17:03:07 +03:00
2021-04-09 20:39:41 +03:00
set -eux
2019-08-10 17:03:07 +03:00
set -o pipefail
systemd-analyze log-level debug
systemd-analyze log-target console
export SYSTEMD_PAGER =
SERVICE_PATH = " $( mktemp /etc/systemd/system/execreloadXXX.service) "
SERVICE_NAME = " ${ SERVICE_PATH ##*/ } "
echo "[#1] Failing ExecReload= should not kill the service"
2021-04-08 01:09:55 +03:00
cat >" $SERVICE_PATH " <<EOF
2019-08-10 17:03:07 +03:00
[ Service]
ExecStart = /bin/sleep infinity
ExecReload = /bin/false
EOF
systemctl daemon-reload
2021-04-09 20:49:32 +03:00
systemctl start " $SERVICE_NAME "
systemctl status " $SERVICE_NAME "
2019-08-10 17:03:07 +03:00
# The reload SHOULD fail but SHOULD NOT affect the service state
2021-04-09 20:49:32 +03:00
systemctl reload " $SERVICE_NAME " && { echo 'unexpected success' ; exit 1; }
systemctl status " $SERVICE_NAME "
systemctl stop " $SERVICE_NAME "
2019-08-10 17:03:07 +03:00
echo "[#2] Failing ExecReload= should not kill the service (multiple ExecReload=)"
2021-04-08 01:09:55 +03:00
cat >" $SERVICE_PATH " <<EOF
2019-08-10 17:03:07 +03:00
[ Service]
ExecStart = /bin/sleep infinity
ExecReload = /bin/true
ExecReload = /bin/false
ExecReload = /bin/true
EOF
systemctl daemon-reload
2021-04-09 20:49:32 +03:00
systemctl start " $SERVICE_NAME "
systemctl status " $SERVICE_NAME "
2019-08-10 17:03:07 +03:00
# The reload SHOULD fail but SHOULD NOT affect the service state
2021-04-09 20:49:32 +03:00
systemctl reload " $SERVICE_NAME " && { echo 'unexpected success' ; exit 1; }
systemctl status " $SERVICE_NAME "
systemctl stop " $SERVICE_NAME "
2019-08-10 17:03:07 +03:00
echo "[#3] Failing ExecReload=- should not affect reload's exit code"
2021-04-08 01:09:55 +03:00
cat >" $SERVICE_PATH " <<EOF
2019-08-10 17:03:07 +03:00
[ Service]
ExecStart = /bin/sleep infinity
ExecReload = -/bin/false
EOF
systemctl daemon-reload
2021-04-09 20:49:32 +03:00
systemctl start " $SERVICE_NAME "
systemctl status " $SERVICE_NAME "
systemctl reload " $SERVICE_NAME "
systemctl status " $SERVICE_NAME "
systemctl stop " $SERVICE_NAME "
2019-08-10 17:03:07 +03:00
systemd-analyze log-level info
2021-04-08 01:09:55 +03:00
echo OK >/testok
2019-08-10 17:03:07 +03:00
exit 0