]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/units/testsuite-03.sh
scope: on unified, make sure to unwatch all PIDs once they've been moved to the cgrou...
[thirdparty/systemd.git] / test / units / testsuite-03.sh
CommitLineData
ff12a795
JT
1#!/usr/bin/env bash
2set -ex
b5da077d 3
903e7c37 4# Test merging of a --job-mode=ignore-dependencies job into a previously
b5da077d
MS
5# installed job.
6
7systemctl start --no-block hello-after-sleep.target
b46f4ef1 8
b5da077d 9systemctl list-jobs > /root/list-jobs.txt
b46f4ef1
EV
10while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
11 systemctl list-jobs > /root/list-jobs.txt
12done
13
818567fc 14grep 'hello\.service.*waiting' /root/list-jobs.txt
b5da077d
MS
15
16# This is supposed to finish quickly, not wait for sleep to finish.
17START_SEC=$(date -u '+%s')
903e7c37 18systemctl start --job-mode=ignore-dependencies hello
b5da077d
MS
19END_SEC=$(date -u '+%s')
20ELAPSED=$(($END_SEC-$START_SEC))
21
818567fc 22[ "$ELAPSED" -lt 3 ]
b5da077d
MS
23
24# sleep should still be running, hello not.
25systemctl list-jobs > /root/list-jobs.txt
818567fc 26grep 'sleep\.service.*running' /root/list-jobs.txt
b5da077d 27grep 'hello\.service' /root/list-jobs.txt && exit 1
818567fc 28systemctl stop sleep.service hello-after-sleep.target
06c1c4f9 29
f087c7e0
LP
30# Some basic testing that --show-transaction does something useful
31! systemctl is-active systemd-importd
32systemctl -T start systemd-importd
33systemctl is-active systemd-importd
34systemctl --show-transaction stop systemd-importd
35! systemctl is-active systemd-importd
36
59ef392e 37# Test for a crash when enqueuing a JOB_NOP when other job already exists
818567fc 38systemctl start --no-block hello-after-sleep.target
06c1c4f9
MS
39# hello.service should still be waiting, so these try-restarts will collapse
40# into NOPs.
818567fc
MP
41systemctl try-restart --job-mode=fail hello.service
42systemctl try-restart hello.service
43systemctl stop hello.service sleep.service hello-after-sleep.target
b5da077d
MS
44
45# TODO: add more job queueing/merging tests here.
46
d710d363 47# Test for irreversible jobs
818567fc 48systemctl start unstoppable.service
d710d363
MS
49
50# This is expected to fail with 'job cancelled'
51systemctl stop unstoppable.service && exit 1
52# But this should succeed
818567fc 53systemctl stop --job-mode=replace-irreversibly unstoppable.service
d710d363
MS
54
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.
818567fc 58systemctl start unstoppable.service
d710d363 59
93a08841
MP
60# Test waiting for a started unit(s) to terminate again
61cat <<EOF > /run/systemd/system/wait2.service
62[Unit]
63Description=Wait for 2 seconds
64[Service]
65ExecStart=/bin/sh -ec 'sleep 2'
66EOF
67cat <<EOF > /run/systemd/system/wait5fail.service
68[Unit]
69Description=Wait for 5 seconds and fail
70[Service]
71ExecStart=/bin/sh -ec 'sleep 5; false'
72EOF
73
74# wait2 succeeds
75START_SEC=$(date -u '+%s')
818567fc 76systemctl start --wait wait2.service
93a08841
MP
77END_SEC=$(date -u '+%s')
78ELAPSED=$(($END_SEC-$START_SEC))
5209e9af 79[[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1
93a08841
MP
80
81# wait5fail fails, so systemctl should fail
82START_SEC=$(date -u '+%s')
83! systemctl start --wait wait2.service wait5fail.service || exit 1
84END_SEC=$(date -u '+%s')
85ELAPSED=$(($END_SEC-$START_SEC))
86[[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1
87
9ed7de60
PW
88# Test time-limited scopes
89START_SEC=$(date -u '+%s')
90set +e
91systemd-run --scope --property=RuntimeMaxSec=3s sleep 10
92RESULT=$?
93END_SEC=$(date -u '+%s')
94ELAPSED=$(($END_SEC-$START_SEC))
95[[ "$ELAPSED" -ge 3 ]] && [[ "$ELAPSED" -le 5 ]] || exit 1
96[[ "$RESULT" -ne 0 ]] || exit 1
97
b5da077d 98touch /testok