2020-03-04 10:35:06 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -ex
|
2013-01-25 20:10:00 +01:00
|
|
|
|
2015-05-18 06:58:24 +02:00
|
|
|
# Test merging of a --job-mode=ignore-dependencies job into a previously
|
2013-01-25 20:10:00 +01:00
|
|
|
# installed job.
|
|
|
|
|
|
|
|
systemctl start --no-block hello-after-sleep.target
|
2016-01-17 04:21:52 +01:00
|
|
|
|
2013-01-25 20:10:00 +01:00
|
|
|
systemctl list-jobs > /root/list-jobs.txt
|
2016-01-17 04:21:52 +01:00
|
|
|
while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
|
|
|
|
systemctl list-jobs > /root/list-jobs.txt
|
|
|
|
done
|
|
|
|
|
2017-08-07 21:09:21 +02:00
|
|
|
grep 'hello\.service.*waiting' /root/list-jobs.txt
|
2013-01-25 20:10:00 +01:00
|
|
|
|
|
|
|
# This is supposed to finish quickly, not wait for sleep to finish.
|
|
|
|
START_SEC=$(date -u '+%s')
|
2015-05-18 06:58:24 +02:00
|
|
|
systemctl start --job-mode=ignore-dependencies hello
|
2013-01-25 20:10:00 +01:00
|
|
|
END_SEC=$(date -u '+%s')
|
|
|
|
ELAPSED=$(($END_SEC-$START_SEC))
|
|
|
|
|
2017-08-07 21:09:21 +02:00
|
|
|
[ "$ELAPSED" -lt 3 ]
|
2013-01-25 20:10:00 +01:00
|
|
|
|
|
|
|
# sleep should still be running, hello not.
|
|
|
|
systemctl list-jobs > /root/list-jobs.txt
|
2017-08-07 21:09:21 +02:00
|
|
|
grep 'sleep\.service.*running' /root/list-jobs.txt
|
2013-01-25 20:10:00 +01:00
|
|
|
grep 'hello\.service' /root/list-jobs.txt && exit 1
|
2017-08-07 21:09:21 +02:00
|
|
|
systemctl stop sleep.service hello-after-sleep.target
|
2014-11-26 16:33:40 +01:00
|
|
|
|
2019-03-26 17:39:36 +01:00
|
|
|
# Some basic testing that --show-transaction does something useful
|
|
|
|
! systemctl is-active systemd-importd
|
|
|
|
systemctl -T start systemd-importd
|
|
|
|
systemctl is-active systemd-importd
|
|
|
|
systemctl --show-transaction stop systemd-importd
|
|
|
|
! systemctl is-active systemd-importd
|
|
|
|
|
2015-11-06 20:01:21 +01:00
|
|
|
# Test for a crash when enqueuing a JOB_NOP when other job already exists
|
2017-08-07 21:09:21 +02:00
|
|
|
systemctl start --no-block hello-after-sleep.target
|
2014-11-26 16:33:40 +01:00
|
|
|
# hello.service should still be waiting, so these try-restarts will collapse
|
|
|
|
# into NOPs.
|
2017-08-07 21:09:21 +02:00
|
|
|
systemctl try-restart --job-mode=fail hello.service
|
|
|
|
systemctl try-restart hello.service
|
|
|
|
systemctl stop hello.service sleep.service hello-after-sleep.target
|
2013-01-25 20:10:00 +01:00
|
|
|
|
|
|
|
# TODO: add more job queueing/merging tests here.
|
|
|
|
|
2013-02-22 18:59:07 +01:00
|
|
|
# Test for irreversible jobs
|
2017-08-07 21:09:21 +02:00
|
|
|
systemctl start unstoppable.service
|
2013-02-22 18:59:07 +01:00
|
|
|
|
|
|
|
# This is expected to fail with 'job cancelled'
|
|
|
|
systemctl stop unstoppable.service && exit 1
|
|
|
|
# But this should succeed
|
2017-08-07 21:09:21 +02:00
|
|
|
systemctl stop --job-mode=replace-irreversibly unstoppable.service
|
2013-02-22 18:59:07 +01:00
|
|
|
|
|
|
|
# We're going to shutdown soon. Let's see if it succeeds when
|
|
|
|
# there's an active service that tries to be unstoppable.
|
|
|
|
# Shutdown of the container/VM will hang if not.
|
2017-08-07 21:09:21 +02:00
|
|
|
systemctl start unstoppable.service
|
2013-02-22 18:59:07 +01:00
|
|
|
|
2016-09-05 13:14:36 +02:00
|
|
|
# Test waiting for a started unit(s) to terminate again
|
|
|
|
cat <<EOF > /run/systemd/system/wait2.service
|
|
|
|
[Unit]
|
|
|
|
Description=Wait for 2 seconds
|
|
|
|
[Service]
|
|
|
|
ExecStart=/bin/sh -ec 'sleep 2'
|
|
|
|
EOF
|
|
|
|
cat <<EOF > /run/systemd/system/wait5fail.service
|
|
|
|
[Unit]
|
|
|
|
Description=Wait for 5 seconds and fail
|
|
|
|
[Service]
|
|
|
|
ExecStart=/bin/sh -ec 'sleep 5; false'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# wait2 succeeds
|
|
|
|
START_SEC=$(date -u '+%s')
|
2017-08-07 21:09:21 +02:00
|
|
|
systemctl start --wait wait2.service
|
2016-09-05 13:14:36 +02:00
|
|
|
END_SEC=$(date -u '+%s')
|
|
|
|
ELAPSED=$(($END_SEC-$START_SEC))
|
2016-11-07 19:51:20 +01:00
|
|
|
[[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1
|
2016-09-05 13:14:36 +02:00
|
|
|
|
|
|
|
# wait5fail fails, so systemctl should fail
|
|
|
|
START_SEC=$(date -u '+%s')
|
|
|
|
! systemctl start --wait wait2.service wait5fail.service || exit 1
|
|
|
|
END_SEC=$(date -u '+%s')
|
|
|
|
ELAPSED=$(($END_SEC-$START_SEC))
|
|
|
|
[[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1
|
|
|
|
|
2019-06-12 09:45:26 +02:00
|
|
|
# Test time-limited scopes
|
|
|
|
START_SEC=$(date -u '+%s')
|
|
|
|
set +e
|
|
|
|
systemd-run --scope --property=RuntimeMaxSec=3s sleep 10
|
|
|
|
RESULT=$?
|
|
|
|
END_SEC=$(date -u '+%s')
|
|
|
|
ELAPSED=$(($END_SEC-$START_SEC))
|
|
|
|
[[ "$ELAPSED" -ge 3 ]] && [[ "$ELAPSED" -le 5 ]] || exit 1
|
|
|
|
[[ "$RESULT" -ne 0 ]] || exit 1
|
|
|
|
|
2013-01-25 20:10:00 +01:00
|
|
|
touch /testok
|