4 # Test merging of a --job-mode=ignore-dependencies job into a previously
7 systemctl start
--no-block hello-after-sleep.target
9 systemctl list-jobs
> /root
/list-jobs.txt
10 while ! grep 'sleep\.service.*running' /root
/list-jobs.txt
; do
11 systemctl list-jobs
> /root
/list-jobs.txt
14 grep 'hello\.service.*waiting' /root
/list-jobs.txt
16 # This is supposed to finish quickly, not wait for sleep to finish.
17 START_SEC
=$
(date -u '+%s')
18 systemctl start
--job-mode=ignore-dependencies hello
19 END_SEC
=$
(date -u '+%s')
20 ELAPSED
=$
(($END_SEC-$START_SEC))
24 # sleep should still be running, hello not.
25 systemctl list-jobs
> /root
/list-jobs.txt
26 grep 'sleep\.service.*running' /root
/list-jobs.txt
27 grep 'hello\.service' /root
/list-jobs.txt
&& exit 1
28 systemctl stop
sleep.service hello-after-sleep.target
30 # Some basic testing that --show-transaction does something useful
31 ! systemctl is-active systemd-importd
32 systemctl
-T start systemd-importd
33 systemctl is-active systemd-importd
34 systemctl
--show-transaction stop systemd-importd
35 ! systemctl is-active systemd-importd
37 # Test for a crash when enqueuing a JOB_NOP when other job already exists
38 systemctl start
--no-block hello-after-sleep.target
39 # hello.service should still be waiting, so these try-restarts will collapse
41 systemctl try-restart
--job-mode=fail hello.service
42 systemctl try-restart hello.service
43 systemctl stop hello.service
sleep.service hello-after-sleep.target
45 # TODO: add more job queueing/merging tests here.
47 # Test for irreversible jobs
48 systemctl start unstoppable.service
50 # This is expected to fail with 'job cancelled'
51 systemctl stop unstoppable.service
&& exit 1
52 # But this should succeed
53 systemctl stop
--job-mode=replace-irreversibly unstoppable.service
55 # We're going to shutdown soon. Let's see if it succeeds when
56 # there's an active service that tries to be unstoppable.
57 # Shutdown of the container/VM will hang if not.
58 systemctl start unstoppable.service
60 # Test waiting for a started unit(s) to terminate again
61 cat <<EOF > /run/systemd/system/wait2.service
63 Description=Wait for 2 seconds
65 ExecStart=/bin/sh -ec 'sleep 2'
67 cat <<EOF > /run/systemd/system/wait5fail.service
69 Description=Wait for 5 seconds and fail
71 ExecStart=/bin/sh -ec 'sleep 5; false'
75 START_SEC
=$
(date -u '+%s')
76 systemctl start
--wait wait2.service
77 END_SEC
=$
(date -u '+%s')
78 ELAPSED
=$
(($END_SEC-$START_SEC))
79 [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] ||
exit 1
81 # wait5fail fails, so systemctl should fail
82 START_SEC
=$
(date -u '+%s')
83 ! systemctl start
--wait wait2.service wait5fail.service ||
exit 1
84 END_SEC
=$
(date -u '+%s')
85 ELAPSED
=$
(($END_SEC-$START_SEC))
86 [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] ||
exit 1
88 # Test time-limited scopes
89 START_SEC
=$
(date -u '+%s')
91 systemd-run
--scope --property=RuntimeMaxSec
=3s
sleep 10
93 END_SEC
=$
(date -u '+%s')
94 ELAPSED
=$
(($END_SEC-$START_SEC))
95 [[ "$ELAPSED" -ge 3 ]] && [[ "$ELAPSED" -le 5 ]] ||
exit 1
96 [[ "$RESULT" -ne 0 ]] ||
exit 1