2020-05-08 01:26:53 +03:00
#!/usr/bin/env bash
2021-10-17 19:13:06 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2020-05-08 01:26:53 +03:00
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
2021-04-09 20:39:41 +03:00
set -eux
2023-05-16 21:41:35 +03:00
set -o pipefail
2020-05-08 01:26:53 +03:00
2023-05-16 21:41:35 +03:00
# Test start & stop operations without daemon-reload
at_exit( ) {
set +e
rm -f /run/systemd/system/testsuite-23-no-reload.{ service,target}
}
trap at_exit EXIT
cat >/run/systemd/system/testsuite-23-no-reload.target <<EOF
2020-05-08 01:26:53 +03:00
[ Unit]
2023-05-16 21:41:35 +03:00
Wants = testsuite-23-no-reload.service
2020-05-08 01:26:53 +03:00
EOF
systemctl daemon-reload
2023-05-16 21:41:35 +03:00
systemctl start testsuite-23-no-reload.target
2020-05-08 01:26:53 +03:00
# The filesystem on the test image, despite being ext4, seems to have a mtime
# granularity of one second, which means the manager's unit cache won't be
# marked as dirty when writing the unit file, unless we wait at least a full
# second after the previous daemon-reload.
2021-05-04 14:54:33 +03:00
# May 07 23:12:20 H testsuite-48.sh[30]: + cat
2023-05-16 21:41:35 +03:00
# May 07 23:12:20 H testsuite-48.sh[30]: + ls -l --full-time /etc/systemd/system/testsuite-23-no-reload.service
2021-05-04 14:54:33 +03:00
# May 07 23:12:20 H testsuite-48.sh[52]: -rw-r--r-- 1 root root 50 2020-05-07 23:12:20.000000000 +0100 /
2023-05-16 21:41:35 +03:00
# May 07 23:12:20 H testsuite-48.sh[30]: + stat -f --format=%t /etc/systemd/system/testsuite-23-no-reload.servic
2021-05-04 14:54:33 +03:00
# May 07 23:12:20 H testsuite-48.sh[53]: ef53
2020-06-16 20:46:55 +03:00
sleep 3.1
2020-05-08 01:26:53 +03:00
2023-05-16 21:41:35 +03:00
cat >/run/systemd/system/testsuite-23-no-reload.service <<EOF
2020-05-08 01:26:53 +03:00
[ Service]
ExecStart = /bin/sleep infinity
EOF
2023-05-16 21:41:35 +03:00
systemctl start testsuite-23-no-reload.service
2020-05-08 01:26:53 +03:00
2023-05-16 21:41:35 +03:00
systemctl is-active testsuite-23-no-reload.service
2020-05-08 01:26:53 +03:00
2020-06-16 20:46:55 +03:00
# Stop and remove, and try again to exercise https://github.com/systemd/systemd/issues/15992
2023-05-16 21:41:35 +03:00
systemctl stop testsuite-23-no-reload.service
rm -f /run/systemd/system/testsuite-23-no-reload.service
2020-06-16 20:46:55 +03:00
systemctl daemon-reload
sleep 3.1
2023-05-16 21:41:35 +03:00
cat >/run/systemd/system/testsuite-23-no-reload.service <<EOF
2020-06-16 20:46:55 +03:00
[ Service]
ExecStart = /bin/sleep infinity
EOF
# Start a non-existing unit first, so that the cache is reloaded for an unrelated
# reason. Starting the existing unit later should still work thanks to the check
# for the last load attempt vs cache timestamp.
2023-05-16 21:41:35 +03:00
systemctl start testsuite-23-no-reload-nonexistent.service || true
2020-06-16 20:46:55 +03:00
2023-05-16 21:41:35 +03:00
systemctl start testsuite-23-no-reload.service
2020-06-16 20:46:55 +03:00
2023-05-16 21:41:35 +03:00
systemctl is-active testsuite-23-no-reload.service
2020-06-16 20:46:55 +03:00
2020-07-03 20:45:19 +03:00
# Stop and remove, and try again to exercise the transaction setup code path by
# having the target pull in the unloaded but available unit
2023-05-16 21:41:35 +03:00
systemctl stop testsuite-23-no-reload.service testsuite-23-no-reload.target
rm -f /run/systemd/system/testsuite-23-no-reload.service /run/systemd/system/testsuite-23-no-reload.target
2020-07-03 20:45:19 +03:00
systemctl daemon-reload
sleep 3.1
2023-05-16 21:41:35 +03:00
cat >/run/systemd/system/testsuite-23-no-reload.target <<EOF
2020-07-03 20:45:19 +03:00
[ Unit]
Conflicts = shutdown.target
2023-05-16 21:41:35 +03:00
Wants = testsuite-23-no-reload.service
2020-07-03 20:45:19 +03:00
EOF
systemctl daemon-reload
2023-05-16 21:41:35 +03:00
systemctl start testsuite-23-no-reload.target
2020-07-03 20:45:19 +03:00
2023-05-16 21:41:35 +03:00
cat >/run/systemd/system/testsuite-23-no-reload.service <<EOF
2020-07-03 20:45:19 +03:00
[ Service]
ExecStart = /bin/sleep infinity
EOF
2023-05-16 21:41:35 +03:00
systemctl restart testsuite-23-no-reload.target
2020-05-08 01:26:53 +03:00
2023-05-16 21:41:35 +03:00
systemctl is-active testsuite-23-no-reload.service