]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-15.sh
tree-wide: do not use "re" with fmemopen
[thirdparty/systemd.git] / test / units / testsuite-15.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -eux
4 set -o pipefail
5
6 clear_unit () {
7 local UNIT_NAME="${1:?}"
8 systemctl stop "$UNIT_NAME" 2>/dev/null || :
9 rm -f /{etc,run,usr/lib}/systemd/system/"$UNIT_NAME"
10 rm -fr /{etc,run,usr/lib}/systemd/system/"$UNIT_NAME".d
11 rm -fr /{etc,run,usr/lib}/systemd/system/"$UNIT_NAME".{wants,requires}
12 if [[ $UNIT_NAME == *@ ]]; then
13 local base="${UNIT_NAME%@*}"
14 local suffix="${UNIT_NAME##*.}"
15 systemctl stop "$base@"*."$suffix" 2>/dev/null || :
16 rm -f /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix"
17 rm -fr /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix".d
18 rm -fr /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix".{wants,requires}
19 fi
20 }
21
22 clear_units () {
23 for u in "$@"; do
24 clear_unit "$u"
25 done
26 systemctl daemon-reload
27 }
28
29 create_service () {
30 local SERVICE_NAME="${1:?}"
31 clear_units "${SERVICE_NAME}".service
32
33 cat >/etc/systemd/system/"$SERVICE_NAME".service <<EOF
34 [Unit]
35 Description=$SERVICE_NAME unit
36
37 [Service]
38 ExecStart=sleep 100000
39 EOF
40 mkdir -p /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{d,wants,requires}
41 }
42
43 create_services () {
44 for u in "$@"; do
45 create_service "$u"
46 done
47 }
48
49 check_ok () {
50 x="$(systemctl show --value -p "${2:?}" "${1:?}")"
51 case "$x" in
52 *${3:?}*) return 0 ;;
53 *) return 1 ;;
54 esac
55 }
56
57 check_ko () {
58 ! check_ok "$@"
59 }
60
61 test_basic_dropins () {
62 echo "Testing basic dropins..."
63
64 echo "*** test a wants b wants c"
65 create_services test15-a test15-b test15-c
66 ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/
67 ln -s ../test15-c.service /etc/systemd/system/test15-b.service.wants/
68 check_ok test15-a Wants test15-b.service
69 check_ok test15-b Wants test15-c.service
70
71 echo "*** test a wants,requires b"
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-b.service /etc/systemd/system/test15-a.service.requires/
75 check_ok test15-a Wants test15-b.service
76 check_ok test15-a Requires test15-b.service
77
78 echo "*** test a wants nonexistent"
79 create_service test15-a
80 ln -s ../nonexistent.service /etc/systemd/system/test15-a.service.wants/
81 check_ok test15-a Wants nonexistent.service
82 systemctl start test15-a
83 systemctl stop test15-a
84
85 echo "*** test a requires nonexistent"
86 ln -sf ../nonexistent.service /etc/systemd/system/test15-a.service.requires/
87 systemctl daemon-reload
88 check_ok test15-a Requires nonexistent.service
89
90 # 'b' is already loaded when 'c' pulls it in via a dropin.
91 echo "*** test a,c require b"
92 create_services test15-a test15-b test15-c
93 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
94 ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/
95 systemctl start test15-a
96 check_ok test15-c Requires test15-b.service
97 systemctl stop test15-a test15-b
98
99 # 'b' is already loaded when 'c' pulls it in via an alias dropin.
100 echo "*** test a wants alias"
101 create_services test15-a test15-b test15-c
102 ln -sf test15-c.service /etc/systemd/system/test15-c1.service
103 ln -sf ../test15-c.service /etc/systemd/system/test15-a.service.wants/
104 ln -sf ../test15-c1.service /etc/systemd/system/test15-b.service.wants/
105 systemctl start test15-a
106 check_ok test15-a Wants test15-c.service
107 check_ok test15-b Wants test15-c.service
108 systemctl stop test15-a test15-c
109
110 echo "*** test service.d/ top level drop-in"
111 create_services test15-a test15-b
112 check_ko test15-a ExecCondition "/bin/echo a"
113 check_ko test15-b ExecCondition "/bin/echo b"
114 mkdir -p /usr/lib/systemd/system/service.d
115 cat >/usr/lib/systemd/system/service.d/override.conf <<EOF
116 [Service]
117 ExecCondition=/bin/echo %n
118 EOF
119 systemctl daemon-reload
120 check_ok test15-a ExecCondition "/bin/echo test15-a"
121 check_ok test15-b ExecCondition "/bin/echo test15-b"
122 rm -rf /usr/lib/systemd/system/service.d
123
124 clear_units test15-{a,b,c,c1}.service
125 }
126
127 test_linked_units () {
128 echo "Testing linked units..."
129 echo "*** test linked unit (same basename)"
130
131 create_service test15-a
132 mv /etc/systemd/system/test15-a.service /
133 ln -s /test15-a.service /etc/systemd/system/
134 ln -s test15-a.service /etc/systemd/system/test15-b.service
135
136 check_ok test15-a Names test15-a.service
137 check_ok test15-a Names test15-b.service
138
139 echo "*** test linked unit (cross basename)"
140
141 mv /test15-a.service /test15-a@.scope
142 ln -fs /test15-a@.scope /etc/systemd/system/test15-a.service
143 systemctl daemon-reload
144
145 check_ok test15-a Names test15-a.service
146 check_ok test15-a Names test15-b.service
147 check_ko test15-a Names test15-a@ # test15-a@.scope is the symlink target.
148 # Make sure it is completely ignored.
149
150 rm /test15-a@.scope
151 clear_units test15-{a,b}.service
152 }
153
154 test_template_alias() {
155 echo "Testing instance alias..."
156 echo "*** forward"
157
158 create_service test15-a@
159 ln -s test15-a@inst.service /etc/systemd/system/test15-b@inst.service # alias
160
161 check_ok test15-a@inst Names test15-a@inst.service
162 check_ok test15-a@inst Names test15-b@inst.service
163
164 check_ok test15-a@other Names test15-a@other.service
165 check_ko test15-a@other Names test15-b@other.service
166
167 echo "*** reverse"
168
169 systemctl daemon-reload
170
171 check_ok test15-b@inst Names test15-a@inst.service
172 check_ok test15-b@inst Names test15-b@inst.service
173
174 check_ko test15-b@other Names test15-a@other.service
175 check_ok test15-b@other Names test15-b@other.service
176
177 clear_units test15-{a,b}@.service
178 }
179
180 test_hierarchical_service_dropins () {
181 echo "Testing hierarchical service dropins..."
182 echo "*** test service.d/ top level drop-in"
183 create_services a-b-c
184 check_ko a-b-c ExecCondition "echo service.d"
185 check_ko a-b-c ExecCondition "echo a-.service.d"
186 check_ko a-b-c ExecCondition "echo a-b-.service.d"
187 check_ko a-b-c ExecCondition "echo a-b-c.service.d"
188
189 for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do
190 mkdir -p /usr/lib/systemd/system/$dropin
191 echo "
192 [Service]
193 ExecCondition=echo $dropin
194 " >/usr/lib/systemd/system/$dropin/override.conf
195 systemctl daemon-reload
196 check_ok a-b-c ExecCondition "echo $dropin"
197
198 # Check that we can start a transient service in presence of the drop-ins
199 systemd-run -u a-b-c2.service -p Description='sleepy' sleep infinity
200
201 # The transient setting replaces the default
202 check_ok a-b-c2.service Description "sleepy"
203
204 # The override takes precedence for ExecCondition
205 # (except the last iteration when it only applies to the other service)
206 if [ "$dropin" != "a-b-c.service.d" ]; then
207 check_ok a-b-c2.service ExecCondition "echo $dropin"
208 fi
209
210 # Check that things are the same after a reload
211 systemctl daemon-reload
212 check_ok a-b-c2.service Description "sleepy"
213 if [ "$dropin" != "a-b-c.service.d" ]; then
214 check_ok a-b-c2.service ExecCondition "echo $dropin"
215 fi
216
217 systemctl stop a-b-c2.service
218 done
219 for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do
220 rm -rf /usr/lib/systemd/system/$dropin
221 done
222
223 clear_units a-b-c.service
224 }
225
226 test_hierarchical_slice_dropins () {
227 echo "Testing hierarchical slice dropins..."
228 echo "*** test slice.d/ top level drop-in"
229 # Slice units don't even need a fragment, so we test the defaults here
230 check_ok a-b-c.slice Description "Slice /a/b/c"
231 check_ok a-b-c.slice MemoryMax "infinity"
232
233 # Test drop-ins
234 for dropin in slice.d a-.slice.d a-b-.slice.d a-b-c.slice.d; do
235 mkdir -p /usr/lib/systemd/system/$dropin
236 echo "
237 [Slice]
238 MemoryMax=1000000000
239 " >/usr/lib/systemd/system/$dropin/override.conf
240 systemctl daemon-reload
241 check_ok a-b-c.slice MemoryMax "1000000000"
242
243 busctl call \
244 org.freedesktop.systemd1 \
245 /org/freedesktop/systemd1 \
246 org.freedesktop.systemd1.Manager \
247 StartTransientUnit 'ssa(sv)a(sa(sv))' \
248 'a-b-c.slice' 'replace' \
249 2 \
250 'Description' s 'slice too' \
251 'MemoryMax' t 1000000002 \
252 0
253
254 # The override takes precedence for MemoryMax
255 check_ok a-b-c.slice MemoryMax "1000000000"
256 # The transient setting replaces the default
257 check_ok a-b-c.slice Description "slice too"
258
259 # Check that things are the same after a reload
260 systemctl daemon-reload
261 check_ok a-b-c.slice MemoryMax "1000000000"
262 check_ok a-b-c.slice Description "slice too"
263
264 busctl call \
265 org.freedesktop.systemd1 \
266 /org/freedesktop/systemd1 \
267 org.freedesktop.systemd1.Manager \
268 StopUnit 'ss' \
269 'a-b-c.slice' 'replace'
270
271 rm /usr/lib/systemd/system/$dropin/override.conf
272 done
273
274 # Test unit with a fragment
275 echo "
276 [Slice]
277 MemoryMax=1000000001
278 " >/usr/lib/systemd/system/a-b-c.slice
279 systemctl daemon-reload
280 check_ok a-b-c.slice MemoryMax "1000000001"
281
282 clear_units a-b-c.slice
283 }
284
285 test_transient_service_dropins () {
286 echo "Testing dropins for a transient service..."
287 echo "*** test transient service drop-ins"
288
289 mkdir -p /etc/systemd/system/service.d
290 mkdir -p /etc/systemd/system/a-.service.d
291 mkdir -p /etc/systemd/system/a-b-.service.d
292 mkdir -p /etc/systemd/system/a-b-c.service.d
293
294 echo -e '[Service]\nStandardInputText=aaa' >/etc/systemd/system/service.d/drop1.conf
295 echo -e '[Service]\nStandardInputText=bbb' >/etc/systemd/system/a-.service.d/drop2.conf
296 echo -e '[Service]\nStandardInputText=ccc' >/etc/systemd/system/a-b-.service.d/drop3.conf
297 echo -e '[Service]\nStandardInputText=ddd' >/etc/systemd/system/a-b-c.service.d/drop4.conf
298
299 # There's no fragment yet, so this fails
300 systemctl cat a-b-c.service && exit 1
301
302 # xxx → eHh4Cg==
303 systemd-run -u a-b-c.service -p StandardInputData=eHh4Cg== sleep infinity
304
305 data=$(systemctl show -P StandardInputData a-b-c.service)
306 # xxx\naaa\n\bbb\nccc\nddd\n → eHh4…
307 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
308
309 # Do a reload and check again
310 systemctl daemon-reload
311 data=$(systemctl show -P StandardInputData a-b-c.service)
312 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
313
314 clear_units a-b-c.service
315 rm /etc/systemd/system/service.d/drop1.conf \
316 /etc/systemd/system/a-.service.d/drop2.conf \
317 /etc/systemd/system/a-b-.service.d/drop3.conf
318 }
319
320 test_template_dropins () {
321 echo "Testing template dropins..."
322
323 create_services foo bar@ yup@
324
325 # Declare some deps to check if the body was loaded
326 cat >>/etc/systemd/system/bar@.service <<EOF
327 [Unit]
328 After=bar-template-after.device
329 EOF
330
331 cat >>/etc/systemd/system/yup@.service <<EOF
332 [Unit]
333 After=yup-template-after.device
334 EOF
335
336 ln -s /etc/systemd/system/bar@.service /etc/systemd/system/foo.service.wants/bar@1.service
337 check_ok foo Wants bar@1.service
338
339 echo "*** test bar-alias@.service→bar@.service, but instance symlinks point to yup@.service ***"
340 ln -s bar@.service /etc/systemd/system/bar-alias@.service
341 ln -s bar@1.service /etc/systemd/system/bar-alias@1.service
342 ln -s yup@.service /etc/systemd/system/bar-alias@2.service
343 ln -s yup@3.service /etc/systemd/system/bar-alias@3.service
344
345 # create some dropin deps
346 mkdir -p /etc/systemd/system/bar@{,0,1,2,3}.service.requires/
347 mkdir -p /etc/systemd/system/yup@{,0,1,2,3}.service.requires/
348 mkdir -p /etc/systemd/system/bar-alias@{,0,1,2,3}.service.requires/
349
350 ln -s ../bar-template-requires.device /etc/systemd/system/bar@.service.requires/
351 ln -s ../bar-0-requires.device /etc/systemd/system/bar@0.service.requires/
352 ln -s ../bar-1-requires.device /etc/systemd/system/bar@1.service.requires/
353 ln -s ../bar-2-requires.device /etc/systemd/system/bar@2.service.requires/
354 ln -s ../bar-3-requires.device /etc/systemd/system/bar@3.service.requires/
355
356 ln -s ../yup-template-requires.device /etc/systemd/system/yup@.service.requires/
357 ln -s ../yup-0-requires.device /etc/systemd/system/yup@0.service.requires/
358 ln -s ../yup-1-requires.device /etc/systemd/system/yup@1.service.requires/
359 ln -s ../yup-2-requires.device /etc/systemd/system/yup@2.service.requires/
360 ln -s ../yup-3-requires.device /etc/systemd/system/yup@3.service.requires/
361
362 ln -s ../bar-alias-template-requires.device /etc/systemd/system/bar-alias@.service.requires/
363 ln -s ../bar-alias-0-requires.device /etc/systemd/system/bar-alias@0.service.requires/
364 ln -s ../bar-alias-1-requires.device /etc/systemd/system/bar-alias@1.service.requires/
365 ln -s ../bar-alias-2-requires.device /etc/systemd/system/bar-alias@2.service.requires/
366 ln -s ../bar-alias-3-requires.device /etc/systemd/system/bar-alias@3.service.requires/
367
368 systemctl daemon-reload
369
370 echo '*** bar@0 is aliased by bar-alias@0 ***'
371 systemctl show -p Names,Requires bar@0
372 systemctl show -p Names,Requires bar-alias@0
373 check_ok bar@0 Names bar@0
374 check_ok bar@0 Names bar-alias@0
375
376 check_ok bar@0 After bar-template-after.device
377
378 check_ok bar@0 Requires bar-0-requires.device
379 check_ok bar@0 Requires bar-alias-0-requires.device
380 check_ok bar@0 Requires bar-template-requires.device
381 check_ok bar@0 Requires bar-alias-template-requires.device
382 check_ko bar@0 Requires yup-template-requires.device
383
384 check_ok bar-alias@0 After bar-template-after.device
385
386 check_ok bar-alias@0 Requires bar-0-requires.device
387 check_ok bar-alias@0 Requires bar-alias-0-requires.device
388 check_ok bar-alias@0 Requires bar-template-requires.device
389 check_ok bar-alias@0 Requires bar-alias-template-requires.device
390 check_ko bar-alias@0 Requires yup-template-requires.device
391 check_ko bar-alias@0 Requires yup-0-requires.device
392
393 echo '*** bar@1 is aliased by bar-alias@1 ***'
394 systemctl show -p Names,Requires bar@1
395 systemctl show -p Names,Requires bar-alias@1
396 check_ok bar@1 Names bar@1
397 check_ok bar@1 Names bar-alias@1
398
399 check_ok bar@1 After bar-template-after.device
400
401 check_ok bar@1 Requires bar-1-requires.device
402 check_ok bar@1 Requires bar-alias-1-requires.device
403 check_ok bar@1 Requires bar-template-requires.device
404 # See https://github.com/systemd/systemd/pull/13119#discussion_r308145418
405 check_ok bar@1 Requires bar-alias-template-requires.device
406 check_ko bar@1 Requires yup-template-requires.device
407 check_ko bar@1 Requires yup-1-requires.device
408
409 check_ok bar-alias@1 After bar-template-after.device
410
411 check_ok bar-alias@1 Requires bar-1-requires.device
412 check_ok bar-alias@1 Requires bar-alias-1-requires.device
413 check_ok bar-alias@1 Requires bar-template-requires.device
414 check_ok bar-alias@1 Requires bar-alias-template-requires.device
415 check_ko bar-alias@1 Requires yup-template-requires.device
416 check_ko bar-alias@1 Requires yup-1-requires.device
417
418 echo '*** bar-alias@2 aliases yup@2, bar@2 is independent ***'
419 systemctl show -p Names,Requires bar@2
420 systemctl show -p Names,Requires bar-alias@2
421 check_ok bar@2 Names bar@2
422 check_ko bar@2 Names bar-alias@2
423
424 check_ok bar@2 After bar-template-after.device
425
426 check_ok bar@2 Requires bar-2-requires.device
427 check_ko bar@2 Requires bar-alias-2-requires.device
428 check_ok bar@2 Requires bar-template-requires.device
429 check_ko bar@2 Requires bar-alias-template-requires.device
430 check_ko bar@2 Requires yup-template-requires.device
431 check_ko bar@2 Requires yup-2-requires.device
432
433 check_ko bar-alias@2 After bar-template-after.device
434
435 check_ko bar-alias@2 Requires bar-2-requires.device
436 check_ok bar-alias@2 Requires bar-alias-2-requires.device
437 check_ko bar-alias@2 Requires bar-template-requires.device
438 check_ok bar-alias@2 Requires bar-alias-template-requires.device
439 check_ok bar-alias@2 Requires yup-template-requires.device
440 check_ok bar-alias@2 Requires yup-2-requires.device
441
442 echo '*** bar-alias@3 aliases yup@3, bar@3 is independent ***'
443 systemctl show -p Names,Requires bar@3
444 systemctl show -p Names,Requires bar-alias@3
445 check_ok bar@3 Names bar@3
446 check_ko bar@3 Names bar-alias@3
447
448 check_ok bar@3 After bar-template-after.device
449
450 check_ok bar@3 Requires bar-3-requires.device
451 check_ko bar@3 Requires bar-alias-3-requires.device
452 check_ok bar@3 Requires bar-template-requires.device
453 check_ko bar@3 Requires bar-alias-template-requires.device
454 check_ko bar@3 Requires yup-template-requires.device
455 check_ko bar@3 Requires yup-3-requires.device
456
457 check_ko bar-alias@3 After bar-template-after.device
458
459 check_ko bar-alias@3 Requires bar-3-requires.device
460 check_ok bar-alias@3 Requires bar-alias-3-requires.device
461 check_ko bar-alias@3 Requires bar-template-requires.device
462 check_ok bar-alias@3 Requires bar-alias-template-requires.device
463 check_ok bar-alias@3 Requires yup-template-requires.device
464 check_ok bar-alias@3 Requires yup-3-requires.device
465
466 clear_units foo.service {bar,yup,bar-alias}@{,1,2,3}.service
467 }
468
469 test_alias_dropins () {
470 echo "Testing alias dropins..."
471
472 echo "*** test a wants b1 alias of b"
473 create_services test15-a test15-b
474 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
475 ln -sf ../test15-b1.service /etc/systemd/system/test15-a.service.wants/
476 check_ok test15-a Wants test15-b.service
477 systemctl start test15-a
478 systemctl --quiet is-active test15-b
479 systemctl stop test15-a test15-b
480 rm /etc/systemd/system/test15-b1.service
481 clear_units test15-{a,b}.service
482
483 # Check that dependencies don't vary.
484 echo "*** test 2"
485 create_services test15-a test15-x test15-y
486 mkdir -p /etc/systemd/system/test15-a1.service.wants/
487 ln -sf test15-a.service /etc/systemd/system/test15-a1.service
488 ln -sf ../test15-x.service /etc/systemd/system/test15-a.service.wants/
489 ln -sf ../test15-y.service /etc/systemd/system/test15-a1.service.wants/
490 check_ok test15-a1 Wants test15-x.service # see [1]
491 check_ok test15-a1 Wants test15-y.service
492 systemctl start test15-a
493 check_ok test15-a1 Wants test15-x.service # see [2]
494 check_ok test15-a1 Wants test15-y.service
495 systemctl stop test15-a test15-x test15-y
496 rm /etc/systemd/system/test15-a1.service
497
498 clear_units test15-{a,x,y}.service
499 }
500
501 test_masked_dropins () {
502 echo "Testing masked dropins..."
503
504 create_services test15-a test15-b
505
506 # 'b' is masked for both deps
507 echo "*** test a wants,requires b is masked"
508 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
509 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service
510 check_ko test15-a Wants test15-b.service
511 check_ko test15-a Requires test15-b.service
512
513 # 'a' wants 'b' and 'b' is masked at a lower level
514 echo "*** test a wants b, mask override"
515 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.wants/test15-b.service
516 ln -sf /dev/null /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
517 check_ok test15-a Wants test15-b.service
518
519 # 'a' wants 'b' and 'b' is masked at a higher level
520 echo "*** test a wants b, mask"
521 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
522 ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
523 check_ko test15-a Wants test15-b.service
524
525 # 'a' is masked but has an override config file
526 echo "*** test a is masked but has an override"
527 create_services test15-a test15-b
528 ln -sf /dev/null /etc/systemd/system/test15-a.service
529 cat >/usr/lib/systemd/system/test15-a.service.d/override.conf <<EOF
530 [Unit]
531 After=test15-b.service
532 EOF
533 check_ok test15-a UnitFileState masked
534
535 # 'b1' is an alias for 'b': masking 'b' dep should not influence 'b1' dep
536 echo "*** test a wants b, b1, and one is masked"
537 create_services test15-a test15-b
538 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
539 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
540 ln -sf ../test15-b1.service /usr/lib/systemd/system/test15-a.service.wants/test15-b1.service
541 systemctl cat test15-a
542 systemctl show -p Wants,Requires test15-a
543 systemctl cat test15-b1
544 systemctl show -p Wants,Requires test15-b1
545 check_ok test15-a Wants test15-b.service
546 check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units
547 rm /etc/systemd/system/test15-b1.service
548
549 # 'b1' is an alias for 'b': masking 'b1' should not influence 'b' dep
550 echo "*** test a wants b, alias dep is masked"
551 create_services test15-a test15-b
552 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
553 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b1.service
554 ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
555 check_ok test15-a Wants test15-b.service
556 check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units
557 rm /etc/systemd/system/test15-b1.service
558
559 # 'a' has Wants=b.service but also has a masking
560 # dropin 'b': 'b' should still be pulled in.
561 echo "*** test a wants b both ways"
562 create_services test15-a test15-b
563 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
564 cat >/usr/lib/systemd/system/test15-a.service.d/wants-b.conf<<EOF
565 [Unit]
566 Wants=test15-b.service
567 EOF
568 check_ok test15-a Wants test15-b.service
569
570 # mask a dropin that points to an nonexistent unit.
571 echo "*** test a wants nonexistent is masked"
572 create_services test15-a
573 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/nonexistent.service
574 ln -sf ../nonexistent.service /usr/lib/systemd/system/test15-a.service.requires/
575 check_ko test15-a Requires nonexistent.service
576
577 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
578 # masked at a higher level.
579 echo "*** test a wants b is masked"
580 create_services test15-a test15-b test15-c
581 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
582 ln -sf ../test15-b.service /run/systemd/system/test15-c.service.requires/
583 ln -sf /dev/null /etc/systemd/system/test15-c.service.requires/test15-b.service
584 systemctl start test15-a
585 check_ko test15-c Requires test15-b.service
586 systemctl stop test15-a test15-b
587
588 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
589 # masked at a lower level.
590 echo "*** test a requires b is masked"
591 create_services test15-a test15-b test15-c
592 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
593 ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/
594 ln -sf /dev/null /run/systemd/system/test15-c.service.requires/test15-b.service
595 systemctl start test15-a
596 check_ok test15-c Requires test15-b.service
597 systemctl stop test15-a test15-b
598
599 # 'a' requires 2 aliases of 'b' and one of them is a mask.
600 echo "*** test a requires alias of b, other alias masked"
601 create_services test15-a test15-b
602 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
603 ln -sf test15-b.service /etc/systemd/system/test15-b2.service
604 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b1.service
605 ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/
606 ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/
607 check_ok test15-a Requires test15-b
608
609 # Same as above but now 'b' is masked.
610 echo "*** test a requires alias of b, b dep masked"
611 create_services test15-a test15-b
612 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
613 ln -sf test15-b.service /etc/systemd/system/test15-b2.service
614 ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/
615 ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/
616 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service
617 check_ok test15-a Requires test15-b
618
619 clear_units test15-{a,b}.service
620 }
621
622 test_invalid_dropins () {
623 echo "Testing invalid dropins..."
624 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
625 systemctl cat nonexistent@.service || true
626 create_services a
627 systemctl daemon-reload
628 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
629 systemctl cat a@.service || true
630 systemctl stop a
631 clear_units a.service
632 return 0
633 }
634
635 test_symlink_dropin_directory () {
636 # For issue #21920.
637 echo "Testing symlink drop-in directory..."
638 create_services test15-a
639 rmdir /{etc,run,usr/lib}/systemd/system/test15-a.service.d
640 mkdir -p /tmp/testsuite-15-test15-a-dropin-directory
641 ln -s /tmp/testsuite-15-test15-a-dropin-directory /etc/systemd/system/test15-a.service.d
642 cat >/tmp/testsuite-15-test15-a-dropin-directory/override.conf <<EOF
643 [Unit]
644 Description=hogehoge
645 EOF
646 ln -s /tmp/testsuite-15-test15-a-dropin-directory-nonexistent /run/systemd/system/test15-a.service.d
647 touch /tmp/testsuite-15-test15-a-dropin-directory-regular
648 ln -s /tmp/testsuite-15-test15-a-dropin-directory-regular /usr/lib/systemd/system/test15-a.service.d
649 check_ok test15-a Description hogehoge
650
651 clear_units test15-a.service
652 }
653
654 test_basic_dropins
655 test_linked_units
656 test_template_alias
657 test_hierarchical_service_dropins
658 test_hierarchical_slice_dropins
659 test_transient_service_dropins
660 test_template_dropins
661 test_alias_dropins
662 test_masked_dropins
663 test_invalid_dropins
664 test_symlink_dropin_directory
665
666 touch /testok