2 # SPDX-License-Identifier: LGPL-2.1-or-later
6 # shellcheck source=test/units/test-control.sh
7 .
"$(dirname "$0")"/test-control.sh
8 # shellcheck source=test/units/util.sh
9 .
"$(dirname "$0")"/util.sh
11 maybe_mount_usr_overlay
12 trap 'maybe_umount_usr_overlay' EXIT
15 local unit_name
="${1:?}"
18 systemctl stop
"$unit_name" 2>/dev
/null ||
:
19 rm -f /{etc
,run
,usr
/lib
}/systemd
/system
/"$unit_name"
20 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$unit_name".d
21 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$unit_name".
{wants
,requires
}
22 if [[ $unit_name == *@
* ]]; then
23 base
="${unit_name%@*}"
24 suffix
="${unit_name##*.}"
25 systemctl stop
"$base@"*.
"$suffix" 2>/dev
/null ||
:
26 rm -f /{etc
,run
,usr
/lib
}/systemd
/system
/"$base@"*.
"$suffix"
27 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$base@"*.
"$suffix".d
28 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$base@"*.
"$suffix".
{wants
,requires
}
36 systemctl daemon-reload
40 local service_name
="${1:?}"
41 clear_units
"${service_name}".service
43 cat >/etc
/systemd
/system
/"$service_name".service
<<EOF
45 Description=$service_name unit
48 ExecStart=sleep 100000
50 mkdir
-p /{etc
,run
,usr
/lib
}/systemd
/system
/"$service_name".service.
{d
,wants
,requires
}
60 x
="$(systemctl show --value -p "${2:?}" "${1:?}")"
71 testcase_basic_dropins
() {
72 echo "Testing basic dropins..."
74 echo "*** test a wants b wants c"
75 create_services test15-a test15-b test15-c
76 ln -s ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.wants
/
77 ln -s ..
/test15-c.service
/etc
/systemd
/system
/test15-b.service.wants
/
78 check_ok test15-a Wants test15-b.service
79 check_ok test15-b Wants test15-c.service
81 echo "*** test a wants,requires b"
82 create_services test15-a test15-b test15-c
83 ln -s ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.wants
/
84 ln -s ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
85 check_ok test15-a Wants test15-b.service
86 check_ok test15-a Requires test15-b.service
88 echo "*** test a wants nonexistent"
89 create_service test15-a
90 ln -s ..
/nonexistent.service
/etc
/systemd
/system
/test15-a.service.wants
/
91 check_ok test15-a Wants nonexistent.service
92 systemctl start test15-a
93 systemctl stop test15-a
95 echo "*** test a requires nonexistent"
96 ln -sf ..
/nonexistent.service
/etc
/systemd
/system
/test15-a.service.requires
/
97 systemctl daemon-reload
98 check_ok test15-a Requires nonexistent.service
100 # 'b' is already loaded when 'c' pulls it in via a dropin.
101 echo "*** test a,c require b"
102 create_services test15-a test15-b test15-c
103 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
104 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-c.service.requires
/
105 systemctl start test15-a
106 check_ok test15-c Requires test15-b.service
107 systemctl stop test15-a test15-b
109 # 'b' is already loaded when 'c' pulls it in via an alias dropin.
110 echo "*** test a wants alias"
111 create_services test15-a test15-b test15-c
112 ln -sf test15-c.service
/etc
/systemd
/system
/test15-c1.service
113 ln -sf ..
/test15-c.service
/etc
/systemd
/system
/test15-a.service.wants
/
114 ln -sf ..
/test15-c1.service
/etc
/systemd
/system
/test15-b.service.wants
/
115 systemctl start test15-a
116 check_ok test15-a Wants test15-c.service
117 check_ok test15-b Wants test15-c.service
118 systemctl stop test15-a test15-c
120 echo "*** test service.d/ top level drop-in"
121 create_services test15-a test15-b
122 check_ko test15-a ExecCondition
"/bin/echo a"
123 check_ko test15-b ExecCondition
"/bin/echo b"
124 mkdir
-p /run
/systemd
/system
/service.d
125 cat >/run
/systemd
/system
/service.d
/override.conf
<<EOF
127 ExecCondition=/bin/echo %n
129 systemctl daemon-reload
130 check_ok test15-a ExecCondition
"/bin/echo test15-a"
131 check_ok test15-b ExecCondition
"/bin/echo test15-b"
132 rm -rf /run
/systemd
/system
/service.d
134 clear_units test15-
{a
,b
,c
,c1
}.service
137 testcase_linked_units
() {
138 echo "Testing linked units..."
139 echo "*** test linked unit (same basename)"
141 create_service test15-a
142 mv /etc
/systemd
/system
/test15-a.service
/
143 ln -s /test15-a.service
/etc
/systemd
/system
/
144 ln -s test15-a.service
/etc
/systemd
/system
/test15-b.service
146 check_ok test15-a Names test15-a.service
147 check_ok test15-a Names test15-b.service
149 echo "*** test linked unit (cross basename)"
151 mv /test15-a.service
/test15-a@.scope
152 ln -fs /test15-a@.scope
/etc
/systemd
/system
/test15-a.service
153 systemctl daemon-reload
155 check_ok test15-a Names test15-a.service
156 check_ok test15-a Names test15-b.service
157 check_ko test15-a Names test15-a@
# test15-a@.scope is the symlink target.
158 # Make sure it is completely ignored.
161 clear_units test15-
{a
,b
}.service
164 testcase_template_alias
() {
165 echo "Testing instance alias..."
168 create_service test15-a@
169 ln -s test15-a@inst.service
/etc
/systemd
/system
/test15-b@inst.service
# alias
171 check_ok test15-a@inst Names test15-a@inst.service
172 check_ok test15-a@inst Names test15-b@inst.service
174 check_ok test15-a@other Names test15-a@other.service
175 check_ko test15-a@other Names test15-b@other.service
179 systemctl daemon-reload
181 check_ok test15-b@inst Names test15-a@inst.service
182 check_ok test15-b@inst Names test15-b@inst.service
184 check_ko test15-b@other Names test15-a@other.service
185 check_ok test15-b@other Names test15-b@other.service
187 clear_units test15-
{a
,b
}@.service
190 testcase_hierarchical_service_dropins
() {
191 echo "Testing hierarchical service dropins..."
192 echo "*** test service.d/ top level drop-in"
193 create_services a-b-c
194 check_ko a-b-c ExecCondition
"echo service.d"
195 check_ko a-b-c ExecCondition
"echo a-.service.d"
196 check_ko a-b-c ExecCondition
"echo a-b-.service.d"
197 check_ko a-b-c ExecCondition
"echo a-b-c.service.d"
199 for dropin
in service.d a-.service.d a-b-.service.d a-b-c.service.d
; do
200 mkdir
-p "/run/systemd/system/$dropin"
201 cat >"/run/systemd/system/$dropin/override.conf" <<EOF
203 ExecCondition=echo $dropin
205 systemctl daemon-reload
206 check_ok a-b-c ExecCondition
"echo $dropin"
208 # Check that we can start a transient service in presence of the drop-ins
209 systemd-run
-u a-b-c2.service
-p Description
='sleepy' sleep infinity
211 # The transient setting replaces the default
212 check_ok a-b-c2.service Description
"sleepy"
214 # The override takes precedence for ExecCondition
215 # (except the last iteration when it only applies to the other service)
216 if [ "$dropin" != "a-b-c.service.d" ]; then
217 check_ok a-b-c2.service ExecCondition
"echo $dropin"
220 # Check that things are the same after a reload
221 systemctl daemon-reload
222 check_ok a-b-c2.service Description
"sleepy"
223 if [ "$dropin" != "a-b-c.service.d" ]; then
224 check_ok a-b-c2.service ExecCondition
"echo $dropin"
227 systemctl stop a-b-c2.service
229 for dropin
in service.d a-.service.d a-b-.service.d a-b-c.service.d
; do
230 rm -rf "/run/systemd/system/$dropin"
233 clear_units a-b-c.service
236 testcase_hierarchical_slice_dropins
() {
237 echo "Testing hierarchical slice dropins..."
238 echo "*** test slice.d/ top level drop-in"
239 # Slice units don't even need a fragment, so we test the defaults here
240 check_ok a-b-c.slice Description
"Slice /a/b/c"
241 check_ok a-b-c.slice MemoryMax
"infinity"
244 for dropin
in slice.d a-.slice.d a-b-.slice.d a-b-c.slice.d
; do
245 mkdir
-p "/run/systemd/system/$dropin"
246 cat >"/run/systemd/system/$dropin/override.conf" <<EOF
250 systemctl daemon-reload
251 check_ok a-b-c.slice MemoryMax
"1000000000"
254 org.freedesktop.systemd1 \
255 /org
/freedesktop
/systemd1 \
256 org.freedesktop.systemd1.Manager \
257 StartTransientUnit
'ssa(sv)a(sa(sv))' \
258 'a-b-c.slice' 'replace' \
260 'Description' s
'slice too' \
261 'MemoryMax' t
1000000002 \
264 # The override takes precedence for MemoryMax
265 check_ok a-b-c.slice MemoryMax
"1000000000"
266 # The transient setting replaces the default
267 check_ok a-b-c.slice Description
"slice too"
269 # Check that things are the same after a reload
270 systemctl daemon-reload
271 check_ok a-b-c.slice MemoryMax
"1000000000"
272 check_ok a-b-c.slice Description
"slice too"
275 org.freedesktop.systemd1 \
276 /org
/freedesktop
/systemd1 \
277 org.freedesktop.systemd1.Manager \
279 'a-b-c.slice' 'replace'
281 rm -f "/run/systemd/system/$dropin/override.conf"
284 # Test unit with a fragment
285 cat >/run
/systemd
/system
/a-b-c.slice
<<EOF
289 systemctl daemon-reload
290 check_ok a-b-c.slice MemoryMax
"1000000001"
292 clear_units a-b-c.slice
295 testcase_transient_service_dropins
() {
296 echo "Testing dropins for a transient service..."
297 echo "*** test transient service drop-ins"
299 mkdir
-p /etc
/systemd
/system
/service.d
300 mkdir
-p /etc
/systemd
/system
/a-.service.d
301 mkdir
-p /etc
/systemd
/system
/a-b-.service.d
302 mkdir
-p /etc
/systemd
/system
/a-b-c.service.d
304 echo -e '[Service]\nStandardInputText=aaa' >/etc
/systemd
/system
/service.d
/drop1.conf
305 echo -e '[Service]\nStandardInputText=bbb' >/etc
/systemd
/system
/a-.service.d
/drop2.conf
306 echo -e '[Service]\nStandardInputText=ccc' >/etc
/systemd
/system
/a-b-.service.d
/drop3.conf
307 echo -e '[Service]\nStandardInputText=ddd' >/etc
/systemd
/system
/a-b-c.service.d
/drop4.conf
309 # There's no fragment yet, so this fails
310 systemctl
cat a-b-c.service
&& exit 1
313 systemd-run
-u a-b-c.service
-p StandardInputData
=eHh4Cg
== sleep infinity
315 data
=$
(systemctl show
-P StandardInputData a-b-c.service
)
316 # xxx\naaa\n\bbb\nccc\nddd\n → eHh4…
317 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
319 # Do a reload and check again
320 systemctl daemon-reload
321 data
=$
(systemctl show
-P StandardInputData a-b-c.service
)
322 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
324 clear_units a-b-c.service
325 rm /etc
/systemd
/system
/service.d
/drop1.conf \
326 /etc
/systemd
/system
/a-.service.d
/drop2.conf \
327 /etc
/systemd
/system
/a-b-.service.d
/drop3.conf
330 testcase_transient_slice_dropins
() {
331 echo "Testing dropins for a transient slice..."
332 echo "*** test transient slice drop-ins"
334 # FIXME: implement reloading of individual units.
336 # The settings here are loaded twice. For most settings it doesn't matter,
337 # but Documentation is not deduplicated, so we current get repeated entried
340 mkdir
-p /etc
/systemd
/system
/slice.d
341 mkdir
-p /etc
/systemd
/system
/a-.slice.d
342 mkdir
-p /etc
/systemd
/system
/a-b-.slice.d
343 mkdir
-p /etc
/systemd
/system
/a-b-c.slice.d
345 echo -e '[Unit]\nDocumentation=man:drop1' >/etc
/systemd
/system
/slice.d
/drop1.conf
346 echo -e '[Unit]\nDocumentation=man:drop2' >/etc
/systemd
/system
/a-.slice.d
/drop2.conf
347 echo -e '[Unit]\nDocumentation=man:drop3' >/etc
/systemd
/system
/a-b-.slice.d
/drop3.conf
348 echo -e '[Unit]\nDocumentation=man:drop4' >/etc
/systemd
/system
/a-b-c.slice.d
/drop4.conf
350 # Invoke daemon-reload to make sure that the call below doesn't fail
351 systemctl daemon-reload
353 # No fragment is required, so this works
354 systemctl
cat a-b-c.slice
357 org.freedesktop.systemd1 \
358 /org
/freedesktop
/systemd1 \
359 org.freedesktop.systemd1.Manager \
360 StartTransientUnit
'ssa(sv)a(sa(sv))' \
361 'a-b-c.slice' 'replace' \
363 'Documentation' as
1 'man:drop5' \
366 data
=$
(systemctl show
-P Documentation a-b-c.slice
)
367 test "$data" = "man:drop1 man:drop2 man:drop3 man:drop4 man:drop5 man:drop1 man:drop2 man:drop3 man:drop4"
369 # Do a reload and check again
370 systemctl daemon-reload
371 data
=$
(systemctl show
-P Documentation a-b-c.slice
)
372 test "$data" = "man:drop5 man:drop1 man:drop2 man:drop3 man:drop4"
374 clear_units a-b-c.slice
375 rm /etc
/systemd
/system
/slice.d
/drop1.conf \
376 /etc
/systemd
/system
/a-.slice.d
/drop2.conf \
377 /etc
/systemd
/system
/a-b-.slice.d
/drop3.conf
380 testcase_template_dropins
() {
381 echo "Testing template dropins..."
383 create_services foo bar@ yup@
385 # Declare some deps to check if the body was loaded
386 cat >>/etc
/systemd
/system
/bar@.service
<<EOF
388 After=bar-template-after.device
391 cat >>/etc
/systemd
/system
/yup@.service
<<EOF
393 After=yup-template-after.device
396 ln -s /etc
/systemd
/system
/bar@.service
/etc
/systemd
/system
/foo.service.wants
/bar@
1.service
397 check_ok foo Wants bar@
1.service
399 echo "*** test bar-alias@.service→bar@.service, but instance symlinks point to yup@.service ***"
400 ln -s bar@.service
/etc
/systemd
/system
/bar-alias@.service
401 ln -s bar@
1.service
/etc
/systemd
/system
/bar-alias@
1.service
402 ln -s yup@.service
/etc
/systemd
/system
/bar-alias@
2.service
403 ln -s yup@
3.service
/etc
/systemd
/system
/bar-alias@
3.service
405 # create some dropin deps
406 mkdir
-p /etc
/systemd
/system
/bar@
{,0,1,2,3}.service.requires
/
407 mkdir
-p /etc
/systemd
/system
/yup@
{,0,1,2,3}.service.requires
/
408 mkdir
-p /etc
/systemd
/system
/bar-alias@
{,0,1,2,3}.service.requires
/
410 ln -s ..
/bar-template-requires.device
/etc
/systemd
/system
/bar@.service.requires
/
411 ln -s ..
/bar-0-requires.device
/etc
/systemd
/system
/bar@
0.service.requires
/
412 ln -s ..
/bar-1-requires.device
/etc
/systemd
/system
/bar@
1.service.requires
/
413 ln -s ..
/bar-2-requires.device
/etc
/systemd
/system
/bar@
2.service.requires
/
414 ln -s ..
/bar-3-requires.device
/etc
/systemd
/system
/bar@
3.service.requires
/
416 ln -s ..
/yup-template-requires.device
/etc
/systemd
/system
/yup@.service.requires
/
417 ln -s ..
/yup-0-requires.device
/etc
/systemd
/system
/yup@
0.service.requires
/
418 ln -s ..
/yup-1-requires.device
/etc
/systemd
/system
/yup@
1.service.requires
/
419 ln -s ..
/yup-2-requires.device
/etc
/systemd
/system
/yup@
2.service.requires
/
420 ln -s ..
/yup-3-requires.device
/etc
/systemd
/system
/yup@
3.service.requires
/
422 ln -s ..
/bar-alias-template-requires.device
/etc
/systemd
/system
/bar-alias@.service.requires
/
423 ln -s ..
/bar-alias-0-requires.device
/etc
/systemd
/system
/bar-alias@
0.service.requires
/
424 ln -s ..
/bar-alias-1-requires.device
/etc
/systemd
/system
/bar-alias@
1.service.requires
/
425 ln -s ..
/bar-alias-2-requires.device
/etc
/systemd
/system
/bar-alias@
2.service.requires
/
426 ln -s ..
/bar-alias-3-requires.device
/etc
/systemd
/system
/bar-alias@
3.service.requires
/
428 systemctl daemon-reload
430 echo '*** bar@0 is aliased by bar-alias@0 ***'
431 systemctl show
-p Names
,Requires bar@
0
432 systemctl show
-p Names
,Requires bar-alias@
0
433 check_ok bar@
0 Names bar@
0
434 check_ok bar@
0 Names bar-alias@
0
436 check_ok bar@
0 After bar-template-after.device
438 check_ok bar@
0 Requires bar-0-requires.device
439 check_ok bar@
0 Requires bar-alias-0-requires.device
440 check_ok bar@
0 Requires bar-template-requires.device
441 check_ok bar@
0 Requires bar-alias-template-requires.device
442 check_ko bar@
0 Requires yup-template-requires.device
444 check_ok bar-alias@
0 After bar-template-after.device
446 check_ok bar-alias@
0 Requires bar-0-requires.device
447 check_ok bar-alias@
0 Requires bar-alias-0-requires.device
448 check_ok bar-alias@
0 Requires bar-template-requires.device
449 check_ok bar-alias@
0 Requires bar-alias-template-requires.device
450 check_ko bar-alias@
0 Requires yup-template-requires.device
451 check_ko bar-alias@
0 Requires yup-0-requires.device
453 echo '*** bar@1 is aliased by bar-alias@1 ***'
454 systemctl show
-p Names
,Requires bar@
1
455 systemctl show
-p Names
,Requires bar-alias@
1
456 check_ok bar@
1 Names bar@
1
457 check_ok bar@
1 Names bar-alias@
1
459 check_ok bar@
1 After bar-template-after.device
461 check_ok bar@
1 Requires bar-1-requires.device
462 check_ok bar@
1 Requires bar-alias-1-requires.device
463 check_ok bar@
1 Requires bar-template-requires.device
464 # See https://github.com/systemd/systemd/pull/13119#discussion_r308145418
465 check_ok bar@
1 Requires bar-alias-template-requires.device
466 check_ko bar@
1 Requires yup-template-requires.device
467 check_ko bar@
1 Requires yup-1-requires.device
469 check_ok bar-alias@
1 After bar-template-after.device
471 check_ok bar-alias@
1 Requires bar-1-requires.device
472 check_ok bar-alias@
1 Requires bar-alias-1-requires.device
473 check_ok bar-alias@
1 Requires bar-template-requires.device
474 check_ok bar-alias@
1 Requires bar-alias-template-requires.device
475 check_ko bar-alias@
1 Requires yup-template-requires.device
476 check_ko bar-alias@
1 Requires yup-1-requires.device
478 echo '*** bar-alias@2 aliases yup@2, bar@2 is independent ***'
479 systemctl show
-p Names
,Requires bar@
2
480 systemctl show
-p Names
,Requires bar-alias@
2
481 check_ok bar@
2 Names bar@
2
482 check_ko bar@
2 Names bar-alias@
2
484 check_ok bar@
2 After bar-template-after.device
486 check_ok bar@
2 Requires bar-2-requires.device
487 check_ko bar@
2 Requires bar-alias-2-requires.device
488 check_ok bar@
2 Requires bar-template-requires.device
489 check_ko bar@
2 Requires bar-alias-template-requires.device
490 check_ko bar@
2 Requires yup-template-requires.device
491 check_ko bar@
2 Requires yup-2-requires.device
493 check_ko bar-alias@
2 After bar-template-after.device
495 check_ko bar-alias@
2 Requires bar-2-requires.device
496 check_ok bar-alias@
2 Requires bar-alias-2-requires.device
497 check_ko bar-alias@
2 Requires bar-template-requires.device
498 check_ok bar-alias@
2 Requires bar-alias-template-requires.device
499 check_ok bar-alias@
2 Requires yup-template-requires.device
500 check_ok bar-alias@
2 Requires yup-2-requires.device
502 echo '*** bar-alias@3 aliases yup@3, bar@3 is independent ***'
503 systemctl show
-p Names
,Requires bar@
3
504 systemctl show
-p Names
,Requires bar-alias@
3
505 check_ok bar@
3 Names bar@
3
506 check_ko bar@
3 Names bar-alias@
3
508 check_ok bar@
3 After bar-template-after.device
510 check_ok bar@
3 Requires bar-3-requires.device
511 check_ko bar@
3 Requires bar-alias-3-requires.device
512 check_ok bar@
3 Requires bar-template-requires.device
513 check_ko bar@
3 Requires bar-alias-template-requires.device
514 check_ko bar@
3 Requires yup-template-requires.device
515 check_ko bar@
3 Requires yup-3-requires.device
517 check_ko bar-alias@
3 After bar-template-after.device
519 check_ko bar-alias@
3 Requires bar-3-requires.device
520 check_ok bar-alias@
3 Requires bar-alias-3-requires.device
521 check_ko bar-alias@
3 Requires bar-template-requires.device
522 check_ok bar-alias@
3 Requires bar-alias-template-requires.device
523 check_ok bar-alias@
3 Requires yup-template-requires.device
524 check_ok bar-alias@
3 Requires yup-3-requires.device
526 clear_units foo.service
{bar
,yup
,bar-alias
}@
{,1,2,3}.service
529 testcase_alias_dropins
() {
530 echo "Testing alias dropins..."
532 echo "*** test a wants b1 alias of b"
533 create_services test15-a test15-b
534 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
535 ln -sf ..
/test15-b1.service
/etc
/systemd
/system
/test15-a.service.wants
/
536 check_ok test15-a Wants test15-b.service
537 systemctl start test15-a
538 systemctl
--quiet is-active test15-b
539 systemctl stop test15-a test15-b
540 rm /etc
/systemd
/system
/test15-b1.service
541 clear_units test15-
{a
,b
}.service
543 # Check that dependencies don't vary.
545 create_services test15-a test15-x test15-y
546 mkdir
-p /etc
/systemd
/system
/test15-a1.service.wants
/
547 ln -sf test15-a.service
/etc
/systemd
/system
/test15-a1.service
548 ln -sf ..
/test15-x.service
/etc
/systemd
/system
/test15-a.service.wants
/
549 ln -sf ..
/test15-y.service
/etc
/systemd
/system
/test15-a1.service.wants
/
550 check_ok test15-a1 Wants test15-x.service
# see [1]
551 check_ok test15-a1 Wants test15-y.service
552 systemctl start test15-a
553 check_ok test15-a1 Wants test15-x.service
# see [2]
554 check_ok test15-a1 Wants test15-y.service
555 systemctl stop test15-a test15-x test15-y
556 rm /etc
/systemd
/system
/test15-a1.service
558 clear_units test15-
{a
,x
,y
}.service
561 testcase_masked_dropins
() {
562 echo "Testing masked dropins..."
564 create_services test15-a test15-b
566 # 'b' is masked for both deps
567 echo "*** test a wants,requires b is masked"
568 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
569 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b.service
570 check_ko test15-a Wants test15-b.service
571 check_ko test15-a Requires test15-b.service
573 # 'a' wants 'b' and 'b' is masked at a lower level
574 echo "*** test a wants b, mask override"
575 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
576 ln -sf /dev
/null
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
577 check_ok test15-a Wants test15-b.service
579 # 'a' wants 'b' and 'b' is masked at a higher level
580 echo "*** test a wants b, mask"
581 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
582 ln -sf ..
/test15-b.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
583 check_ko test15-a Wants test15-b.service
585 # 'a' is masked but has an override config file
586 echo "*** test a is masked but has an override"
587 create_services test15-a test15-b
588 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service
589 cat >/usr
/lib
/systemd
/system
/test15-a.service.d
/override.conf
<<EOF
591 After=test15-b.service
593 check_ok test15-a UnitFileState masked
595 # 'b1' is an alias for 'b': masking 'b' dep should not influence 'b1' dep
596 echo "*** test a wants b, b1, and one is masked"
597 create_services test15-a test15-b
598 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
599 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
600 ln -sf ..
/test15-b1.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b1.service
601 systemctl
cat test15-a
602 systemctl show
-p Wants
,Requires test15-a
603 systemctl
cat test15-b1
604 systemctl show
-p Wants
,Requires test15-b1
605 check_ok test15-a Wants test15-b.service
606 check_ko test15-a Wants test15-b1.service
# the alias does not show up in the list of units
607 rm /etc
/systemd
/system
/test15-b1.service
609 # 'b1' is an alias for 'b': masking 'b1' should not influence 'b' dep
610 echo "*** test a wants b, alias dep is masked"
611 create_services test15-a test15-b
612 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
613 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b1.service
614 ln -sf ..
/test15-b.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
615 check_ok test15-a Wants test15-b.service
616 check_ko test15-a Wants test15-b1.service
# the alias does not show up in the list of units
617 rm /etc
/systemd
/system
/test15-b1.service
619 # 'a' has Wants=b.service but also has a masking
620 # dropin 'b': 'b' should still be pulled in.
621 echo "*** test a wants b both ways"
622 create_services test15-a test15-b
623 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
624 cat >/usr
/lib
/systemd
/system
/test15-a.service.d
/wants-b.conf
<<EOF
626 Wants=test15-b.service
628 check_ok test15-a Wants test15-b.service
630 # mask a dropin that points to an nonexistent unit.
631 echo "*** test a wants nonexistent is masked"
632 create_services test15-a
633 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/nonexistent.service
634 ln -sf ..
/nonexistent.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
635 check_ko test15-a Requires nonexistent.service
637 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
638 # masked at a higher level.
639 echo "*** test a wants b is masked"
640 create_services test15-a test15-b test15-c
641 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
642 ln -sf ..
/test15-b.service
/run
/systemd
/system
/test15-c.service.requires
/
643 ln -sf /dev
/null
/etc
/systemd
/system
/test15-c.service.requires
/test15-b.service
644 systemctl start test15-a
645 check_ko test15-c Requires test15-b.service
646 systemctl stop test15-a test15-b
648 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
649 # masked at a lower level.
650 echo "*** test a requires b is masked"
651 create_services test15-a test15-b test15-c
652 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
653 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-c.service.requires
/
654 ln -sf /dev
/null
/run
/systemd
/system
/test15-c.service.requires
/test15-b.service
655 systemctl start test15-a
656 check_ok test15-c Requires test15-b.service
657 systemctl stop test15-a test15-b
659 # 'a' requires 2 aliases of 'b' and one of them is a mask.
660 echo "*** test a requires alias of b, other alias masked"
661 create_services test15-a test15-b
662 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
663 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b2.service
664 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b1.service
665 ln -sf ..
/test15-b1.service
/run
/systemd
/system
/test15-a.service.requires
/
666 ln -sf ..
/test15-b2.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
667 check_ok test15-a Requires test15-b
669 # Same as above but now 'b' is masked.
670 echo "*** test a requires alias of b, b dep masked"
671 create_services test15-a test15-b
672 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
673 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b2.service
674 ln -sf ..
/test15-b1.service
/run
/systemd
/system
/test15-a.service.requires
/
675 ln -sf ..
/test15-b2.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
676 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b.service
677 check_ok test15-a Requires test15-b
679 clear_units test15-
{a
,b
}.service
682 testcase_invalid_dropins
() {
683 echo "Testing invalid dropins..."
684 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
685 systemctl
cat nonexistent@.service || true
687 systemctl daemon-reload
688 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
689 systemctl
cat a@.service || true
691 clear_units a.service
695 testcase_symlink_dropin_directory
() {
697 echo "Testing symlink drop-in directory..."
698 create_services test15-a
699 rmdir /{etc
,run
,usr
/lib
}/systemd
/system
/test15-a.service.d
700 mkdir
-p /tmp
/testsuite-15-test15-a-dropin-directory
701 ln -s /tmp
/testsuite-15-test15-a-dropin-directory
/etc
/systemd
/system
/test15-a.service.d
702 cat >/tmp
/testsuite-15-test15-a-dropin-directory
/override.conf
<<EOF
706 ln -s /tmp
/testsuite-15-test15-a-dropin-directory-nonexistent
/run
/systemd
/system
/test15-a.service.d
707 touch /tmp
/testsuite-15-test15-a-dropin-directory-regular
708 ln -s /tmp
/testsuite-15-test15-a-dropin-directory-regular
/usr
/lib
/systemd
/system
/test15-a.service.d
709 check_ok test15-a Description hogehoge
711 clear_units test15-a.service