]>
Commit | Line | Data |
---|---|---|
8b3d4ff0 MB |
1 | #!/bin/bash |
2 | set -eux | |
3 | set -o pipefail | |
2897b343 MP |
4 | |
5 | _clear_service () { | |
8b3d4ff0 MB |
6 | local SERVICE_NAME="${1:?_clear_service: missing argument}" |
7 | systemctl stop "$SERVICE_NAME.service" 2>/dev/null || : | |
8 | rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service | |
9 | rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d | |
10 | rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{wants,requires} | |
11 | if [[ $SERVICE_NAME == *@ ]]; then | |
12 | systemctl stop "$SERVICE_NAME"*.service 2>/dev/null || : | |
13 | rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service | |
14 | rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.d | |
15 | rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.{wants,requires} | |
a10f5d05 | 16 | fi |
2897b343 MP |
17 | } |
18 | ||
19 | clear_services () { | |
8b3d4ff0 MB |
20 | for u in "$@"; do |
21 | _clear_service "$u" | |
f2dec872 BR |
22 | done |
23 | systemctl daemon-reload | |
2897b343 MP |
24 | } |
25 | ||
26 | create_service () { | |
8b3d4ff0 MB |
27 | local SERVICE_NAME="${1:?create_service: missing argument}" |
28 | clear_services "$SERVICE_NAME" | |
2897b343 | 29 | |
8b3d4ff0 | 30 | cat >/etc/systemd/system/"$SERVICE_NAME".service <<EOF |
2897b343 | 31 | [Unit] |
8b3d4ff0 | 32 | Description=$SERVICE_NAME unit |
2897b343 MP |
33 | |
34 | [Service] | |
8b3d4ff0 | 35 | ExecStart=sleep 100000 |
2897b343 | 36 | EOF |
8b3d4ff0 | 37 | mkdir -p /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{d,wants,requires} |
2897b343 MP |
38 | } |
39 | ||
40 | create_services () { | |
8b3d4ff0 MB |
41 | for u in "$@"; do |
42 | create_service "$u" | |
f2dec872 | 43 | done |
2897b343 MP |
44 | } |
45 | ||
46 | check_ok () { | |
8b3d4ff0 | 47 | x="$(systemctl show --value -p "${2:?}" "${1:?}")" |
f2dec872 | 48 | case "$x" in |
8b3d4ff0 MB |
49 | *${3:?}*) return 0 ;; |
50 | *) return 1 ;; | |
f2dec872 | 51 | esac |
2897b343 MP |
52 | } |
53 | ||
54 | check_ko () { | |
f2dec872 | 55 | ! check_ok "$@" |
2897b343 MP |
56 | } |
57 | ||
58 | test_basic_dropins () { | |
f2dec872 BR |
59 | echo "Testing basic dropins..." |
60 | ||
61 | echo "*** test a wants b wants c" | |
a10f5d05 MB |
62 | create_services test15-a test15-b test15-c |
63 | ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/ | |
64 | ln -s ../test15-c.service /etc/systemd/system/test15-b.service.wants/ | |
65 | check_ok test15-a Wants test15-b.service | |
66 | check_ok test15-b Wants test15-c.service | |
f2dec872 BR |
67 | |
68 | echo "*** test a wants,requires b" | |
a10f5d05 MB |
69 | create_services test15-a test15-b test15-c |
70 | ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/ | |
71 | ln -s ../test15-b.service /etc/systemd/system/test15-a.service.requires/ | |
72 | check_ok test15-a Wants test15-b.service | |
73 | check_ok test15-a Requires test15-b.service | |
f2dec872 BR |
74 | |
75 | echo "*** test a wants nonexistent" | |
a10f5d05 MB |
76 | create_service test15-a |
77 | ln -s ../nonexistent.service /etc/systemd/system/test15-a.service.wants/ | |
78 | check_ok test15-a Wants nonexistent.service | |
79 | systemctl start test15-a | |
80 | systemctl stop test15-a | |
f2dec872 BR |
81 | |
82 | echo "*** test a requires nonexistent" | |
a10f5d05 | 83 | ln -sf ../nonexistent.service /etc/systemd/system/test15-a.service.requires/ |
f2dec872 | 84 | systemctl daemon-reload |
a10f5d05 | 85 | check_ok test15-a Requires nonexistent.service |
f2dec872 BR |
86 | |
87 | # 'b' is already loaded when 'c' pulls it in via a dropin. | |
88 | echo "*** test a,c require b" | |
a10f5d05 MB |
89 | create_services test15-a test15-b test15-c |
90 | ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/ | |
91 | ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/ | |
92 | systemctl start test15-a | |
93 | check_ok test15-c Requires test15-b.service | |
94 | systemctl stop test15-a test15-b | |
f2dec872 BR |
95 | |
96 | # 'b' is already loaded when 'c' pulls it in via an alias dropin. | |
97 | echo "*** test a wants alias" | |
a10f5d05 MB |
98 | create_services test15-a test15-b test15-c |
99 | ln -sf test15-c.service /etc/systemd/system/test15-c1.service | |
100 | ln -sf ../test15-c.service /etc/systemd/system/test15-a.service.wants/ | |
101 | ln -sf ../test15-c1.service /etc/systemd/system/test15-b.service.wants/ | |
102 | systemctl start test15-a | |
103 | check_ok test15-a Wants test15-c.service | |
104 | check_ok test15-b Wants test15-c.service | |
105 | systemctl stop test15-a test15-c | |
f2dec872 | 106 | |
e1f67bc7 | 107 | echo "*** test service.d/ top level drop-in" |
a10f5d05 MB |
108 | create_services test15-a test15-b |
109 | check_ko test15-a ExecCondition "/bin/echo a" | |
110 | check_ko test15-b ExecCondition "/bin/echo b" | |
e1f67bc7 MB |
111 | mkdir -p /usr/lib/systemd/system/service.d |
112 | cat >/usr/lib/systemd/system/service.d/override.conf <<EOF | |
113 | [Service] | |
114 | ExecCondition=/bin/echo %n | |
115 | EOF | |
a10f5d05 MB |
116 | systemctl daemon-reload |
117 | check_ok test15-a ExecCondition "/bin/echo test15-a" | |
118 | check_ok test15-b ExecCondition "/bin/echo test15-b" | |
e1f67bc7 MB |
119 | rm -rf /usr/lib/systemd/system/service.d |
120 | ||
8b3d4ff0 | 121 | clear_services test15-a test15-b test15-c test15-c1 |
2897b343 MP |
122 | } |
123 | ||
3a6ce677 BR |
124 | test_linked_units () { |
125 | echo "Testing linked units..." | |
126 | echo "*** test linked unit (same basename)" | |
127 | ||
128 | create_service test15-a | |
129 | mv /etc/systemd/system/test15-a.service / | |
130 | ln -s /test15-a.service /etc/systemd/system/ | |
131 | ln -s test15-a.service /etc/systemd/system/test15-b.service | |
132 | ||
133 | check_ok test15-a Names test15-a.service | |
134 | check_ok test15-a Names test15-b.service | |
135 | ||
136 | echo "*** test linked unit (cross basename)" | |
137 | ||
138 | mv /test15-a.service /test15-a@.scope | |
139 | ln -fs /test15-a@.scope /etc/systemd/system/test15-a.service | |
140 | systemctl daemon-reload | |
141 | ||
142 | check_ok test15-a Names test15-a.service | |
143 | check_ok test15-a Names test15-b.service | |
144 | check_ko test15-a Names test15-a@ # test15-a@.scope is the symlink target. | |
145 | # Make sure it is completely ignored. | |
146 | ||
147 | rm /test15-a@.scope | |
148 | clear_services test15-a test15-b | |
149 | } | |
150 | ||
8b3d4ff0 MB |
151 | test_template_alias() { |
152 | echo "Testing instance alias..." | |
153 | echo "*** forward" | |
154 | ||
155 | create_service test15-a@ | |
156 | ln -s test15-a@inst.service /etc/systemd/system/test15-b@inst.service # alias | |
157 | ||
158 | check_ok test15-a@inst Names test15-a@inst.service | |
159 | check_ok test15-a@inst Names test15-b@inst.service | |
160 | ||
161 | check_ok test15-a@other Names test15-a@other.service | |
162 | check_ko test15-a@other Names test15-b@other.service | |
163 | ||
164 | echo "*** reverse" | |
165 | ||
166 | systemctl daemon-reload | |
167 | ||
168 | check_ok test15-b@inst Names test15-a@inst.service | |
169 | check_ok test15-b@inst Names test15-b@inst.service | |
170 | ||
171 | check_ko test15-b@other Names test15-a@other.service | |
172 | check_ok test15-b@other Names test15-b@other.service | |
173 | ||
174 | clear_services test15-a@ test15-b@ | |
175 | } | |
176 | ||
46cdbd49 BR |
177 | test_hierarchical_dropins () { |
178 | echo "Testing hierarchical dropins..." | |
179 | echo "*** test service.d/ top level drop-in" | |
180 | create_services a-b-c | |
181 | check_ko a-b-c ExecCondition "/bin/echo service.d" | |
182 | check_ko a-b-c ExecCondition "/bin/echo a-.service.d" | |
183 | check_ko a-b-c ExecCondition "/bin/echo a-b-.service.d" | |
184 | check_ko a-b-c ExecCondition "/bin/echo a-b-c.service.d" | |
185 | ||
186 | for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do | |
187 | mkdir -p /usr/lib/systemd/system/$dropin | |
188 | echo " | |
189 | [Service] | |
190 | ExecCondition=/bin/echo $dropin | |
8b3d4ff0 | 191 | " >/usr/lib/systemd/system/$dropin/override.conf |
a10f5d05 | 192 | systemctl daemon-reload |
46cdbd49 BR |
193 | check_ok a-b-c ExecCondition "/bin/echo $dropin" |
194 | done | |
195 | for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do | |
196 | rm -rf /usr/lib/systemd/system/$dropin | |
197 | done | |
198 | ||
199 | clear_services a-b-c | |
200 | } | |
201 | ||
2897b343 | 202 | test_template_dropins () { |
f2dec872 BR |
203 | echo "Testing template dropins..." |
204 | ||
205 | create_services foo bar@ yup@ | |
2897b343 | 206 | |
f2dec872 BR |
207 | # Declare some deps to check if the body was loaded |
208 | cat >>/etc/systemd/system/bar@.service <<EOF | |
209 | [Unit] | |
210 | After=bar-template-after.device | |
211 | EOF | |
2897b343 | 212 | |
f2dec872 BR |
213 | cat >>/etc/systemd/system/yup@.service <<EOF |
214 | [Unit] | |
215 | After=yup-template-after.device | |
216 | EOF | |
2897b343 | 217 | |
f2dec872 BR |
218 | ln -s /etc/systemd/system/bar@.service /etc/systemd/system/foo.service.wants/bar@1.service |
219 | check_ok foo Wants bar@1.service | |
220 | ||
221 | echo "*** test bar-alias@.service→bar@.service, but instance symlinks point to yup@.service ***" | |
222 | ln -s bar@.service /etc/systemd/system/bar-alias@.service | |
223 | ln -s bar@1.service /etc/systemd/system/bar-alias@1.service | |
224 | ln -s yup@.service /etc/systemd/system/bar-alias@2.service | |
225 | ln -s yup@3.service /etc/systemd/system/bar-alias@3.service | |
226 | ||
227 | # create some dropin deps | |
228 | mkdir -p /etc/systemd/system/bar@{,0,1,2,3}.service.requires/ | |
229 | mkdir -p /etc/systemd/system/yup@{,0,1,2,3}.service.requires/ | |
230 | mkdir -p /etc/systemd/system/bar-alias@{,0,1,2,3}.service.requires/ | |
231 | ||
232 | ln -s ../bar-template-requires.device /etc/systemd/system/bar@.service.requires/ | |
233 | ln -s ../bar-0-requires.device /etc/systemd/system/bar@0.service.requires/ | |
234 | ln -s ../bar-1-requires.device /etc/systemd/system/bar@1.service.requires/ | |
235 | ln -s ../bar-2-requires.device /etc/systemd/system/bar@2.service.requires/ | |
236 | ln -s ../bar-3-requires.device /etc/systemd/system/bar@3.service.requires/ | |
237 | ||
238 | ln -s ../yup-template-requires.device /etc/systemd/system/yup@.service.requires/ | |
239 | ln -s ../yup-0-requires.device /etc/systemd/system/yup@0.service.requires/ | |
240 | ln -s ../yup-1-requires.device /etc/systemd/system/yup@1.service.requires/ | |
241 | ln -s ../yup-2-requires.device /etc/systemd/system/yup@2.service.requires/ | |
242 | ln -s ../yup-3-requires.device /etc/systemd/system/yup@3.service.requires/ | |
243 | ||
244 | ln -s ../bar-alias-template-requires.device /etc/systemd/system/bar-alias@.service.requires/ | |
245 | ln -s ../bar-alias-0-requires.device /etc/systemd/system/bar-alias@0.service.requires/ | |
246 | ln -s ../bar-alias-1-requires.device /etc/systemd/system/bar-alias@1.service.requires/ | |
247 | ln -s ../bar-alias-2-requires.device /etc/systemd/system/bar-alias@2.service.requires/ | |
248 | ln -s ../bar-alias-3-requires.device /etc/systemd/system/bar-alias@3.service.requires/ | |
249 | ||
250 | systemctl daemon-reload | |
251 | ||
252 | echo '*** bar@0 is aliased by bar-alias@0 ***' | |
253 | systemctl show -p Names,Requires bar@0 | |
254 | systemctl show -p Names,Requires bar-alias@0 | |
255 | check_ok bar@0 Names bar@0 | |
256 | check_ok bar@0 Names bar-alias@0 | |
257 | ||
258 | check_ok bar@0 After bar-template-after.device | |
259 | ||
260 | check_ok bar@0 Requires bar-0-requires.device | |
261 | check_ok bar@0 Requires bar-alias-0-requires.device | |
262 | check_ok bar@0 Requires bar-template-requires.device | |
263 | check_ok bar@0 Requires bar-alias-template-requires.device | |
264 | check_ko bar@0 Requires yup-template-requires.device | |
265 | ||
266 | check_ok bar-alias@0 After bar-template-after.device | |
267 | ||
268 | check_ok bar-alias@0 Requires bar-0-requires.device | |
269 | check_ok bar-alias@0 Requires bar-alias-0-requires.device | |
270 | check_ok bar-alias@0 Requires bar-template-requires.device | |
271 | check_ok bar-alias@0 Requires bar-alias-template-requires.device | |
272 | check_ko bar-alias@0 Requires yup-template-requires.device | |
273 | check_ko bar-alias@0 Requires yup-0-requires.device | |
274 | ||
275 | echo '*** bar@1 is aliased by bar-alias@1 ***' | |
276 | systemctl show -p Names,Requires bar@1 | |
277 | systemctl show -p Names,Requires bar-alias@1 | |
278 | check_ok bar@1 Names bar@1 | |
279 | check_ok bar@1 Names bar-alias@1 | |
280 | ||
281 | check_ok bar@1 After bar-template-after.device | |
282 | ||
283 | check_ok bar@1 Requires bar-1-requires.device | |
284 | check_ok bar@1 Requires bar-alias-1-requires.device | |
285 | check_ok bar@1 Requires bar-template-requires.device | |
286 | # See https://github.com/systemd/systemd/pull/13119#discussion_r308145418 | |
287 | check_ok bar@1 Requires bar-alias-template-requires.device | |
288 | check_ko bar@1 Requires yup-template-requires.device | |
289 | check_ko bar@1 Requires yup-1-requires.device | |
290 | ||
291 | check_ok bar-alias@1 After bar-template-after.device | |
292 | ||
293 | check_ok bar-alias@1 Requires bar-1-requires.device | |
294 | check_ok bar-alias@1 Requires bar-alias-1-requires.device | |
295 | check_ok bar-alias@1 Requires bar-template-requires.device | |
296 | check_ok bar-alias@1 Requires bar-alias-template-requires.device | |
297 | check_ko bar-alias@1 Requires yup-template-requires.device | |
298 | check_ko bar-alias@1 Requires yup-1-requires.device | |
299 | ||
300 | echo '*** bar-alias@2 aliases yup@2, bar@2 is independent ***' | |
301 | systemctl show -p Names,Requires bar@2 | |
302 | systemctl show -p Names,Requires bar-alias@2 | |
303 | check_ok bar@2 Names bar@2 | |
304 | check_ko bar@2 Names bar-alias@2 | |
305 | ||
306 | check_ok bar@2 After bar-template-after.device | |
307 | ||
308 | check_ok bar@2 Requires bar-2-requires.device | |
309 | check_ko bar@2 Requires bar-alias-2-requires.device | |
310 | check_ok bar@2 Requires bar-template-requires.device | |
311 | check_ko bar@2 Requires bar-alias-template-requires.device | |
312 | check_ko bar@2 Requires yup-template-requires.device | |
313 | check_ko bar@2 Requires yup-2-requires.device | |
314 | ||
315 | check_ko bar-alias@2 After bar-template-after.device | |
316 | ||
317 | check_ko bar-alias@2 Requires bar-2-requires.device | |
318 | check_ok bar-alias@2 Requires bar-alias-2-requires.device | |
319 | check_ko bar-alias@2 Requires bar-template-requires.device | |
320 | check_ok bar-alias@2 Requires bar-alias-template-requires.device | |
321 | check_ok bar-alias@2 Requires yup-template-requires.device | |
322 | check_ok bar-alias@2 Requires yup-2-requires.device | |
323 | ||
324 | echo '*** bar-alias@3 aliases yup@3, bar@3 is independent ***' | |
325 | systemctl show -p Names,Requires bar@3 | |
326 | systemctl show -p Names,Requires bar-alias@3 | |
327 | check_ok bar@3 Names bar@3 | |
328 | check_ko bar@3 Names bar-alias@3 | |
329 | ||
330 | check_ok bar@3 After bar-template-after.device | |
331 | ||
332 | check_ok bar@3 Requires bar-3-requires.device | |
333 | check_ko bar@3 Requires bar-alias-3-requires.device | |
334 | check_ok bar@3 Requires bar-template-requires.device | |
335 | check_ko bar@3 Requires bar-alias-template-requires.device | |
336 | check_ko bar@3 Requires yup-template-requires.device | |
337 | check_ko bar@3 Requires yup-3-requires.device | |
338 | ||
339 | check_ko bar-alias@3 After bar-template-after.device | |
340 | ||
341 | check_ko bar-alias@3 Requires bar-3-requires.device | |
342 | check_ok bar-alias@3 Requires bar-alias-3-requires.device | |
343 | check_ko bar-alias@3 Requires bar-template-requires.device | |
344 | check_ok bar-alias@3 Requires bar-alias-template-requires.device | |
345 | check_ok bar-alias@3 Requires yup-template-requires.device | |
346 | check_ok bar-alias@3 Requires yup-3-requires.device | |
347 | ||
348 | clear_services foo {bar,yup,bar-alias}@{,1,2,3} | |
2897b343 MP |
349 | } |
350 | ||
351 | test_alias_dropins () { | |
f2dec872 BR |
352 | echo "Testing alias dropins..." |
353 | ||
354 | echo "*** test a wants b1 alias of b" | |
a10f5d05 MB |
355 | create_services test15-a test15-b |
356 | ln -sf test15-b.service /etc/systemd/system/test15-b1.service | |
357 | ln -sf ../test15-b1.service /etc/systemd/system/test15-a.service.wants/ | |
358 | check_ok test15-a Wants test15-b.service | |
359 | systemctl start test15-a | |
360 | systemctl --quiet is-active test15-b | |
361 | systemctl stop test15-a test15-b | |
362 | rm /etc/systemd/system/test15-b1.service | |
363 | clear_services test15-a test15-b | |
f2dec872 BR |
364 | |
365 | # Check that dependencies don't vary. | |
366 | echo "*** test 2" | |
a10f5d05 MB |
367 | create_services test15-a test15-x test15-y |
368 | mkdir -p /etc/systemd/system/test15-a1.service.wants/ | |
369 | ln -sf test15-a.service /etc/systemd/system/test15-a1.service | |
370 | ln -sf ../test15-x.service /etc/systemd/system/test15-a.service.wants/ | |
371 | ln -sf ../test15-y.service /etc/systemd/system/test15-a1.service.wants/ | |
372 | check_ok test15-a1 Wants test15-x.service # see [1] | |
373 | check_ok test15-a1 Wants test15-y.service | |
374 | systemctl start test15-a | |
375 | check_ok test15-a1 Wants test15-x.service # see [2] | |
376 | check_ok test15-a1 Wants test15-y.service | |
377 | systemctl stop test15-a test15-x test15-y | |
378 | rm /etc/systemd/system/test15-a1.service | |
379 | ||
380 | clear_services test15-a test15-x test15-y | |
2897b343 MP |
381 | } |
382 | ||
383 | test_masked_dropins () { | |
f2dec872 BR |
384 | echo "Testing masked dropins..." |
385 | ||
a10f5d05 | 386 | create_services test15-a test15-b |
f2dec872 BR |
387 | |
388 | # 'b' is masked for both deps | |
389 | echo "*** test a wants,requires b is masked" | |
a10f5d05 MB |
390 | ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service |
391 | ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service | |
392 | check_ko test15-a Wants test15-b.service | |
393 | check_ko test15-a Requires test15-b.service | |
f2dec872 BR |
394 | |
395 | # 'a' wants 'b' and 'b' is masked at a lower level | |
396 | echo "*** test a wants b, mask override" | |
a10f5d05 MB |
397 | ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.wants/test15-b.service |
398 | ln -sf /dev/null /usr/lib/systemd/system/test15-a.service.wants/test15-b.service | |
399 | check_ok test15-a Wants test15-b.service | |
f2dec872 BR |
400 | |
401 | # 'a' wants 'b' and 'b' is masked at a higher level | |
402 | echo "*** test a wants b, mask" | |
a10f5d05 MB |
403 | ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service |
404 | ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service | |
405 | check_ko test15-a Wants test15-b.service | |
f2dec872 BR |
406 | |
407 | # 'a' is masked but has an override config file | |
408 | echo "*** test a is masked but has an override" | |
a10f5d05 MB |
409 | create_services test15-a test15-b |
410 | ln -sf /dev/null /etc/systemd/system/test15-a.service | |
411 | cat >/usr/lib/systemd/system/test15-a.service.d/override.conf <<EOF | |
98393f85 | 412 | [Unit] |
a10f5d05 | 413 | After=test15-b.service |
98393f85 | 414 | EOF |
a10f5d05 | 415 | check_ok test15-a UnitFileState masked |
f2dec872 BR |
416 | |
417 | # 'b1' is an alias for 'b': masking 'b' dep should not influence 'b1' dep | |
418 | echo "*** test a wants b, b1, and one is masked" | |
a10f5d05 MB |
419 | create_services test15-a test15-b |
420 | ln -sf test15-b.service /etc/systemd/system/test15-b1.service | |
421 | ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service | |
422 | ln -sf ../test15-b1.service /usr/lib/systemd/system/test15-a.service.wants/test15-b1.service | |
423 | systemctl cat test15-a | |
424 | systemctl show -p Wants,Requires test15-a | |
425 | systemctl cat test15-b1 | |
426 | systemctl show -p Wants,Requires test15-b1 | |
427 | check_ok test15-a Wants test15-b.service | |
428 | check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units | |
429 | rm /etc/systemd/system/test15-b1.service | |
f2dec872 BR |
430 | |
431 | # 'b1' is an alias for 'b': masking 'b1' should not influence 'b' dep | |
432 | echo "*** test a wants b, alias dep is masked" | |
a10f5d05 MB |
433 | create_services test15-a test15-b |
434 | ln -sf test15-b.service /etc/systemd/system/test15-b1.service | |
435 | ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b1.service | |
436 | ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service | |
437 | check_ok test15-a Wants test15-b.service | |
438 | check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units | |
439 | rm /etc/systemd/system/test15-b1.service | |
f2dec872 BR |
440 | |
441 | # 'a' has Wants=b.service but also has a masking | |
442 | # dropin 'b': 'b' should still be pulled in. | |
443 | echo "*** test a wants b both ways" | |
a10f5d05 MB |
444 | create_services test15-a test15-b |
445 | ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service | |
446 | cat >/usr/lib/systemd/system/test15-a.service.d/wants-b.conf<<EOF | |
2897b343 | 447 | [Unit] |
a10f5d05 | 448 | Wants=test15-b.service |
2897b343 | 449 | EOF |
a10f5d05 | 450 | check_ok test15-a Wants test15-b.service |
f2dec872 BR |
451 | |
452 | # mask a dropin that points to an nonexistent unit. | |
453 | echo "*** test a wants nonexistent is masked" | |
a10f5d05 MB |
454 | create_services test15-a |
455 | ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/nonexistent.service | |
456 | ln -sf ../nonexistent.service /usr/lib/systemd/system/test15-a.service.requires/ | |
457 | check_ko test15-a Requires nonexistent.service | |
f2dec872 BR |
458 | |
459 | # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is | |
460 | # masked at a higher level. | |
461 | echo "*** test a wants b is masked" | |
a10f5d05 MB |
462 | create_services test15-a test15-b test15-c |
463 | ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/ | |
464 | ln -sf ../test15-b.service /run/systemd/system/test15-c.service.requires/ | |
465 | ln -sf /dev/null /etc/systemd/system/test15-c.service.requires/test15-b.service | |
466 | systemctl start test15-a | |
467 | check_ko test15-c Requires test15-b.service | |
468 | systemctl stop test15-a test15-b | |
f2dec872 BR |
469 | |
470 | # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is | |
471 | # masked at a lower level. | |
472 | echo "*** test a requires b is masked" | |
a10f5d05 MB |
473 | create_services test15-a test15-b test15-c |
474 | ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/ | |
475 | ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/ | |
476 | ln -sf /dev/null /run/systemd/system/test15-c.service.requires/test15-b.service | |
477 | systemctl start test15-a | |
478 | check_ok test15-c Requires test15-b.service | |
479 | systemctl stop test15-a test15-b | |
f2dec872 BR |
480 | |
481 | # 'a' requires 2 aliases of 'b' and one of them is a mask. | |
482 | echo "*** test a requires alias of b, other alias masked" | |
a10f5d05 MB |
483 | create_services test15-a test15-b |
484 | ln -sf test15-b.service /etc/systemd/system/test15-b1.service | |
485 | ln -sf test15-b.service /etc/systemd/system/test15-b2.service | |
486 | ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b1.service | |
487 | ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/ | |
488 | ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/ | |
489 | check_ok test15-a Requires test15-b | |
f2dec872 BR |
490 | |
491 | # Same as above but now 'b' is masked. | |
492 | echo "*** test a requires alias of b, b dep masked" | |
a10f5d05 MB |
493 | create_services test15-a test15-b |
494 | ln -sf test15-b.service /etc/systemd/system/test15-b1.service | |
495 | ln -sf test15-b.service /etc/systemd/system/test15-b2.service | |
496 | ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/ | |
497 | ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/ | |
498 | ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service | |
499 | check_ok test15-a Requires test15-b | |
500 | ||
501 | clear_services test15-a test15-b | |
2897b343 MP |
502 | } |
503 | ||
97e5042f MB |
504 | test_invalid_dropins () { |
505 | echo "Testing invalid dropins..." | |
506 | # Assertion failed on earlier versions, command exits unsuccessfully on later versions | |
507 | systemctl cat nonexistent@.service || true | |
508 | create_services a | |
509 | systemctl daemon-reload | |
510 | # Assertion failed on earlier versions, command exits unsuccessfully on later versions | |
511 | systemctl cat a@.service || true | |
512 | systemctl stop a | |
513 | clear_services a | |
514 | return 0 | |
515 | } | |
516 | ||
2897b343 | 517 | test_basic_dropins |
3a6ce677 | 518 | test_linked_units |
8b3d4ff0 | 519 | test_template_alias |
46cdbd49 | 520 | test_hierarchical_dropins |
2897b343 MP |
521 | test_template_dropins |
522 | test_alias_dropins | |
523 | test_masked_dropins | |
97e5042f | 524 | test_invalid_dropins |
2897b343 MP |
525 | |
526 | touch /testok |