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
12 local unit_name
="${1:?}"
15 systemctl stop
"$unit_name" 2>/dev
/null ||
:
16 rm -f /{etc
,run
,usr
/lib
}/systemd
/system
/"$unit_name"
17 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$unit_name".d
18 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$unit_name".
{wants
,requires
}
19 if [[ $unit_name == *@
* ]]; then
20 base
="${unit_name%@*}"
21 suffix
="${unit_name##*.}"
22 systemctl stop
"$base@"*.
"$suffix" 2>/dev
/null ||
:
23 rm -f /{etc
,run
,usr
/lib
}/systemd
/system
/"$base@"*.
"$suffix"
24 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$base@"*.
"$suffix".d
25 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/"$base@"*.
"$suffix".
{wants
,requires
}
33 systemctl daemon-reload
37 local service_name
="${1:?}"
38 clear_units
"${service_name}".service
40 cat >/etc
/systemd
/system
/"$service_name".service
<<EOF
42 Description=$service_name unit
45 ExecStart=sleep 100000
47 mkdir
-p /{etc
,run
,usr
/lib
}/systemd
/system
/"$service_name".service.
{d
,wants
,requires
}
57 x
="$(systemctl show --value -p "${2:?}" "${1:?}")"
68 testcase_basic_dropins
() {
69 echo "Testing basic dropins..."
71 echo "*** test a wants b wants c"
72 create_services test15-a test15-b test15-c
73 ln -s ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.wants
/
74 ln -s ..
/test15-c.service
/etc
/systemd
/system
/test15-b.service.wants
/
75 check_ok test15-a Wants test15-b.service
76 check_ok test15-b Wants test15-c.service
78 echo "*** test a wants,requires b"
79 create_services test15-a test15-b test15-c
80 ln -s ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.wants
/
81 ln -s ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
82 check_ok test15-a Wants test15-b.service
83 check_ok test15-a Requires test15-b.service
85 echo "*** test a wants nonexistent"
86 create_service test15-a
87 ln -s ..
/nonexistent.service
/etc
/systemd
/system
/test15-a.service.wants
/
88 check_ok test15-a Wants nonexistent.service
89 systemctl start test15-a
90 systemctl stop test15-a
92 echo "*** test a requires nonexistent"
93 ln -sf ..
/nonexistent.service
/etc
/systemd
/system
/test15-a.service.requires
/
94 systemctl daemon-reload
95 check_ok test15-a Requires nonexistent.service
97 # 'b' is already loaded when 'c' pulls it in via a dropin.
98 echo "*** test a,c require b"
99 create_services test15-a test15-b test15-c
100 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
101 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-c.service.requires
/
102 systemctl start test15-a
103 check_ok test15-c Requires test15-b.service
104 systemctl stop test15-a test15-b
106 # 'b' is already loaded when 'c' pulls it in via an alias dropin.
107 echo "*** test a wants alias"
108 create_services test15-a test15-b test15-c
109 ln -sf test15-c.service
/etc
/systemd
/system
/test15-c1.service
110 ln -sf ..
/test15-c.service
/etc
/systemd
/system
/test15-a.service.wants
/
111 ln -sf ..
/test15-c1.service
/etc
/systemd
/system
/test15-b.service.wants
/
112 systemctl start test15-a
113 check_ok test15-a Wants test15-c.service
114 check_ok test15-b Wants test15-c.service
115 systemctl stop test15-a test15-c
117 echo "*** test service.d/ top level drop-in"
118 create_services test15-a test15-b
119 check_ko test15-a ExecCondition
"/bin/echo a"
120 check_ko test15-b ExecCondition
"/bin/echo b"
121 mkdir
-p /run
/systemd
/system
/service.d
122 cat >/run
/systemd
/system
/service.d
/override.conf
<<EOF
124 ExecCondition=/bin/echo %n
126 systemctl daemon-reload
127 check_ok test15-a ExecCondition
"/bin/echo test15-a"
128 check_ok test15-b ExecCondition
"/bin/echo test15-b"
129 rm -rf /run
/systemd
/system
/service.d
131 clear_units test15-
{a
,b
,c
,c1
}.service
134 testcase_linked_units
() {
135 echo "Testing linked units..."
136 echo "*** test linked unit (same basename)"
138 create_service test15-a
139 mv /etc
/systemd
/system
/test15-a.service
/
140 ln -s /test15-a.service
/etc
/systemd
/system
/
141 ln -s test15-a.service
/etc
/systemd
/system
/test15-b.service
143 check_ok test15-a Names test15-a.service
144 check_ok test15-a Names test15-b.service
146 echo "*** test linked unit (cross basename)"
148 mv /test15-a.service
/test15-a@.scope
149 ln -fs /test15-a@.scope
/etc
/systemd
/system
/test15-a.service
150 systemctl daemon-reload
152 check_ok test15-a Names test15-a.service
153 check_ok test15-a Names test15-b.service
154 check_ko test15-a Names test15-a@
# test15-a@.scope is the symlink target.
155 # Make sure it is completely ignored.
158 clear_units test15-
{a
,b
}.service
161 testcase_template_alias
() {
162 echo "Testing instance alias..."
165 create_service test15-a@
166 ln -s test15-a@inst.service
/etc
/systemd
/system
/test15-b@inst.service
# alias
168 check_ok test15-a@inst Names test15-a@inst.service
169 check_ok test15-a@inst Names test15-b@inst.service
171 check_ok test15-a@other Names test15-a@other.service
172 check_ko test15-a@other Names test15-b@other.service
176 systemctl daemon-reload
178 check_ok test15-b@inst Names test15-a@inst.service
179 check_ok test15-b@inst Names test15-b@inst.service
181 check_ko test15-b@other Names test15-a@other.service
182 check_ok test15-b@other Names test15-b@other.service
184 clear_units test15-
{a
,b
}@.service
187 testcase_hierarchical_service_dropins
() {
188 echo "Testing hierarchical service dropins..."
189 echo "*** test service.d/ top level drop-in"
190 create_services a-b-c
191 check_ko a-b-c ExecCondition
"echo service.d"
192 check_ko a-b-c ExecCondition
"echo a-.service.d"
193 check_ko a-b-c ExecCondition
"echo a-b-.service.d"
194 check_ko a-b-c ExecCondition
"echo a-b-c.service.d"
196 for dropin
in service.d a-.service.d a-b-.service.d a-b-c.service.d
; do
197 mkdir
-p "/run/systemd/system/$dropin"
198 cat >"/run/systemd/system/$dropin/override.conf" <<EOF
200 ExecCondition=echo $dropin
202 systemctl daemon-reload
203 check_ok a-b-c ExecCondition
"echo $dropin"
205 # Check that we can start a transient service in presence of the drop-ins
206 systemd-run
-u a-b-c2.service
-p Description
='sleepy' sleep infinity
208 # The transient setting replaces the default
209 check_ok a-b-c2.service Description
"sleepy"
211 # The override takes precedence for ExecCondition
212 # (except the last iteration when it only applies to the other service)
213 if [ "$dropin" != "a-b-c.service.d" ]; then
214 check_ok a-b-c2.service ExecCondition
"echo $dropin"
217 # Check that things are the same after a reload
218 systemctl daemon-reload
219 check_ok a-b-c2.service Description
"sleepy"
220 if [ "$dropin" != "a-b-c.service.d" ]; then
221 check_ok a-b-c2.service ExecCondition
"echo $dropin"
224 systemctl stop a-b-c2.service
226 for dropin
in service.d a-.service.d a-b-.service.d a-b-c.service.d
; do
227 rm -rf "/run/systemd/system/$dropin"
230 clear_units a-b-c.service
233 testcase_hierarchical_slice_dropins
() {
234 echo "Testing hierarchical slice dropins..."
235 echo "*** test slice.d/ top level drop-in"
236 # Slice units don't even need a fragment, so we test the defaults here
237 check_ok a-b-c.slice Description
"Slice /a/b/c"
238 check_ok a-b-c.slice MemoryMax
"infinity"
241 for dropin
in slice.d a-.slice.d a-b-.slice.d a-b-c.slice.d
; do
242 mkdir
-p "/run/systemd/system/$dropin"
243 cat >"/run/systemd/system/$dropin/override.conf" <<EOF
247 systemctl daemon-reload
248 check_ok a-b-c.slice MemoryMax
"1000000000"
251 org.freedesktop.systemd1 \
252 /org
/freedesktop
/systemd1 \
253 org.freedesktop.systemd1.Manager \
254 StartTransientUnit
'ssa(sv)a(sa(sv))' \
255 'a-b-c.slice' 'replace' \
257 'Description' s
'slice too' \
258 'MemoryMax' t
1000000002 \
261 # The override takes precedence for MemoryMax
262 check_ok a-b-c.slice MemoryMax
"1000000000"
263 # The transient setting replaces the default
264 check_ok a-b-c.slice Description
"slice too"
266 # Check that things are the same after a reload
267 systemctl daemon-reload
268 check_ok a-b-c.slice MemoryMax
"1000000000"
269 check_ok a-b-c.slice Description
"slice too"
272 org.freedesktop.systemd1 \
273 /org
/freedesktop
/systemd1 \
274 org.freedesktop.systemd1.Manager \
276 'a-b-c.slice' 'replace'
278 rm -f "/run/systemd/system/$dropin/override.conf"
281 # Test unit with a fragment
282 cat >/run
/systemd
/system
/a-b-c.slice
<<EOF
286 systemctl daemon-reload
287 check_ok a-b-c.slice MemoryMax
"1000000001"
289 clear_units a-b-c.slice
292 testcase_transient_service_dropins
() {
293 echo "Testing dropins for a transient service..."
294 echo "*** test transient service drop-ins"
296 mkdir
-p /etc
/systemd
/system
/service.d
297 mkdir
-p /etc
/systemd
/system
/a-.service.d
298 mkdir
-p /etc
/systemd
/system
/a-b-.service.d
299 mkdir
-p /etc
/systemd
/system
/a-b-c.service.d
301 echo -e '[Service]\nStandardInputText=aaa' >/etc
/systemd
/system
/service.d
/drop1.conf
302 echo -e '[Service]\nStandardInputText=bbb' >/etc
/systemd
/system
/a-.service.d
/drop2.conf
303 echo -e '[Service]\nStandardInputText=ccc' >/etc
/systemd
/system
/a-b-.service.d
/drop3.conf
304 echo -e '[Service]\nStandardInputText=ddd' >/etc
/systemd
/system
/a-b-c.service.d
/drop4.conf
306 # There's no fragment yet, so this fails
307 systemctl
cat a-b-c.service
&& exit 1
310 systemd-run
-u a-b-c.service
-p StandardInputData
=eHh4Cg
== sleep infinity
312 data
=$
(systemctl show
-P StandardInputData a-b-c.service
)
313 # xxx\naaa\n\bbb\nccc\nddd\n → eHh4…
314 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
316 # Do a reload and check again
317 systemctl daemon-reload
318 data
=$
(systemctl show
-P StandardInputData a-b-c.service
)
319 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
321 clear_units a-b-c.service
322 rm /etc
/systemd
/system
/service.d
/drop1.conf \
323 /etc
/systemd
/system
/a-.service.d
/drop2.conf \
324 /etc
/systemd
/system
/a-b-.service.d
/drop3.conf
327 testcase_transient_slice_dropins
() {
328 echo "Testing dropins for a transient slice..."
329 echo "*** test transient slice drop-ins"
331 # FIXME: implement reloading of individual units.
333 # The settings here are loaded twice. For most settings it doesn't matter,
334 # but Documentation is not deduplicated, so we current get repeated entried
337 mkdir
-p /etc
/systemd
/system
/slice.d
338 mkdir
-p /etc
/systemd
/system
/a-.slice.d
339 mkdir
-p /etc
/systemd
/system
/a-b-.slice.d
340 mkdir
-p /etc
/systemd
/system
/a-b-c.slice.d
342 echo -e '[Unit]\nDocumentation=man:drop1' >/etc
/systemd
/system
/slice.d
/drop1.conf
343 echo -e '[Unit]\nDocumentation=man:drop2' >/etc
/systemd
/system
/a-.slice.d
/drop2.conf
344 echo -e '[Unit]\nDocumentation=man:drop3' >/etc
/systemd
/system
/a-b-.slice.d
/drop3.conf
345 echo -e '[Unit]\nDocumentation=man:drop4' >/etc
/systemd
/system
/a-b-c.slice.d
/drop4.conf
347 # Invoke daemon-reload to make sure that the call below doesn't fail
348 systemctl daemon-reload
350 # No fragment is required, so this works
351 systemctl
cat a-b-c.slice
354 org.freedesktop.systemd1 \
355 /org
/freedesktop
/systemd1 \
356 org.freedesktop.systemd1.Manager \
357 StartTransientUnit
'ssa(sv)a(sa(sv))' \
358 'a-b-c.slice' 'replace' \
360 'Documentation' as
1 'man:drop5' \
363 data
=$
(systemctl show
-P Documentation a-b-c.slice
)
364 test "$data" = "man:drop1 man:drop2 man:drop3 man:drop4 man:drop5 man:drop1 man:drop2 man:drop3 man:drop4"
366 # Do a reload and check again
367 systemctl daemon-reload
368 data
=$
(systemctl show
-P Documentation a-b-c.slice
)
369 test "$data" = "man:drop5 man:drop1 man:drop2 man:drop3 man:drop4"
371 clear_units a-b-c.slice
372 rm /etc
/systemd
/system
/slice.d
/drop1.conf \
373 /etc
/systemd
/system
/a-.slice.d
/drop2.conf \
374 /etc
/systemd
/system
/a-b-.slice.d
/drop3.conf
377 testcase_template_dropins
() {
378 echo "Testing template dropins..."
380 create_services foo bar@ yup@
382 # Declare some deps to check if the body was loaded
383 cat >>/etc
/systemd
/system
/bar@.service
<<EOF
385 After=bar-template-after.device
388 cat >>/etc
/systemd
/system
/yup@.service
<<EOF
390 After=yup-template-after.device
393 ln -s /etc
/systemd
/system
/bar@.service
/etc
/systemd
/system
/foo.service.wants
/bar@
1.service
394 check_ok foo Wants bar@
1.service
396 echo "*** test bar-alias@.service→bar@.service, but instance symlinks point to yup@.service ***"
397 ln -s bar@.service
/etc
/systemd
/system
/bar-alias@.service
398 ln -s bar@
1.service
/etc
/systemd
/system
/bar-alias@
1.service
399 ln -s yup@.service
/etc
/systemd
/system
/bar-alias@
2.service
400 ln -s yup@
3.service
/etc
/systemd
/system
/bar-alias@
3.service
402 # create some dropin deps
403 mkdir
-p /etc
/systemd
/system
/bar@
{,0,1,2,3}.service.requires
/
404 mkdir
-p /etc
/systemd
/system
/yup@
{,0,1,2,3}.service.requires
/
405 mkdir
-p /etc
/systemd
/system
/bar-alias@
{,0,1,2,3}.service.requires
/
407 ln -s ..
/bar-template-requires.device
/etc
/systemd
/system
/bar@.service.requires
/
408 ln -s ..
/bar-0-requires.device
/etc
/systemd
/system
/bar@
0.service.requires
/
409 ln -s ..
/bar-1-requires.device
/etc
/systemd
/system
/bar@
1.service.requires
/
410 ln -s ..
/bar-2-requires.device
/etc
/systemd
/system
/bar@
2.service.requires
/
411 ln -s ..
/bar-3-requires.device
/etc
/systemd
/system
/bar@
3.service.requires
/
413 ln -s ..
/yup-template-requires.device
/etc
/systemd
/system
/yup@.service.requires
/
414 ln -s ..
/yup-0-requires.device
/etc
/systemd
/system
/yup@
0.service.requires
/
415 ln -s ..
/yup-1-requires.device
/etc
/systemd
/system
/yup@
1.service.requires
/
416 ln -s ..
/yup-2-requires.device
/etc
/systemd
/system
/yup@
2.service.requires
/
417 ln -s ..
/yup-3-requires.device
/etc
/systemd
/system
/yup@
3.service.requires
/
419 ln -s ..
/bar-alias-template-requires.device
/etc
/systemd
/system
/bar-alias@.service.requires
/
420 ln -s ..
/bar-alias-0-requires.device
/etc
/systemd
/system
/bar-alias@
0.service.requires
/
421 ln -s ..
/bar-alias-1-requires.device
/etc
/systemd
/system
/bar-alias@
1.service.requires
/
422 ln -s ..
/bar-alias-2-requires.device
/etc
/systemd
/system
/bar-alias@
2.service.requires
/
423 ln -s ..
/bar-alias-3-requires.device
/etc
/systemd
/system
/bar-alias@
3.service.requires
/
425 systemctl daemon-reload
427 echo '*** bar@0 is aliased by bar-alias@0 ***'
428 systemctl show
-p Names
,Requires bar@
0
429 systemctl show
-p Names
,Requires bar-alias@
0
430 check_ok bar@
0 Names bar@
0
431 check_ok bar@
0 Names bar-alias@
0
433 check_ok bar@
0 After bar-template-after.device
435 check_ok bar@
0 Requires bar-0-requires.device
436 check_ok bar@
0 Requires bar-alias-0-requires.device
437 check_ok bar@
0 Requires bar-template-requires.device
438 check_ok bar@
0 Requires bar-alias-template-requires.device
439 check_ko bar@
0 Requires yup-template-requires.device
441 check_ok bar-alias@
0 After bar-template-after.device
443 check_ok bar-alias@
0 Requires bar-0-requires.device
444 check_ok bar-alias@
0 Requires bar-alias-0-requires.device
445 check_ok bar-alias@
0 Requires bar-template-requires.device
446 check_ok bar-alias@
0 Requires bar-alias-template-requires.device
447 check_ko bar-alias@
0 Requires yup-template-requires.device
448 check_ko bar-alias@
0 Requires yup-0-requires.device
450 echo '*** bar@1 is aliased by bar-alias@1 ***'
451 systemctl show
-p Names
,Requires bar@
1
452 systemctl show
-p Names
,Requires bar-alias@
1
453 check_ok bar@
1 Names bar@
1
454 check_ok bar@
1 Names bar-alias@
1
456 check_ok bar@
1 After bar-template-after.device
458 check_ok bar@
1 Requires bar-1-requires.device
459 check_ok bar@
1 Requires bar-alias-1-requires.device
460 check_ok bar@
1 Requires bar-template-requires.device
461 # See https://github.com/systemd/systemd/pull/13119#discussion_r308145418
462 check_ok bar@
1 Requires bar-alias-template-requires.device
463 check_ko bar@
1 Requires yup-template-requires.device
464 check_ko bar@
1 Requires yup-1-requires.device
466 check_ok bar-alias@
1 After bar-template-after.device
468 check_ok bar-alias@
1 Requires bar-1-requires.device
469 check_ok bar-alias@
1 Requires bar-alias-1-requires.device
470 check_ok bar-alias@
1 Requires bar-template-requires.device
471 check_ok bar-alias@
1 Requires bar-alias-template-requires.device
472 check_ko bar-alias@
1 Requires yup-template-requires.device
473 check_ko bar-alias@
1 Requires yup-1-requires.device
475 echo '*** bar-alias@2 aliases yup@2, bar@2 is independent ***'
476 systemctl show
-p Names
,Requires bar@
2
477 systemctl show
-p Names
,Requires bar-alias@
2
478 check_ok bar@
2 Names bar@
2
479 check_ko bar@
2 Names bar-alias@
2
481 check_ok bar@
2 After bar-template-after.device
483 check_ok bar@
2 Requires bar-2-requires.device
484 check_ko bar@
2 Requires bar-alias-2-requires.device
485 check_ok bar@
2 Requires bar-template-requires.device
486 check_ko bar@
2 Requires bar-alias-template-requires.device
487 check_ko bar@
2 Requires yup-template-requires.device
488 check_ko bar@
2 Requires yup-2-requires.device
490 check_ko bar-alias@
2 After bar-template-after.device
492 check_ko bar-alias@
2 Requires bar-2-requires.device
493 check_ok bar-alias@
2 Requires bar-alias-2-requires.device
494 check_ko bar-alias@
2 Requires bar-template-requires.device
495 check_ok bar-alias@
2 Requires bar-alias-template-requires.device
496 check_ok bar-alias@
2 Requires yup-template-requires.device
497 check_ok bar-alias@
2 Requires yup-2-requires.device
499 echo '*** bar-alias@3 aliases yup@3, bar@3 is independent ***'
500 systemctl show
-p Names
,Requires bar@
3
501 systemctl show
-p Names
,Requires bar-alias@
3
502 check_ok bar@
3 Names bar@
3
503 check_ko bar@
3 Names bar-alias@
3
505 check_ok bar@
3 After bar-template-after.device
507 check_ok bar@
3 Requires bar-3-requires.device
508 check_ko bar@
3 Requires bar-alias-3-requires.device
509 check_ok bar@
3 Requires bar-template-requires.device
510 check_ko bar@
3 Requires bar-alias-template-requires.device
511 check_ko bar@
3 Requires yup-template-requires.device
512 check_ko bar@
3 Requires yup-3-requires.device
514 check_ko bar-alias@
3 After bar-template-after.device
516 check_ko bar-alias@
3 Requires bar-3-requires.device
517 check_ok bar-alias@
3 Requires bar-alias-3-requires.device
518 check_ko bar-alias@
3 Requires bar-template-requires.device
519 check_ok bar-alias@
3 Requires bar-alias-template-requires.device
520 check_ok bar-alias@
3 Requires yup-template-requires.device
521 check_ok bar-alias@
3 Requires yup-3-requires.device
523 clear_units foo.service
{bar
,yup
,bar-alias
}@
{,1,2,3}.service
526 testcase_alias_dropins
() {
527 echo "Testing alias dropins..."
529 echo "*** test a wants b1 alias of b"
530 create_services test15-a test15-b
531 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
532 ln -sf ..
/test15-b1.service
/etc
/systemd
/system
/test15-a.service.wants
/
533 check_ok test15-a Wants test15-b.service
534 systemctl start test15-a
535 systemctl
--quiet is-active test15-b
536 systemctl stop test15-a test15-b
537 rm /etc
/systemd
/system
/test15-b1.service
538 clear_units test15-
{a
,b
}.service
540 # Check that dependencies don't vary.
542 create_services test15-a test15-x test15-y
543 mkdir
-p /etc
/systemd
/system
/test15-a1.service.wants
/
544 ln -sf test15-a.service
/etc
/systemd
/system
/test15-a1.service
545 ln -sf ..
/test15-x.service
/etc
/systemd
/system
/test15-a.service.wants
/
546 ln -sf ..
/test15-y.service
/etc
/systemd
/system
/test15-a1.service.wants
/
547 check_ok test15-a1 Wants test15-x.service
# see [1]
548 check_ok test15-a1 Wants test15-y.service
549 systemctl start test15-a
550 check_ok test15-a1 Wants test15-x.service
# see [2]
551 check_ok test15-a1 Wants test15-y.service
552 systemctl stop test15-a test15-x test15-y
553 rm /etc
/systemd
/system
/test15-a1.service
555 clear_units test15-
{a
,x
,y
}.service
558 testcase_masked_dropins
() {
559 echo "Testing masked dropins..."
561 create_services test15-a test15-b
563 # 'b' is masked for both deps
564 echo "*** test a wants,requires b is masked"
565 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
566 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b.service
567 check_ko test15-a Wants test15-b.service
568 check_ko test15-a Requires test15-b.service
570 # 'a' wants 'b' and 'b' is masked at a lower level
571 echo "*** test a wants b, mask override"
572 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
573 ln -sf /dev
/null
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
574 check_ok test15-a Wants test15-b.service
576 # 'a' wants 'b' and 'b' is masked at a higher level
577 echo "*** test a wants b, mask"
578 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
579 ln -sf ..
/test15-b.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
580 check_ko test15-a Wants test15-b.service
582 # 'a' is masked but has an override config file
583 echo "*** test a is masked but has an override"
584 create_services test15-a test15-b
585 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service
586 cat >/usr
/lib
/systemd
/system
/test15-a.service.d
/override.conf
<<EOF
588 After=test15-b.service
590 check_ok test15-a UnitFileState masked
592 # 'b1' is an alias for 'b': masking 'b' dep should not influence 'b1' dep
593 echo "*** test a wants b, b1, and one is masked"
594 create_services test15-a test15-b
595 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
596 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
597 ln -sf ..
/test15-b1.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b1.service
598 systemctl
cat test15-a
599 systemctl show
-p Wants
,Requires test15-a
600 systemctl
cat test15-b1
601 systemctl show
-p Wants
,Requires test15-b1
602 check_ok test15-a Wants test15-b.service
603 check_ko test15-a Wants test15-b1.service
# the alias does not show up in the list of units
604 rm /etc
/systemd
/system
/test15-b1.service
606 # 'b1' is an alias for 'b': masking 'b1' should not influence 'b' dep
607 echo "*** test a wants b, alias dep is masked"
608 create_services test15-a test15-b
609 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
610 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b1.service
611 ln -sf ..
/test15-b.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
612 check_ok test15-a Wants test15-b.service
613 check_ko test15-a Wants test15-b1.service
# the alias does not show up in the list of units
614 rm /etc
/systemd
/system
/test15-b1.service
616 # 'a' has Wants=b.service but also has a masking
617 # dropin 'b': 'b' should still be pulled in.
618 echo "*** test a wants b both ways"
619 create_services test15-a test15-b
620 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
621 cat >/usr
/lib
/systemd
/system
/test15-a.service.d
/wants-b.conf
<<EOF
623 Wants=test15-b.service
625 check_ok test15-a Wants test15-b.service
627 # mask a dropin that points to an nonexistent unit.
628 echo "*** test a wants nonexistent is masked"
629 create_services test15-a
630 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/nonexistent.service
631 ln -sf ..
/nonexistent.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
632 check_ko test15-a Requires nonexistent.service
634 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
635 # masked at a higher level.
636 echo "*** test a wants b is masked"
637 create_services test15-a test15-b test15-c
638 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
639 ln -sf ..
/test15-b.service
/run
/systemd
/system
/test15-c.service.requires
/
640 ln -sf /dev
/null
/etc
/systemd
/system
/test15-c.service.requires
/test15-b.service
641 systemctl start test15-a
642 check_ko test15-c Requires test15-b.service
643 systemctl stop test15-a test15-b
645 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
646 # masked at a lower level.
647 echo "*** test a requires b is masked"
648 create_services test15-a test15-b test15-c
649 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
650 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-c.service.requires
/
651 ln -sf /dev
/null
/run
/systemd
/system
/test15-c.service.requires
/test15-b.service
652 systemctl start test15-a
653 check_ok test15-c Requires test15-b.service
654 systemctl stop test15-a test15-b
656 # 'a' requires 2 aliases of 'b' and one of them is a mask.
657 echo "*** test a requires alias of b, other alias masked"
658 create_services test15-a test15-b
659 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
660 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b2.service
661 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b1.service
662 ln -sf ..
/test15-b1.service
/run
/systemd
/system
/test15-a.service.requires
/
663 ln -sf ..
/test15-b2.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
664 check_ok test15-a Requires test15-b
666 # Same as above but now 'b' is masked.
667 echo "*** test a requires alias of b, b dep masked"
668 create_services test15-a test15-b
669 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
670 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b2.service
671 ln -sf ..
/test15-b1.service
/run
/systemd
/system
/test15-a.service.requires
/
672 ln -sf ..
/test15-b2.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
673 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b.service
674 check_ok test15-a Requires test15-b
676 clear_units test15-
{a
,b
}.service
679 testcase_invalid_dropins
() {
680 echo "Testing invalid dropins..."
681 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
682 systemctl
cat nonexistent@.service || true
684 systemctl daemon-reload
685 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
686 systemctl
cat a@.service || true
688 clear_units a.service
692 testcase_symlink_dropin_directory
() {
694 echo "Testing symlink drop-in directory..."
695 create_services test15-a
696 rmdir /{etc
,run
,usr
/lib
}/systemd
/system
/test15-a.service.d
697 mkdir
-p /tmp
/testsuite-15-test15-a-dropin-directory
698 ln -s /tmp
/testsuite-15-test15-a-dropin-directory
/etc
/systemd
/system
/test15-a.service.d
699 cat >/tmp
/testsuite-15-test15-a-dropin-directory
/override.conf
<<EOF
703 ln -s /tmp
/testsuite-15-test15-a-dropin-directory-nonexistent
/run
/systemd
/system
/test15-a.service.d
704 touch /tmp
/testsuite-15-test15-a-dropin-directory-regular
705 ln -s /tmp
/testsuite-15-test15-a-dropin-directory-regular
/usr
/lib
/systemd
/system
/test15-a.service.d
706 check_ok test15-a Description hogehoge
708 clear_units test15-a.service