mirror of
https://github.com/systemd/systemd.git
synced 2025-08-30 05:49:54 +03:00
test: cover template OnFailure/OnSuccess handlers in TEST-68-PROPAGATE-EXIT-STATUS
This commit is contained in:
@ -36,6 +36,15 @@ OnFailure=testservice-failure-exit-handler-68.service
|
|||||||
ExecStart=/bin/bash -c "exit 1"
|
ExecStart=/bin/bash -c "exit 1"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
cat >/run/systemd/system/testservice-failure-68-template.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=TEST-68-PROPAGATE-EXIT-STATUS with OnFailure= trigger (template)
|
||||||
|
OnFailure=testservice-failure-exit-handler-68-template@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/bin/bash -c "exit 1"
|
||||||
|
EOF
|
||||||
|
|
||||||
# Trigger testservice-success-exit-handler-68.service
|
# Trigger testservice-success-exit-handler-68.service
|
||||||
cat >/run/systemd/system/testservice-success-68.service <<EOF
|
cat >/run/systemd/system/testservice-success-68.service <<EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
@ -46,6 +55,15 @@ OnSuccess=testservice-success-exit-handler-68.service
|
|||||||
ExecStart=/bin/bash -c "exit 0"
|
ExecStart=/bin/bash -c "exit 0"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
cat >/run/systemd/system/testservice-success-68-template.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=TEST-68-PROPAGATE-EXIT-STATUS with OnSuccess= trigger (template)
|
||||||
|
OnSuccess=testservice-success-exit-handler-68-template@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/bin/bash -c "exit 0"
|
||||||
|
EOF
|
||||||
|
|
||||||
# Script to check that when an OnSuccess= dependency fires, the correct
|
# Script to check that when an OnSuccess= dependency fires, the correct
|
||||||
# MONITOR* env variables are passed.
|
# MONITOR* env variables are passed.
|
||||||
cat >/tmp/check_on_success.sh <<EOF
|
cat >/tmp/check_on_success.sh <<EOF
|
||||||
@ -73,7 +91,7 @@ if [ -z "\$MONITOR_INVOCATION_ID" ]; then
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "\$MONITOR_UNIT" != "testservice-success-68.service" && "\$MONITOR_UNIT" != "testservice-transient-success-68.service" ]]; then
|
if [[ "\$MONITOR_UNIT" != "testservice-success-68.service" && "\$UNIT" != "testservice-success-68-template.service" && "\$MONITOR_UNIT" != "testservice-transient-success-68.service" ]]; then
|
||||||
echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-success-68{-transient}.service\"";
|
echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-success-68{-transient}.service\"";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
@ -92,6 +110,17 @@ ExecStartPre=/tmp/check_on_success.sh
|
|||||||
ExecStart=/tmp/check_on_success.sh
|
ExecStart=/tmp/check_on_success.sh
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Template version.
|
||||||
|
cat >/run/systemd/system/testservice-success-exit-handler-68-template@.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=TEST-68-PROPAGATE-EXIT-STATUS handle service exiting in success (template)
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStartPre=echo "triggered by %i"
|
||||||
|
ExecStartPre=/tmp/check_on_success.sh
|
||||||
|
ExecStart=/tmp/check_on_success.sh
|
||||||
|
EOF
|
||||||
|
|
||||||
# Script to check that when an OnFailure= dependency fires, the correct
|
# Script to check that when an OnFailure= dependency fires, the correct
|
||||||
# MONITOR* env variables are passed.
|
# MONITOR* env variables are passed.
|
||||||
cat >/tmp/check_on_failure.sh <<EOF
|
cat >/tmp/check_on_failure.sh <<EOF
|
||||||
@ -119,7 +148,7 @@ if [ -z "\$MONITOR_INVOCATION_ID" ]; then
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "\$MONITOR_UNIT" != "testservice-failure-68.service" && "\$MONITOR_UNIT" != "testservice-transient-failure-68.service" ]]; then
|
if [[ "\$MONITOR_UNIT" != "testservice-failure-68.service" && "\$UNIT" != "testservice-failure-68-template.service" && "\$MONITOR_UNIT" != "testservice-transient-failure-68.service" ]]; then
|
||||||
echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-failure-68{-transient}.service\"";
|
echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-failure-68{-transient}.service\"";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
@ -139,6 +168,17 @@ ExecStartPre=/tmp/check_on_failure.sh
|
|||||||
ExecStart=/tmp/check_on_failure.sh
|
ExecStart=/tmp/check_on_failure.sh
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Template version.
|
||||||
|
cat >/run/systemd/system/testservice-failure-exit-handler-68-template@.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=TEST-68-PROPAGATE-EXIT-STATUS handle service exiting in failure (template)
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStartPre=echo "triggered by %i"
|
||||||
|
ExecStartPre=/tmp/check_on_failure.sh
|
||||||
|
ExecStart=/tmp/check_on_failure.sh
|
||||||
|
EOF
|
||||||
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
systemctl start testservice-failure-68.service
|
systemctl start testservice-failure-68.service
|
||||||
@ -152,6 +192,12 @@ wait_on_state_or_fail "testservice-success-exit-handler-68.service" "inactive" "
|
|||||||
systemd-run --unit=testservice-transient-failure-68 --property=OnFailure=testservice-failure-exit-handler-68.service /bin/bash -c "exit 1;"
|
systemd-run --unit=testservice-transient-failure-68 --property=OnFailure=testservice-failure-exit-handler-68.service /bin/bash -c "exit 1;"
|
||||||
wait_on_state_or_fail "testservice-failure-exit-handler-68.service" "inactive" "10"
|
wait_on_state_or_fail "testservice-failure-exit-handler-68.service" "inactive" "10"
|
||||||
|
|
||||||
|
# Test template handlers too
|
||||||
|
systemctl start testservice-failure-68-template.service
|
||||||
|
wait_on_state_or_fail "testservice-failure-exit-handler-68-template@testservice-failure-68-template.service.service" "inactive" "10"
|
||||||
|
systemctl start testservice-success-68-template.service
|
||||||
|
wait_on_state_or_fail "testservice-success-exit-handler-68-template@testservice-success-68-template.service.service" "inactive" "10"
|
||||||
|
|
||||||
systemd-analyze log-level info
|
systemd-analyze log-level info
|
||||||
echo OK >/testok
|
echo OK >/testok
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user