summaryrefslogtreecommitdiff
path: root/test/units/testsuite-48.sh
blob: 2b5b86f6e8ba6cd27daccbbe99e944ed18d06545 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -eux

cat >/run/systemd/system/testservice-48.target <<EOF
[Unit]
Wants=testservice-48.service
EOF

systemctl daemon-reload

systemctl start testservice-48.target

# 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.
# May 07 23:12:20 H testsuite-48.sh[30]: + cat
# May 07 23:12:20 H testsuite-48.sh[30]: + ls -l --full-time /etc/systemd/system/testservice-48.service
# 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 /
# May 07 23:12:20 H testsuite-48.sh[30]: + stat -f --format=%t /etc/systemd/system/testservice-48.servic
# May 07 23:12:20 H testsuite-48.sh[53]: ef53
sleep 3.1

cat >/run/systemd/system/testservice-48.service <<EOF
[Service]
ExecStart=/bin/sleep infinity
EOF

systemctl start testservice-48.service

systemctl is-active testservice-48.service

# Stop and remove, and try again to exercise https://github.com/systemd/systemd/issues/15992
systemctl stop testservice-48.service
rm -f /run/systemd/system/testservice-48.service
systemctl daemon-reload

sleep 3.1

cat >/run/systemd/system/testservice-48.service <<EOF
[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.
systemctl start testservice-48-nonexistent.service || true

systemctl start testservice-48.service

systemctl is-active testservice-48.service

# Stop and remove, and try again to exercise the transaction setup code path by
# having the target pull in the unloaded but available unit
systemctl stop testservice-48.service testservice-48.target
rm -f /run/systemd/system/testservice-48.service /run/systemd/system/testservice-48.target
systemctl daemon-reload

sleep 3.1

cat >/run/systemd/system/testservice-48.target <<EOF
[Unit]
Conflicts=shutdown.target
Wants=testservice-48.service
EOF

systemctl daemon-reload

systemctl start testservice-48.target

cat >/run/systemd/system/testservice-48.service <<EOF
[Service]
ExecStart=/bin/sleep infinity
EOF

systemctl restart testservice-48.target

systemctl is-active testservice-48.service

echo OK >/testok

exit 0