6 systemctl stop
$1.service
2>/dev
/null ||
:
7 rm -f /{etc
,run
,usr
/lib
}/systemd
/system
/$1.service
8 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/$1.service.d
9 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/$1.service.
{wants
,requires
}
10 if [[ $1 == *@
]]; then
11 systemctl stop
$1*.service
2>/dev
/null ||
:
12 rm -f /{etc
,run
,usr
/lib
}/systemd
/system
/$1*.service
13 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/$1*.service.d
14 rm -fr /{etc
,run
,usr
/lib
}/systemd
/system
/$1*.service.
{wants
,requires
}
22 systemctl daemon-reload
28 cat >/etc
/systemd
/system
/$1.service
<<EOF
33 ExecStart=/bin/sleep 100000
35 mkdir
-p /{etc
,run
,usr
/lib
}/systemd
/system
/$1.service.d
36 mkdir
-p /etc
/systemd
/system
/$1.service.
{wants
,requires
}
37 mkdir
-p /run
/systemd
/system
/$1.service.
{wants
,requires
}
38 mkdir
-p /usr
/lib
/systemd
/system
/$1.service.
{wants
,requires
}
48 [ $# -eq 3 ] ||
return
50 x
="$(systemctl show --value -p $2 $1)"
61 test_basic_dropins
() {
62 echo "Testing basic dropins..."
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
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
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
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
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
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
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
117 ExecCondition=/bin/echo %n
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
124 clear_services test15-a test15-b test15-c
127 test_hierarchical_dropins
() {
128 echo "Testing hierarchical dropins..."
129 echo "*** test service.d/ top level drop-in"
130 create_services a-b-c
131 check_ko a-b-c ExecCondition
"/bin/echo service.d"
132 check_ko a-b-c ExecCondition
"/bin/echo a-.service.d"
133 check_ko a-b-c ExecCondition
"/bin/echo a-b-.service.d"
134 check_ko a-b-c ExecCondition
"/bin/echo a-b-c.service.d"
136 for dropin
in service.d a-.service.d a-b-.service.d a-b-c.service.d
; do
137 mkdir
-p /usr
/lib
/systemd
/system
/$dropin
140 ExecCondition=/bin/echo $dropin
141 " > /usr
/lib
/systemd
/system
/$dropin/override.conf
142 systemctl daemon-reload
143 check_ok a-b-c ExecCondition
"/bin/echo $dropin"
145 for dropin
in service.d a-.service.d a-b-.service.d a-b-c.service.d
; do
146 rm -rf /usr
/lib
/systemd
/system
/$dropin
152 test_template_dropins
() {
153 echo "Testing template dropins..."
155 create_services foo bar@ yup@
157 # Declare some deps to check if the body was loaded
158 cat >>/etc
/systemd
/system
/bar@.service
<<EOF
160 After=bar-template-after.device
163 cat >>/etc
/systemd
/system
/yup@.service
<<EOF
165 After=yup-template-after.device
168 ln -s /etc
/systemd
/system
/bar@.service
/etc
/systemd
/system
/foo.service.wants
/bar@
1.service
169 check_ok foo Wants bar@
1.service
171 echo "*** test bar-alias@.service→bar@.service, but instance symlinks point to yup@.service ***"
172 ln -s bar@.service
/etc
/systemd
/system
/bar-alias@.service
173 ln -s bar@
1.service
/etc
/systemd
/system
/bar-alias@
1.service
174 ln -s yup@.service
/etc
/systemd
/system
/bar-alias@
2.service
175 ln -s yup@
3.service
/etc
/systemd
/system
/bar-alias@
3.service
177 # create some dropin deps
178 mkdir
-p /etc
/systemd
/system
/bar@
{,0,1,2,3}.service.requires
/
179 mkdir
-p /etc
/systemd
/system
/yup@
{,0,1,2,3}.service.requires
/
180 mkdir
-p /etc
/systemd
/system
/bar-alias@
{,0,1,2,3}.service.requires
/
182 ln -s ..
/bar-template-requires.device
/etc
/systemd
/system
/bar@.service.requires
/
183 ln -s ..
/bar-0-requires.device
/etc
/systemd
/system
/bar@
0.service.requires
/
184 ln -s ..
/bar-1-requires.device
/etc
/systemd
/system
/bar@
1.service.requires
/
185 ln -s ..
/bar-2-requires.device
/etc
/systemd
/system
/bar@
2.service.requires
/
186 ln -s ..
/bar-3-requires.device
/etc
/systemd
/system
/bar@
3.service.requires
/
188 ln -s ..
/yup-template-requires.device
/etc
/systemd
/system
/yup@.service.requires
/
189 ln -s ..
/yup-0-requires.device
/etc
/systemd
/system
/yup@
0.service.requires
/
190 ln -s ..
/yup-1-requires.device
/etc
/systemd
/system
/yup@
1.service.requires
/
191 ln -s ..
/yup-2-requires.device
/etc
/systemd
/system
/yup@
2.service.requires
/
192 ln -s ..
/yup-3-requires.device
/etc
/systemd
/system
/yup@
3.service.requires
/
194 ln -s ..
/bar-alias-template-requires.device
/etc
/systemd
/system
/bar-alias@.service.requires
/
195 ln -s ..
/bar-alias-0-requires.device
/etc
/systemd
/system
/bar-alias@
0.service.requires
/
196 ln -s ..
/bar-alias-1-requires.device
/etc
/systemd
/system
/bar-alias@
1.service.requires
/
197 ln -s ..
/bar-alias-2-requires.device
/etc
/systemd
/system
/bar-alias@
2.service.requires
/
198 ln -s ..
/bar-alias-3-requires.device
/etc
/systemd
/system
/bar-alias@
3.service.requires
/
200 systemctl daemon-reload
202 echo '*** bar@0 is aliased by bar-alias@0 ***'
203 systemctl show
-p Names
,Requires bar@
0
204 systemctl show
-p Names
,Requires bar-alias@
0
205 check_ok bar@
0 Names bar@
0
206 check_ok bar@
0 Names bar-alias@
0
208 check_ok bar@
0 After bar-template-after.device
210 check_ok bar@
0 Requires bar-0-requires.device
211 check_ok bar@
0 Requires bar-alias-0-requires.device
212 check_ok bar@
0 Requires bar-template-requires.device
213 check_ok bar@
0 Requires bar-alias-template-requires.device
214 check_ko bar@
0 Requires yup-template-requires.device
216 check_ok bar-alias@
0 After bar-template-after.device
218 check_ok bar-alias@
0 Requires bar-0-requires.device
219 check_ok bar-alias@
0 Requires bar-alias-0-requires.device
220 check_ok bar-alias@
0 Requires bar-template-requires.device
221 check_ok bar-alias@
0 Requires bar-alias-template-requires.device
222 check_ko bar-alias@
0 Requires yup-template-requires.device
223 check_ko bar-alias@
0 Requires yup-0-requires.device
225 echo '*** bar@1 is aliased by bar-alias@1 ***'
226 systemctl show
-p Names
,Requires bar@
1
227 systemctl show
-p Names
,Requires bar-alias@
1
228 check_ok bar@
1 Names bar@
1
229 check_ok bar@
1 Names bar-alias@
1
231 check_ok bar@
1 After bar-template-after.device
233 check_ok bar@
1 Requires bar-1-requires.device
234 check_ok bar@
1 Requires bar-alias-1-requires.device
235 check_ok bar@
1 Requires bar-template-requires.device
236 # See https://github.com/systemd/systemd/pull/13119#discussion_r308145418
237 check_ok bar@
1 Requires bar-alias-template-requires.device
238 check_ko bar@
1 Requires yup-template-requires.device
239 check_ko bar@
1 Requires yup-1-requires.device
241 check_ok bar-alias@
1 After bar-template-after.device
243 check_ok bar-alias@
1 Requires bar-1-requires.device
244 check_ok bar-alias@
1 Requires bar-alias-1-requires.device
245 check_ok bar-alias@
1 Requires bar-template-requires.device
246 check_ok bar-alias@
1 Requires bar-alias-template-requires.device
247 check_ko bar-alias@
1 Requires yup-template-requires.device
248 check_ko bar-alias@
1 Requires yup-1-requires.device
250 echo '*** bar-alias@2 aliases yup@2, bar@2 is independent ***'
251 systemctl show
-p Names
,Requires bar@
2
252 systemctl show
-p Names
,Requires bar-alias@
2
253 check_ok bar@
2 Names bar@
2
254 check_ko bar@
2 Names bar-alias@
2
256 check_ok bar@
2 After bar-template-after.device
258 check_ok bar@
2 Requires bar-2-requires.device
259 check_ko bar@
2 Requires bar-alias-2-requires.device
260 check_ok bar@
2 Requires bar-template-requires.device
261 check_ko bar@
2 Requires bar-alias-template-requires.device
262 check_ko bar@
2 Requires yup-template-requires.device
263 check_ko bar@
2 Requires yup-2-requires.device
265 check_ko bar-alias@
2 After bar-template-after.device
267 check_ko bar-alias@
2 Requires bar-2-requires.device
268 check_ok bar-alias@
2 Requires bar-alias-2-requires.device
269 check_ko bar-alias@
2 Requires bar-template-requires.device
270 check_ok bar-alias@
2 Requires bar-alias-template-requires.device
271 check_ok bar-alias@
2 Requires yup-template-requires.device
272 check_ok bar-alias@
2 Requires yup-2-requires.device
274 echo '*** bar-alias@3 aliases yup@3, bar@3 is independent ***'
275 systemctl show
-p Names
,Requires bar@
3
276 systemctl show
-p Names
,Requires bar-alias@
3
277 check_ok bar@
3 Names bar@
3
278 check_ko bar@
3 Names bar-alias@
3
280 check_ok bar@
3 After bar-template-after.device
282 check_ok bar@
3 Requires bar-3-requires.device
283 check_ko bar@
3 Requires bar-alias-3-requires.device
284 check_ok bar@
3 Requires bar-template-requires.device
285 check_ko bar@
3 Requires bar-alias-template-requires.device
286 check_ko bar@
3 Requires yup-template-requires.device
287 check_ko bar@
3 Requires yup-3-requires.device
289 check_ko bar-alias@
3 After bar-template-after.device
291 check_ko bar-alias@
3 Requires bar-3-requires.device
292 check_ok bar-alias@
3 Requires bar-alias-3-requires.device
293 check_ko bar-alias@
3 Requires bar-template-requires.device
294 check_ok bar-alias@
3 Requires bar-alias-template-requires.device
295 check_ok bar-alias@
3 Requires yup-template-requires.device
296 check_ok bar-alias@
3 Requires yup-3-requires.device
298 clear_services foo
{bar
,yup
,bar-alias
}@
{,1,2,3}
301 test_alias_dropins
() {
302 echo "Testing alias dropins..."
304 echo "*** test a wants b1 alias of b"
305 create_services test15-a test15-b
306 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
307 ln -sf ..
/test15-b1.service
/etc
/systemd
/system
/test15-a.service.wants
/
308 check_ok test15-a Wants test15-b.service
309 systemctl start test15-a
310 systemctl
--quiet is-active test15-b
311 systemctl stop test15-a test15-b
312 rm /etc
/systemd
/system
/test15-b1.service
313 clear_services test15-a test15-b
315 # Check that dependencies don't vary.
317 create_services test15-a test15-x test15-y
318 mkdir
-p /etc
/systemd
/system
/test15-a1.service.wants
/
319 ln -sf test15-a.service
/etc
/systemd
/system
/test15-a1.service
320 ln -sf ..
/test15-x.service
/etc
/systemd
/system
/test15-a.service.wants
/
321 ln -sf ..
/test15-y.service
/etc
/systemd
/system
/test15-a1.service.wants
/
322 check_ok test15-a1 Wants test15-x.service
# see [1]
323 check_ok test15-a1 Wants test15-y.service
324 systemctl start test15-a
325 check_ok test15-a1 Wants test15-x.service
# see [2]
326 check_ok test15-a1 Wants test15-y.service
327 systemctl stop test15-a test15-x test15-y
328 rm /etc
/systemd
/system
/test15-a1.service
330 clear_services test15-a test15-x test15-y
333 test_masked_dropins
() {
334 echo "Testing masked dropins..."
336 create_services test15-a test15-b
338 # 'b' is masked for both deps
339 echo "*** test a wants,requires b is masked"
340 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
341 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b.service
342 check_ko test15-a Wants test15-b.service
343 check_ko test15-a Requires test15-b.service
345 # 'a' wants 'b' and 'b' is masked at a lower level
346 echo "*** test a wants b, mask override"
347 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
348 ln -sf /dev
/null
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
349 check_ok test15-a Wants test15-b.service
351 # 'a' wants 'b' and 'b' is masked at a higher level
352 echo "*** test a wants b, mask"
353 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
354 ln -sf ..
/test15-b.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
355 check_ko test15-a Wants test15-b.service
357 # 'a' is masked but has an override config file
358 echo "*** test a is masked but has an override"
359 create_services test15-a test15-b
360 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service
361 cat >/usr
/lib
/systemd
/system
/test15-a.service.d
/override.conf
<<EOF
363 After=test15-b.service
365 check_ok test15-a UnitFileState masked
367 # 'b1' is an alias for 'b': masking 'b' dep should not influence 'b1' dep
368 echo "*** test a wants b, b1, and one is masked"
369 create_services test15-a test15-b
370 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
371 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
372 ln -sf ..
/test15-b1.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b1.service
373 systemctl
cat test15-a
374 systemctl show
-p Wants
,Requires test15-a
375 systemctl
cat test15-b1
376 systemctl show
-p Wants
,Requires test15-b1
377 check_ok test15-a Wants test15-b.service
378 check_ko test15-a Wants test15-b1.service
# the alias does not show up in the list of units
379 rm /etc
/systemd
/system
/test15-b1.service
381 # 'b1' is an alias for 'b': masking 'b1' should not influence 'b' dep
382 echo "*** test a wants b, alias dep is masked"
383 create_services test15-a test15-b
384 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
385 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b1.service
386 ln -sf ..
/test15-b.service
/usr
/lib
/systemd
/system
/test15-a.service.wants
/test15-b.service
387 check_ok test15-a Wants test15-b.service
388 check_ko test15-a Wants test15-b1.service
# the alias does not show up in the list of units
389 rm /etc
/systemd
/system
/test15-b1.service
391 # 'a' has Wants=b.service but also has a masking
392 # dropin 'b': 'b' should still be pulled in.
393 echo "*** test a wants b both ways"
394 create_services test15-a test15-b
395 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.wants
/test15-b.service
396 cat >/usr
/lib
/systemd
/system
/test15-a.service.d
/wants-b.conf
<<EOF
398 Wants=test15-b.service
400 check_ok test15-a Wants test15-b.service
402 # mask a dropin that points to an nonexistent unit.
403 echo "*** test a wants nonexistent is masked"
404 create_services test15-a
405 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/nonexistent.service
406 ln -sf ..
/nonexistent.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
407 check_ko test15-a Requires nonexistent.service
409 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
410 # masked at a higher level.
411 echo "*** test a wants b is masked"
412 create_services test15-a test15-b test15-c
413 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
414 ln -sf ..
/test15-b.service
/run
/systemd
/system
/test15-c.service.requires
/
415 ln -sf /dev
/null
/etc
/systemd
/system
/test15-c.service.requires
/test15-b.service
416 systemctl start test15-a
417 check_ko test15-c Requires test15-b.service
418 systemctl stop test15-a test15-b
420 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
421 # masked at a lower level.
422 echo "*** test a requires b is masked"
423 create_services test15-a test15-b test15-c
424 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-a.service.requires
/
425 ln -sf ..
/test15-b.service
/etc
/systemd
/system
/test15-c.service.requires
/
426 ln -sf /dev
/null
/run
/systemd
/system
/test15-c.service.requires
/test15-b.service
427 systemctl start test15-a
428 check_ok test15-c Requires test15-b.service
429 systemctl stop test15-a test15-b
431 # 'a' requires 2 aliases of 'b' and one of them is a mask.
432 echo "*** test a requires alias of b, other alias masked"
433 create_services test15-a test15-b
434 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
435 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b2.service
436 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b1.service
437 ln -sf ..
/test15-b1.service
/run
/systemd
/system
/test15-a.service.requires
/
438 ln -sf ..
/test15-b2.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
439 check_ok test15-a Requires test15-b
441 # Same as above but now 'b' is masked.
442 echo "*** test a requires alias of b, b dep masked"
443 create_services test15-a test15-b
444 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b1.service
445 ln -sf test15-b.service
/etc
/systemd
/system
/test15-b2.service
446 ln -sf ..
/test15-b1.service
/run
/systemd
/system
/test15-a.service.requires
/
447 ln -sf ..
/test15-b2.service
/usr
/lib
/systemd
/system
/test15-a.service.requires
/
448 ln -sf /dev
/null
/etc
/systemd
/system
/test15-a.service.requires
/test15-b.service
449 check_ok test15-a Requires test15-b
451 clear_services test15-a test15-b
454 test_invalid_dropins
() {
455 echo "Testing invalid dropins..."
456 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
457 systemctl
cat nonexistent@.service || true
459 systemctl daemon-reload
460 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
461 systemctl
cat a@.service || true
468 test_hierarchical_dropins
469 test_template_dropins