]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/test-systemctl-enable.sh
test-network: update comment about status of kernel regression
[thirdparty/systemd.git] / test / test-systemctl-enable.sh
CommitLineData
50c5f5a3
ZJS
1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -ex
4
5# Silence warning from running_in_chroot_or_offline()
6export SYSTEMD_IGNORE_CHROOT=1
7
8systemctl=${1:-systemctl}
2a2d002f 9systemd_id128=${2:-systemd-id128}
50c5f5a3
ZJS
10
11unset root
12cleanup() {
13 [ -n "$root" ] && rm -rf "$root"
14}
15trap cleanup exit
16root=$(mktemp -d --tmpdir systemctl-test.XXXXXX)
17
18islink() {
19 test -h "$1" || return 1
20 test "$(readlink "$1")" = "$2" || return 2
21}
22
25cbc42d 23: '-------enable nonexistent--------------------------------------'
d6c51c48 24( ! "$systemctl" --root="$root" enable test1.service )
50c5f5a3 25
25cbc42d 26: '-------basic enablement----------------------------------------'
50c5f5a3
ZJS
27mkdir -p "$root/etc/systemd/system"
28cat >"$root/etc/systemd/system/test1.service" <<EOF
29[Install]
30WantedBy=default.target
31RequiredBy=special.target
32EOF
33
34"$systemctl" --root="$root" enable test1.service
35test -h "$root/etc/systemd/system/default.target.wants/test1.service"
36test -h "$root/etc/systemd/system/special.target.requires/test1.service"
37
38"$systemctl" --root="$root" reenable test1.service
39test -h "$root/etc/systemd/system/default.target.wants/test1.service"
40test -h "$root/etc/systemd/system/special.target.requires/test1.service"
41
42"$systemctl" --root="$root" disable test1.service
3fc53351
ZJS
43test ! -h "$root/etc/systemd/system/default.target.wants/test1.service"
44test ! -h "$root/etc/systemd/system/special.target.requires/test1.service"
45
25cbc42d 46: '-------enable when link already exists-------------------------'
3fc53351
ZJS
47# We don't read the symlink target, so it's OK for the symlink to point
48# to something else. We should just silently accept this.
49
50mkdir -p "$root/etc/systemd/system/default.target.wants"
51mkdir -p "$root/etc/systemd/system/special.target.requires"
52ln -s /usr/lib/systemd/system/test1.service "$root/etc/systemd/system/default.target.wants/test1.service"
53ln -s /usr/lib/systemd/system/test1.service "$root/etc/systemd/system/special.target.requires/test1.service"
54
55"$systemctl" --root="$root" enable test1.service
56test -h "$root/etc/systemd/system/default.target.wants/test1.service"
57test -h "$root/etc/systemd/system/special.target.requires/test1.service"
58
59"$systemctl" --root="$root" reenable test1.service
60test -h "$root/etc/systemd/system/default.target.wants/test1.service"
61test -h "$root/etc/systemd/system/special.target.requires/test1.service"
62
63"$systemctl" --root="$root" disable test1.service
64test ! -h "$root/etc/systemd/system/default.target.wants/test1.service"
65test ! -h "$root/etc/systemd/system/special.target.requires/test1.service"
50c5f5a3 66
25cbc42d 67: '-------suffix guessing-----------------------------------------'
50c5f5a3
ZJS
68"$systemctl" --root="$root" enable test1
69test -h "$root/etc/systemd/system/default.target.wants/test1.service"
70test -h "$root/etc/systemd/system/special.target.requires/test1.service"
71
72"$systemctl" --root="$root" reenable test1
73test -h "$root/etc/systemd/system/default.target.wants/test1.service"
74test -h "$root/etc/systemd/system/special.target.requires/test1.service"
75
76"$systemctl" --root="$root" disable test1
77test ! -e "$root/etc/systemd/system/default.target.wants/test1.service"
78test ! -e "$root/etc/systemd/system/special.target.requires/test1.service"
79
25cbc42d 80: '-------aliases-------------------------------------------------'
50c5f5a3
ZJS
81cat >>"$root/etc/systemd/system/test1.service" <<EOF
82Alias=test1-goodalias.service
83Alias=test1@badalias.service
84Alias=test1-badalias.target
85Alias=test1-badalias.socket
0d11db59
ZJS
86# we have a series of good, bad, and then good again
87Alias=test1-goodalias2.service
50c5f5a3
ZJS
88EOF
89
d6c51c48 90( ! "$systemctl" --root="$root" enable test1 )
0d11db59
ZJS
91test -h "$root/etc/systemd/system/default.target.wants/test1.service"
92test -h "$root/etc/systemd/system/special.target.requires/test1.service"
9aa3d6b4 93test ! -e "$root/etc/systemd/system/test1-goodalias.service"
0d11db59 94test -h "$root/etc/systemd/system/test1-goodalias.service"
9aa3d6b4
ZJS
95test ! -e "$root/etc/systemd/system/test1@badalias.service"
96test ! -e "$root/etc/systemd/system/test1-badalias.target"
97test ! -e "$root/etc/systemd/system/test1-badalias.socket"
0d11db59
ZJS
98test -h "$root/etc/systemd/system/test1-goodalias2.service"
99
25cbc42d 100: '-------aliases in reenable-------------------------------------'
d6c51c48 101( ! "$systemctl" --root="$root" reenable test1 )
9aa3d6b4
ZJS
102test -h "$root/etc/systemd/system/default.target.wants/test1.service"
103test ! -e "$root/etc/systemd/system/test1-goodalias.service"
104test -h "$root/etc/systemd/system/test1-goodalias.service"
50c5f5a3 105
9aa3d6b4
ZJS
106test ! -e "$root/etc/systemd/system/test1@badalias.service"
107test ! -e "$root/etc/systemd/system/test1-badalias.target"
108test ! -e "$root/etc/systemd/system/test1-badalias.socket"
50c5f5a3
ZJS
109
110"$systemctl" --root="$root" disable test1
9aa3d6b4
ZJS
111test ! -e "$root/etc/systemd/system/default.target.wants/test1.service"
112test ! -e "$root/etc/systemd/system/special.target.requires/test1.service"
113test ! -e "$root/etc/systemd/system/test1-goodalias.service"
50c5f5a3 114
25cbc42d 115: '-------aliases when link already exists------------------------'
3fc53351
ZJS
116cat >"$root/etc/systemd/system/test1a.service" <<EOF
117[Install]
118Alias=test1a-alias.service
119EOF
120
121ln -s /usr/lib/systemd/system/test1a.service "$root/etc/systemd/system/test1a-alias.service"
122
123"$systemctl" --root="$root" enable test1a.service
124test -h "$root/etc/systemd/system/test1a-alias.service"
125
126"$systemctl" --root="$root" disable test1a.service
127test ! -h "$root/etc/systemd/system/test1a-alias.service"
128
25cbc42d 129: '-------also units----------------------------------------------'
50c5f5a3
ZJS
130cat >"$root/etc/systemd/system/test2.socket" <<EOF
131[Install]
132WantedBy=sockets.target
133Also=test2.service
134EOF
135
136cat >"$root/etc/systemd/system/test2.service" <<EOF
137[Install]
138WantedBy=default.target
139Also=test2.socket
140EOF
141
142"$systemctl" --root="$root" reenable test2.service
143test -h "$root/etc/systemd/system/default.target.wants/test2.service"
144test -h "$root/etc/systemd/system/sockets.target.wants/test2.socket"
145
146"$systemctl" --root="$root" reenable test2.socket
147test -h "$root/etc/systemd/system/default.target.wants/test2.service"
148test -h "$root/etc/systemd/system/sockets.target.wants/test2.socket"
149
150"$systemctl" --root="$root" disable test2.socket
151test ! -e "$root/etc/systemd/system/default.target.wants/test2.service"
152test ! -e "$root/etc/systemd/system/sockets.target.wants/test2.socket"
153
154
25cbc42d 155: '-------link----------------------------------------------------'
50c5f5a3
ZJS
156# File doesn't exist yet
157test ! -e "$root/link1.path"
d6c51c48 158( ! "$systemctl" --root="$root" link '/link1.path' )
50c5f5a3
ZJS
159test ! -e "$root/etc/systemd/system/link1.path"
160
161cat >"$root/link1.path" <<EOF
162[Install]
163WantedBy=paths.target
164EOF
165
166"$systemctl" --root="$root" link '/link1.path'
167islink "$root/etc/systemd/system/link1.path" "/link1.path"
168
25cbc42d 169: '-------link already linked same path---------------------------'
50c5f5a3
ZJS
170SYSTEMD_LOG_LEVEL=debug "$systemctl" --root="$root" link '/link1.path' # this passes
171islink "$root/etc/systemd/system/link1.path" "/link1.path"
172
25cbc42d 173: '-------link already linked different path----------------------'
50c5f5a3
ZJS
174mkdir "$root/subdir"
175cp "$root/link1.path" "$root/subdir/"
d6c51c48 176( ! "$systemctl" --root="$root" link '/subdir/link1.path' )
50c5f5a3
ZJS
177islink "$root/etc/systemd/system/link1.path" "/link1.path"
178
25cbc42d 179: '-------link bad suffix-----------------------------------------'
50c5f5a3 180cp "$root/link1.path" "$root/subdir/link1.suffix"
d6c51c48 181( ! "$systemctl" --root="$root" link '/subdir/link1.suffix' )
50c5f5a3
ZJS
182test ! -e "$root/etc/systemd/system/link1.suffix"
183
25cbc42d 184: '-------unlink by unit name-------------------------------------'
50c5f5a3
ZJS
185"$systemctl" --root="$root" disable 'link1.path'
186test ! -e "$root/etc/systemd/system/link1.path"
187
25cbc42d 188: '-------unlink by path------------------------------------------'
50c5f5a3
ZJS
189"$systemctl" --root="$root" link '/link1.path'
190test -h "$root/etc/systemd/system/link1.path"
191"$systemctl" --root="$root" disable '/link1.path'
192test ! -e "$root/etc/systemd/system/link1.path"
193
25cbc42d 194: '-------unlink by wrong path------------------------------------'
50c5f5a3
ZJS
195"$systemctl" --root="$root" link '/link1.path'
196test -h "$root/etc/systemd/system/link1.path"
197"$systemctl" --root="$root" disable '/subdir/link1.path' # we only care about the name
198test ! -e "$root/etc/systemd/system/link1.path"
199
200
25cbc42d 201: '-------link and enable-----------------------------------------'
50c5f5a3
ZJS
202"$systemctl" --root="$root" enable '/link1.path'
203islink "$root/etc/systemd/system/link1.path" "/link1.path"
9aa3d6b4 204islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
50c5f5a3 205
25cbc42d 206: '-------enable already linked same path-------------------------'
50c5f5a3
ZJS
207"$systemctl" --root="$root" enable '/link1.path'
208islink "$root/etc/systemd/system/link1.path" "/link1.path"
9aa3d6b4 209islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
50c5f5a3 210
25cbc42d 211: '-------enable already linked different path--------------------'
d6c51c48 212( ! "$systemctl" --root="$root" enable '/subdir/link1.path' )
20d68b3a 213islink "$root/etc/systemd/system/link1.path" "/link1.path"
9aa3d6b4 214islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
50c5f5a3 215
25cbc42d 216: '-------enable bad suffix---------------------------------------'
50c5f5a3 217cp "$root/link1.path" "$root/subdir/link1.suffix"
d6c51c48 218( ! "$systemctl" --root="$root" enable '/subdir/link1.suffix' )
50c5f5a3
ZJS
219test ! -e "$root/etc/systemd/system/link1.suffix"
220test ! -e "$root/etc/systemd/system/paths.target.wants/link1.suffix"
221
25cbc42d 222: '-------disable by unit name------------------------------------'
50c5f5a3
ZJS
223"$systemctl" --root="$root" disable 'link1.path'
224test ! -e "$root/etc/systemd/system/link1.path"
225test ! -e "$root/etc/systemd/system/paths.target.wants/link1.path"
226
25cbc42d 227: '-------disable by path-----------------------------------------'
50c5f5a3
ZJS
228"$systemctl" --root="$root" enable '/link1.path'
229test -h "$root/etc/systemd/system/link1.path"
230test -h "$root/etc/systemd/system/paths.target.wants/link1.path"
231"$systemctl" --root="$root" disable '/link1.path'
232test ! -e "$root/etc/systemd/system/link1.path"
233test ! -e "$root/etc/systemd/system/paths.target.wants/link1.path"
234
235
25cbc42d 236: '-------link and enable-----------------------------------------'
50c5f5a3
ZJS
237"$systemctl" --root="$root" link '/link1.path'
238islink "$root/etc/systemd/system/link1.path" "/link1.path"
239test ! -h "$root/etc/systemd/system/paths.target.wants/link1.path"
240
241"$systemctl" --root="$root" enable 'link1.path'
242islink "$root/etc/systemd/system/link1.path" "/link1.path"
9aa3d6b4 243islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
50c5f5a3 244
29a7c59a
ZJS
245"$systemctl" --root="$root" reenable 'link1.path'
246islink "$root/etc/systemd/system/link1.path" "/link1.path"
9aa3d6b4 247islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
50c5f5a3 248
25cbc42d 249: '-------link instance and enable--------------------------------'
fe6e0cfa
FS
250cat >"$root/link-instance@.service" <<EOF
251[Service]
252ExecStart=true
253[Install]
254WantedBy=services.target
255EOF
256
257"$systemctl" --root="$root" link '/link-instance@.service'
258islink "$root/etc/systemd/system/link-instance@.service" "/link-instance@.service"
259
260"$systemctl" --root="$root" enable 'link-instance@first.service'
261islink "$root/etc/systemd/system/link-instance@first.service" "/link-instance@.service"
262islink "$root/etc/systemd/system/services.target.wants/link-instance@first.service" "/link-instance@.service"
263
264SYSTEMD_LOG_LEVEL=debug "$systemctl" --root="$root" reenable 'link-instance@first.service'
265islink "$root/etc/systemd/system/link-instance@first.service" "/link-instance@.service"
266islink "$root/etc/systemd/system/services.target.wants/link-instance@first.service" "/link-instance@.service"
267
268"$systemctl" --root="$root" disable 'link-instance@first.service'
269test ! -h "$root/etc/systemd/system/link-instance@first.service"
270test ! -h "$root/etc/systemd/system/services.target.wants/link-instance@first.service"
271
25cbc42d 272: '-------manual link---------------------------------------------'
50c5f5a3
ZJS
273cat >"$root/link3.suffix" <<EOF
274[Install]
275WantedBy=services.target
276EOF
277
48eadb9d 278# We wouldn't create such a link ourselves, but it should accept it when present.
50c5f5a3
ZJS
279ln -s "/link3.suffix" "$root/etc/systemd/system/link3.service"
280
48eadb9d
ZJS
281SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
282islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
9aa3d6b4 283islink "$root/etc/systemd/system/services.target.wants/link3.service" "/link3.suffix"
48eadb9d
ZJS
284
285SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" disable 'link3.service'
286test ! -h "$root/etc/systemd/system/link3.service"
287test ! -h "$root/etc/systemd/system/services.target.wants/link3.service"
50c5f5a3 288
25cbc42d 289: '-------enable on masked----------------------------------------'
50c5f5a3 290ln -s "/dev/null" "$root/etc/systemd/system/masked.service"
d6c51c48
ZJS
291( ! "$systemctl" --root="$root" enable 'masked.service' )
292( ! "$systemctl" --root="$root" enable '/etc/systemd/system/masked.service' )
50c5f5a3 293
25cbc42d 294: '-------enable on masked alias----------------------------------'
50c5f5a3
ZJS
295test -h "$root/etc/systemd/system/masked.service"
296ln -s "masked.service" "$root/etc/systemd/system/masked-alias.service"
d6c51c48
ZJS
297( ! "$systemctl" --root="$root" enable 'masked-alias.service' )
298( ! "$systemctl" --root="$root" enable '/etc/systemd/system/masked-alias.service' )
50c5f5a3 299
25cbc42d 300: '-------issue 22000: link in subdirectory-----------------------'
50c5f5a3
ZJS
301mkdir -p "$root/etc/systemd/system/myown.d"
302cat >"$root/etc/systemd/system/link5-also.service" <<EOF
303[Install]
304WantedBy=services.target
305Also=link5.service
306EOF
307cat >"$root/etc/systemd/system/myown.d/link5.service" <<EOF
308[Install]
309WantedBy=services.target
310Also=link5-also.service
311EOF
312
d6c51c48 313( ! "$systemctl" --root="$root" enable 'link5.service' )
50c5f5a3
ZJS
314test ! -h "$root/etc/systemd/system/services.target.wants/link5.service"
315test ! -h "$root/etc/systemd/system/services.target.wants/link5-also.service"
316
317"$systemctl" --root="$root" enable 'link5-also.service'
318test ! -h "$root/etc/systemd/system/services.target.wants/link5.service"
9aa3d6b4 319islink "$root/etc/systemd/system/services.target.wants/link5-also.service" "/etc/systemd/system/link5-also.service"
50c5f5a3 320
25cbc42d 321: '-------template enablement-------------------------------------'
50c5f5a3
ZJS
322cat >"$root/etc/systemd/system/templ1@.service" <<EOF
323[Install]
324WantedBy=services.target
325EOF
326
327# No instance here — this can't succeed.
d6c51c48 328( ! "$systemctl" --root="$root" enable 'templ1@.service' )
50c5f5a3
ZJS
329test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
330
331"$systemctl" --root="$root" enable 'templ1@one.service'
332test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
9aa3d6b4 333islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
50c5f5a3
ZJS
334
335"$systemctl" --root="$root" enable 'templ1@two.service'
336test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
9aa3d6b4
ZJS
337islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
338islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
fe6e0cfa
FS
339
340"$systemctl" --root="$root" reenable 'templ1@two.service'
341test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
342islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
343islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
50c5f5a3
ZJS
344
345"$systemctl" --root="$root" disable 'templ1@one.service'
346test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
347test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
9aa3d6b4 348islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
50c5f5a3
ZJS
349
350"$systemctl" --root="$root" disable 'templ1@two.service'
351test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
352test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
353test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
354
25cbc42d 355: '-------template enablement w/ default instance-----------------'
0c003e83
ZJS
356cat >"$root/etc/systemd/system/templ1@.service" <<EOF
357[Install]
358# check enablement with
359WantedBy=services.target services.target
360RequiredBy=other@templ1.target other@%p.target
50c5f5a3
ZJS
361DefaultInstance=333
362EOF
50c5f5a3
ZJS
363
364"$systemctl" --root="$root" enable 'templ1@.service'
365test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
9aa3d6b4
ZJS
366islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
367islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
50c5f5a3
ZJS
368
369"$systemctl" --root="$root" enable 'templ1@one.service'
370test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
9aa3d6b4
ZJS
371islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
372islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
373islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
374islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service" "/etc/systemd/system/templ1@.service"
50c5f5a3
ZJS
375
376"$systemctl" --root="$root" enable 'templ1@two.service'
377test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
9aa3d6b4
ZJS
378islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
379islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
380islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
381islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service" "/etc/systemd/system/templ1@.service"
382islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
383islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@two.service" "/etc/systemd/system/templ1@.service"
50c5f5a3
ZJS
384
385"$systemctl" --root="$root" disable 'templ1@one.service'
386test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
9aa3d6b4
ZJS
387islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
388islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
50c5f5a3 389test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
0c003e83 390test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service"
9aa3d6b4
ZJS
391islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
392islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@two.service" "/etc/systemd/system/templ1@.service"
50c5f5a3 393
0c003e83 394# disable remaining links here
50c5f5a3
ZJS
395"$systemctl" --root="$root" disable 'templ1@.service'
396test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
397test ! -h "$root/etc/systemd/system/services.target.wants/templ1@333.service"
0c003e83 398test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service"
50c5f5a3 399test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
0c003e83 400test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service"
50c5f5a3 401test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
0c003e83 402test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@two.service"
50c5f5a3 403
25cbc42d 404: '-------removal of relative enablement symlinks-----------------'
9f61c9f7
ZJS
405test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
406ln -s '../templ1@one.service' "$root/etc/systemd/system/services.target.wants/templ1@one.service"
407ln -s 'templ1@two.service' "$root/etc/systemd/system/services.target.wants/templ1@two.service"
408ln -s '../templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@three.service"
409ln -s 'templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@four.service"
410ln -s '/usr/lib/systemd/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@five.service"
411ln -s '/etc/systemd/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@six.service"
412ln -s '/run/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@seven.service"
413
414# this should remove all links
415"$systemctl" --root="$root" disable 'templ1@.service'
416test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
417test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
418test ! -h "$root/etc/systemd/system/services.target.wants/templ1@three.service"
419test ! -h "$root/etc/systemd/system/services.target.wants/templ1@four.service"
420test ! -h "$root/etc/systemd/system/services.target.wants/templ1@five.service"
421test ! -h "$root/etc/systemd/system/services.target.wants/templ1@six.service"
422test ! -h "$root/etc/systemd/system/services.target.wants/templ1@seven.service"
423
25cbc42d 424: '-------template enablement for another template----------------'
17a2679e
ZJS
425cat >"$root/etc/systemd/system/templ2@.service" <<EOF
426[Install]
427RequiredBy=another-template@.target
428EOF
429
430"$systemctl" --root="$root" enable 'templ2@.service'
9aa3d6b4 431islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
17a2679e
ZJS
432
433"$systemctl" --root="$root" enable 'templ2@two.service'
9aa3d6b4
ZJS
434islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
435islink "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service" "/etc/systemd/system/templ2@.service"
17a2679e
ZJS
436
437"$systemctl" --root="$root" disable 'templ2@other.service'
9aa3d6b4
ZJS
438islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
439islink "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service" "/etc/systemd/system/templ2@.service"
17a2679e
ZJS
440
441"$systemctl" --root="$root" disable 'templ2@two.service'
9aa3d6b4 442islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
17a2679e
ZJS
443test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service"
444
445"$systemctl" --root="$root" disable 'templ2@.service'
446test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@.service"
447test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service"
448
25cbc42d 449: '-------aliases w/ and w/o instance-----------------------------'
50c5f5a3
ZJS
450test ! -e "$root/etc/systemd/system/link4.service"
451cat >"$root/etc/systemd/system/link4.service" <<EOF
452[Install]
f663e646 453Alias=link4.service
50c5f5a3
ZJS
454Alias=link4@.service
455Alias=link4@inst.service
456Alias=link4alias.service
457Alias=link4alias2.service
458EOF
459
d6c51c48 460( ! "$systemctl" --root="$root" enable 'link4.service' )
50c5f5a3
ZJS
461test ! -h "$root/etc/systemd/system/link4.service" # this is our file
462test ! -h "$root/etc/systemd/system/link4@.service"
463test ! -h "$root/etc/systemd/system/link4@inst.service"
9aa3d6b4
ZJS
464islink "$root/etc/systemd/system/link4alias.service" "/etc/systemd/system/link4.service"
465islink "$root/etc/systemd/system/link4alias2.service" "/etc/systemd/system/link4.service"
50c5f5a3
ZJS
466
467"$systemctl" --root="$root" disable 'link4.service'
468test ! -h "$root/etc/systemd/system/link4.service"
469test ! -h "$root/etc/systemd/system/link4@.service"
470test ! -h "$root/etc/systemd/system/link4@inst.service"
471test ! -h "$root/etc/systemd/system/link4alias.service"
472test ! -h "$root/etc/systemd/system/link4alias2.service"
473
25cbc42d 474: '-------systemctl enable on path to unit file-------------------'
0d11db59
ZJS
475cat >"$root/etc/systemd/system/link4.service" <<EOF
476[Install]
477Alias=link4alias.service
478Alias=link4alias2.service
479EOF
480
50c5f5a3
ZJS
481# Apparently this works. I'm not sure what to think.
482"$systemctl" --root="$root" enable '/etc/systemd/system/link4.service'
483test ! -h "$root/etc/systemd/system/link4.service" # this is our file
9aa3d6b4
ZJS
484islink "$root/etc/systemd/system/link4alias.service" "/etc/systemd/system/link4.service"
485islink "$root/etc/systemd/system/link4alias2.service" "/etc/systemd/system/link4.service"
50c5f5a3
ZJS
486
487"$systemctl" --root="$root" disable '/etc/systemd/system/link4.service'
488test ! -h "$root/etc/systemd/system/link4.service"
50c5f5a3
ZJS
489test ! -h "$root/etc/systemd/system/link4alias.service"
490test ! -h "$root/etc/systemd/system/link4alias2.service"
491
25cbc42d 492: '-------issue 661: enable on unit file--------------------------'
50c5f5a3
ZJS
493test ! -e "$root/etc/systemd/system/link5.service"
494cat >"$root/etc/systemd/system/link5.service" <<EOF
495[Install]
f663e646 496Alias=link5.service
50c5f5a3
ZJS
497Alias=link5alias.service
498Alias=link5alias2.service
499EOF
500
501"$systemctl" --root="$root" enable 'link5.service'
502test ! -h "$root/etc/systemd/system/link5.service" # this is our file
9aa3d6b4
ZJS
503islink "$root/etc/systemd/system/link5alias.service" "/etc/systemd/system/link5.service"
504islink "$root/etc/systemd/system/link5alias2.service" "/etc/systemd/system/link5.service"
50c5f5a3
ZJS
505
506"$systemctl" --root="$root" disable 'link5.service'
50c5f5a3
ZJS
507test ! -h "$root/etc/systemd/system/link5alias.service"
508test ! -h "$root/etc/systemd/system/link5alias2.service"
509
25cbc42d 510: '-------issue 661: link and enable on unit file-----------------'
85516075
ZJS
511test ! -e "$root/etc/systemd/system/link5copy.service"
512cat >"$root/link5copy.service" <<EOF
513[Install]
514Alias=link5copy.service
515Alias=link5alias.service
516Alias=link5alias2.service
517EOF
518
519test ! -e "$root/etc/systemd/system/link5copy.service"
520
521"$systemctl" --root="$root" link '/link5copy.service'
522islink "$root/etc/systemd/system/link5copy.service" '/link5copy.service'
523test ! -h "$root/etc/systemd/system/link5alias.service"
524test ! -h "$root/etc/systemd/system/link5alias2.service"
525
9aa3d6b4
ZJS
526# FIXME: we must create link5alias2 and link5alias as relative links to link5.service
527# When they are independent links to /link5.service, systemd doesn't know that
528# they are aliases, because we do not follow symlinks outside of the search paths.
529
85516075
ZJS
530"$systemctl" --root="$root" disable 'link5copy.service'
531test ! -h "$root/etc/systemd/system/link5copy.service"
532test ! -h "$root/etc/systemd/system/link5alias.service"
533test ! -h "$root/etc/systemd/system/link5alias2.service"
534
535"$systemctl" --root="$root" enable '/link5copy.service'
536islink "$root/etc/systemd/system/link5copy.service" '/link5copy.service'
6fec0fed
NR
537islink "$root/etc/systemd/system/link5alias.service" '/etc/systemd/system/link5copy.service'
538islink "$root/etc/systemd/system/link5alias2.service" '/etc/systemd/system/link5copy.service'
85516075
ZJS
539
540"$systemctl" --root="$root" disable 'link5copy.service'
541test ! -h "$root/etc/systemd/system/link5copy.service"
542test ! -h "$root/etc/systemd/system/link5alias.service"
543test ! -h "$root/etc/systemd/system/link5alias2.service"
544
25cbc42d 545: '-------issue 19437: plain templates in .wants/ or .requires/---'
50c5f5a3
ZJS
546test ! -e "$root/etc/systemd/system/link5@.path"
547cat >"$root/etc/systemd/system/link5@.path" <<EOF
548[Install]
549WantedBy=target5@.target
550RequiredBy=target5@.target
551WantedBy=target5@inst.target
552RequiredBy=target5@inst.target
553EOF
554
555"$systemctl" --root="$root" enable 'link5@.path'
556test ! -h "$root/etc/systemd/system/link5@.path" # this is our file
9aa3d6b4
ZJS
557islink "$root/etc/systemd/system/target5@.target.wants/link5@.path" "/etc/systemd/system/link5@.path"
558islink "$root/etc/systemd/system/target5@.target.requires/link5@.path" "/etc/systemd/system/link5@.path"
559islink "$root/etc/systemd/system/target5@inst.target.wants/link5@.path" "/etc/systemd/system/link5@.path"
560islink "$root/etc/systemd/system/target5@inst.target.requires/link5@.path" "/etc/systemd/system/link5@.path"
50c5f5a3
ZJS
561
562"$systemctl" --root="$root" disable 'link5@.path'
563test ! -h "$root/etc/systemd/system/link5@.path" # this is our file
564test ! -h "$root/etc/systemd/system/target5@.target.wants/link5@.path"
565test ! -h "$root/etc/systemd/system/target5@.target.requires/link5@.path"
566test ! -h "$root/etc/systemd/system/target5@inst.target.wants/link5@.path"
567test ! -h "$root/etc/systemd/system/target5@inst.target.requires/link5@.path"
568
25cbc42d 569: '-------removal of symlinks not listed in [Install]-------------'
50c5f5a3
ZJS
570# c.f. 66a19d85a533b15ed32f4066ec880b5a8c06babd
571test ! -e "$root/etc/systemd/system/multilink.mount"
572cat >"$root/etc/systemd/system/multilink.mount" <<EOF
573[Install]
574WantedBy=multilink.target
575EOF
576
577mkdir -p "$root/etc/systemd/system/default.target.wants"
578ln -s ../multilink.mount "$root/etc/systemd/system/default.target.wants/"
579ln -s ../multilink.mount "$root/etc/systemd/system/multilink-alias.mount"
580ln -s ../multilink.mount "$root/etc/systemd/system/multilink-badalias.service"
581
582"$systemctl" --root="$root" disable 'multilink.mount'
583test -e "$root/etc/systemd/system/multilink.mount" # this is our file
584test ! -h "$root/etc/systemd/system/default.target.wants/"
585test ! -h "$root/etc/systemd/system/multilink-alias.mount"
586test ! -h "$root/etc/systemd/system/multilink-badalias.service"
587
25cbc42d 588: '-------merge 20017: specifiers in the unit file----------------'
50c5f5a3
ZJS
589test ! -e "$root/etc/systemd/system/some-some-link6@.socket"
590# c.f. de61a04b188f81a85cdb5c64ddb4987dcd9d30d3
591
592check_alias() {
84fdced6 593 : "------------------ %$1 -------------------------------------"
50c5f5a3
ZJS
594 cat >"$root/etc/systemd/system/some-some-link6@.socket" <<EOF
595[Install]
596Alias=target@$1:%$1.socket
597EOF
598 SYSTEMD_LOG_LEVEL=debug "$systemctl" --root="$root" enable 'some-some-link6@.socket' || return 1
9aa3d6b4 599 islink "$root/etc/systemd/system/target@$1:$2.socket" "/etc/systemd/system/some-some-link6@.socket" || return 2
50c5f5a3
ZJS
600}
601
5c29de29
ZJS
602# TODO: our architecture names are different than what uname -m returns.
603# Add something like 'systemd-detect-virt --print-architecture' and use it here.
604check_alias a "$(uname -m | tr '_' '-')" || :
50c5f5a3 605
6ec4c852
ZJS
606test ! -e "$root/etc/os-release"
607test ! -e "$root/usr/lib/os-release"
608
d6c51c48
ZJS
609( ! check_alias A '' )
610( ! check_alias B '' )
611( ! check_alias M '' )
612( ! check_alias o '' )
613( ! check_alias w '' )
614( ! check_alias W '' )
6ec4c852
ZJS
615
616cat >"$root/etc/os-release" <<EOF
617# empty
618EOF
50c5f5a3 619
6ec4c852
ZJS
620check_alias A ''
621check_alias B ''
622check_alias M ''
623check_alias o ''
624check_alias w ''
625check_alias W ''
626
627cat >"$root/etc/os-release" <<EOF
628ID='the-id'
629VERSION_ID=39a
630BUILD_ID=build-id
631VARIANT_ID=wrong
632VARIANT_ID=right
633IMAGE_ID="foobar"
634IMAGE_VERSION='1-2-3'
635EOF
50c5f5a3 636
6ec4c852
ZJS
637check_alias A '1-2-3'
638check_alias B 'build-id'
639check_alias M 'foobar'
640check_alias o 'the-id'
641check_alias w '39a'
642check_alias W 'right'
643
2a2d002f 644check_alias b "$("$systemd_id128" boot-id)"
50c5f5a3 645
19b9d5d0 646# Specifiers not available for [Install]
d6c51c48
ZJS
647( ! check_alias C '' )
648( ! check_alias E '' )
649( ! check_alias f '' )
650( ! check_alias h '' )
651( ! check_alias I '' )
652( ! check_alias J '' )
653( ! check_alias L '' )
654( ! check_alias P '' )
655( ! check_alias s '' )
656( ! check_alias S '' )
657( ! check_alias t '' )
658( ! check_alias T '' )
659( ! check_alias V '' )
50c5f5a3 660
172e9cc3
ZJS
661check_alias g root
662check_alias G 0
663check_alias u root
664check_alias U 0
50c5f5a3 665
50c5f5a3
ZJS
666check_alias i ""
667
50c5f5a3
ZJS
668check_alias j 'link6'
669
50c5f5a3
ZJS
670check_alias l "$(uname -n | sed 's/\..*//')"
671
6ec4c852 672test ! -e "$root/etc/machine-id"
d6c51c48 673( ! check_alias m '' )
50c5f5a3 674
2a2d002f 675"$systemd_id128" new >"$root/etc/machine-id"
6ec4c852 676check_alias m "$(cat "$root/etc/machine-id")"
50c5f5a3
ZJS
677
678check_alias n 'some-some-link6@.socket'
679check_alias N 'some-some-link6@'
680
50c5f5a3
ZJS
681check_alias p 'some-some-link6'
682
c3a053c2
ZJS
683uname -r | grep -q '[^a-zA-Z0-9_.\\-]' || \
684 check_alias v "$(uname -r)"
50c5f5a3 685
d6c51c48
ZJS
686# % is not legal in unit name
687( ! check_alias % '%' )
50c5f5a3 688
d6c51c48
ZJS
689# %z is not defined
690( ! check_alias z 'z' )
50c5f5a3 691
25cbc42d 692: '-------specifiers in WantedBy----------------------------------'
17a2679e
ZJS
693# We don't need to repeat all the tests. Let's do a basic check that specifier
694# expansion is performed.
695
696cat >"$root/etc/systemd/system/some-some-link7.socket" <<EOF
697[Install]
698WantedBy=target@%p.target
699WantedBy=another-target@.target
700RequiredBy=target2@%p.target
701RequiredBy=another-target2@.target
702EOF
703
704"$systemctl" --root="$root" enable 'some-some-link7.socket'
9aa3d6b4
ZJS
705islink "$root/etc/systemd/system/target@some-some-link7.target.wants/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
706islink "$root/etc/systemd/system/another-target@.target.wants/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
707islink "$root/etc/systemd/system/target2@some-some-link7.target.requires/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
708islink "$root/etc/systemd/system/another-target2@.target.requires/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
17a2679e
ZJS
709
710"$systemctl" --root="$root" disable 'some-some-link7.socket'
711test ! -h "$root/etc/systemd/system/target@some-some-link7.target.wants/some-some-link7.socket"
712test ! -h "$root/etc/systemd/system/another-target@.target.wants/some-some-link7.socket"
713test ! -h "$root/etc/systemd/system/target2@some-some-link7.target.requires/some-some-link7.socket"
714test ! -h "$root/etc/systemd/system/another-target2@.target.requires/some-some-link7.socket"
715
50c5f5a3 716# TODO: repeat the tests above for presets
df78419d 717
25cbc42d 718: '-------SYSTEMD_OS_RELEASE relative to root---------------------'
df78419d
ZJS
719# check that os-release overwriting works as expected with root
720test -e "$root/etc/os-release"
721
722cat >"$root/etc/os-release2" <<EOF
723ID='the-id2'
724EOF
725
5cf69e70 726SYSTEMD_OS_RELEASE="/etc/os-release2" check_alias o 'the-id2'