]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-48.sh
tests: add spdx headers to scripts and Makefiles
[thirdparty/systemd.git] / test / units / testsuite-48.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
4 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 set -eux
6
7 cat >/run/systemd/system/testservice-48.target <<EOF
8 [Unit]
9 Wants=testservice-48.service
10 EOF
11
12 systemctl daemon-reload
13
14 systemctl start testservice-48.target
15
16 # The filesystem on the test image, despite being ext4, seems to have a mtime
17 # granularity of one second, which means the manager's unit cache won't be
18 # marked as dirty when writing the unit file, unless we wait at least a full
19 # second after the previous daemon-reload.
20 # May 07 23:12:20 H testsuite-48.sh[30]: + cat
21 # May 07 23:12:20 H testsuite-48.sh[30]: + ls -l --full-time /etc/systemd/system/testservice-48.service
22 # 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 /
23 # May 07 23:12:20 H testsuite-48.sh[30]: + stat -f --format=%t /etc/systemd/system/testservice-48.servic
24 # May 07 23:12:20 H testsuite-48.sh[53]: ef53
25 sleep 3.1
26
27 cat >/run/systemd/system/testservice-48.service <<EOF
28 [Service]
29 ExecStart=/bin/sleep infinity
30 EOF
31
32 systemctl start testservice-48.service
33
34 systemctl is-active testservice-48.service
35
36 # Stop and remove, and try again to exercise https://github.com/systemd/systemd/issues/15992
37 systemctl stop testservice-48.service
38 rm -f /run/systemd/system/testservice-48.service
39 systemctl daemon-reload
40
41 sleep 3.1
42
43 cat >/run/systemd/system/testservice-48.service <<EOF
44 [Service]
45 ExecStart=/bin/sleep infinity
46 EOF
47
48 # Start a non-existing unit first, so that the cache is reloaded for an unrelated
49 # reason. Starting the existing unit later should still work thanks to the check
50 # for the last load attempt vs cache timestamp.
51 systemctl start testservice-48-nonexistent.service || true
52
53 systemctl start testservice-48.service
54
55 systemctl is-active testservice-48.service
56
57 # Stop and remove, and try again to exercise the transaction setup code path by
58 # having the target pull in the unloaded but available unit
59 systemctl stop testservice-48.service testservice-48.target
60 rm -f /run/systemd/system/testservice-48.service /run/systemd/system/testservice-48.target
61 systemctl daemon-reload
62
63 sleep 3.1
64
65 cat >/run/systemd/system/testservice-48.target <<EOF
66 [Unit]
67 Conflicts=shutdown.target
68 Wants=testservice-48.service
69 EOF
70
71 systemctl daemon-reload
72
73 systemctl start testservice-48.target
74
75 cat >/run/systemd/system/testservice-48.service <<EOF
76 [Service]
77 ExecStart=/bin/sleep infinity
78 EOF
79
80 systemctl restart testservice-48.target
81
82 systemctl is-active testservice-48.service
83
84 echo OK >/testok
85
86 exit 0