]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-03-JOBS/test-jobs.sh
Merge pull request #4536 from poettering/seccomp-namespaces
[thirdparty/systemd.git] / test / TEST-03-JOBS / test-jobs.sh
1 #!/bin/bash -x
2
3 # Test merging of a --job-mode=ignore-dependencies job into a previously
4 # installed job.
5
6 systemctl start --no-block hello-after-sleep.target
7
8 systemctl list-jobs > /root/list-jobs.txt
9 while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
10 systemctl list-jobs > /root/list-jobs.txt
11 done
12
13 grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1
14
15 # This is supposed to finish quickly, not wait for sleep to finish.
16 START_SEC=$(date -u '+%s')
17 systemctl start --job-mode=ignore-dependencies hello
18 END_SEC=$(date -u '+%s')
19 ELAPSED=$(($END_SEC-$START_SEC))
20
21 [ "$ELAPSED" -lt 3 ] || exit 1
22
23 # sleep should still be running, hello not.
24 systemctl list-jobs > /root/list-jobs.txt
25 grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1
26 grep 'hello\.service' /root/list-jobs.txt && exit 1
27 systemctl stop sleep.service hello-after-sleep.target || exit 1
28
29 # Test for a crash when enqueuing a JOB_NOP when other job already exists
30 systemctl start --no-block hello-after-sleep.target || exit 1
31 # hello.service should still be waiting, so these try-restarts will collapse
32 # into NOPs.
33 systemctl try-restart --job-mode=fail hello.service || exit 1
34 systemctl try-restart hello.service || exit 1
35 systemctl stop hello.service sleep.service hello-after-sleep.target || exit 1
36
37 # TODO: add more job queueing/merging tests here.
38
39 # Test for irreversible jobs
40 systemctl start unstoppable.service || exit 1
41
42 # This is expected to fail with 'job cancelled'
43 systemctl stop unstoppable.service && exit 1
44 # But this should succeed
45 systemctl stop --job-mode=replace-irreversibly unstoppable.service || exit 1
46
47 # We're going to shutdown soon. Let's see if it succeeds when
48 # there's an active service that tries to be unstoppable.
49 # Shutdown of the container/VM will hang if not.
50 systemctl start unstoppable.service || exit 1
51
52 # Test waiting for a started unit(s) to terminate again
53 cat <<EOF > /run/systemd/system/wait2.service
54 [Unit]
55 Description=Wait for 2 seconds
56 [Service]
57 ExecStart=/bin/sh -ec 'sleep 2'
58 EOF
59 cat <<EOF > /run/systemd/system/wait5fail.service
60 [Unit]
61 Description=Wait for 5 seconds and fail
62 [Service]
63 ExecStart=/bin/sh -ec 'sleep 5; false'
64 EOF
65
66 # wait2 succeeds
67 START_SEC=$(date -u '+%s')
68 systemctl start --wait wait2.service || exit 1
69 END_SEC=$(date -u '+%s')
70 ELAPSED=$(($END_SEC-$START_SEC))
71 [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1
72
73 # wait5fail fails, so systemctl should fail
74 START_SEC=$(date -u '+%s')
75 ! systemctl start --wait wait2.service wait5fail.service || exit 1
76 END_SEC=$(date -u '+%s')
77 ELAPSED=$(($END_SEC-$START_SEC))
78 [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1
79
80 touch /testok