mirror of
https://github.com/systemd/systemd.git
synced 2025-02-28 05:57:33 +03:00
Otherwise, when stopping the service, the last command may not be started yet, and the service manager may not send SIGTERM signal to the last command, but send SIGKILL on timeout. === May 21 08:23:24 test19-exit-cgroup.sh[437]: + disown May 21 08:23:24 test19-exit-cgroup.sh[438]: + sleep infinity May 21 08:23:24 test19-exit-cgroup.sh[437]: + systemd-notify --ready May 21 08:23:24 test19-exit-cgroup.sh[437]: + sleep infinity May 21 08:23:24 test19-exit-cgroup.sh[441]: + systemctl stop one May 21 08:23:24 test19-exit-cgroup.sh[443]: + sleep infinity (snip) May 21 08:23:24 systemd[1]: one.service: Changed running -> stop-sigterm May 21 08:23:24 systemd[1]: Stopping one.service - /tmp/test19-exit-cgroup.sh "systemctl stop one"... May 21 08:23:24 systemd[1]: Received SIGCHLD from PID 441 (systemctl). May 21 08:23:24 systemd[1]: Child 437 (bash) died (code=killed, status=15/TERM) May 21 08:23:24 systemd[1]: one.service: Child 437 belongs to one.service. May 21 08:23:24 systemd[1]: one.service: Main process exited, code=killed, status=15/TERM (success) May 21 08:23:24 systemd[1]: Child 439 (bash) died (code=killed, status=15/TERM) May 21 08:23:24 systemd[1]: one.service: Child 439 belongs to one.service. May 21 08:23:24 systemd[1]: Child 441 (systemctl) died (code=killed, status=15/TERM) May 21 08:23:24 systemd[1]: one.service: Child 441 belongs to one.service. May 21 08:23:24 systemd[1]: Child 442 (bash) died (code=killed, status=15/TERM) May 21 08:23:24 systemd[1]: one.service: Child 442 belongs to one.service. (snip) May 21 08:24:54 systemd[1]: one.service: State 'stop-sigterm' timed out. Killing. May 21 08:24:54 systemd[1]: one.service: Killing process 443 (sleep) with signal SIGKILL. May 21 08:24:54 systemd[1]: one.service: Changed stop-sigterm -> stop-sigkill May 21 08:24:54 systemd[1]: Received SIGCHLD from PID 443 (sleep). May 21 08:24:54 systemd[1]: Child 443 (sleep) died (code=killed, status=9/KILL) May 21 08:24:54 systemd[1]: one.service: Child 443 belongs to one.service. May 21 08:24:54 systemd[1]: one.service: Control group is empty. May 21 08:24:54 systemd[1]: one.service: Failed with result 'timeout'. May 21 08:24:54 systemd[1]: one.service: Service restart not allowed. May 21 08:24:54 systemd[1]: one.service: Changed stop-sigkill -> failed May 21 08:24:54 systemd[1]: one.service: Job 738 one.service/stop finished, result=done May 21 08:24:54 systemd[1]: Stopped one.service - /tmp/test19-exit-cgroup.sh "systemctl stop one". May 21 08:24:54 systemd[1]: one.service: Unit entered failed state. May 21 08:24:54 systemd[1]: one.service: Releasing resources... === Fixes #32947.
104 lines
2.8 KiB
Bash
Executable File
104 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eux
|
|
|
|
# Test ExitType=cgroup
|
|
|
|
# shellcheck source=test/units/util.sh
|
|
. "$(dirname "$0")"/util.sh
|
|
|
|
if [[ "$(get_cgroup_hierarchy)" != unified ]]; then
|
|
echo "Skipping $0 as we're not running with the unified cgroup hierarchy"
|
|
exit 0
|
|
fi
|
|
|
|
systemd-analyze log-level debug
|
|
|
|
# Multiple level process tree, parent process stays up
|
|
cat >/tmp/test19-exit-cgroup.sh <<EOF
|
|
#!/usr/bin/env bash
|
|
set -eux
|
|
|
|
# process tree: systemd -> sleep
|
|
sleep infinity &
|
|
disown
|
|
|
|
# process tree: systemd -> bash -> bash -> sleep
|
|
((sleep infinity); true) &
|
|
|
|
systemd-notify --ready
|
|
|
|
# Run the stop/kill command, but sleep a bit to make the sleep infinity
|
|
# below actually started before stopping/killing the service.
|
|
(sleep 1; \$1) &
|
|
|
|
# process tree: systemd -> bash -> sleep
|
|
sleep infinity
|
|
EOF
|
|
chmod +x /tmp/test19-exit-cgroup.sh
|
|
|
|
# service should be stopped cleanly
|
|
systemd-run --wait \
|
|
--unit=one \
|
|
--property="Type=notify" \
|
|
--property="ExitType=cgroup" \
|
|
/tmp/test19-exit-cgroup.sh 'systemctl stop one'
|
|
|
|
# same thing with a truthy exec condition
|
|
systemd-run --wait \
|
|
--unit=two \
|
|
--property="Type=notify" \
|
|
--property="ExitType=cgroup" \
|
|
--property="ExecCondition=true" \
|
|
/tmp/test19-exit-cgroup.sh 'systemctl stop two'
|
|
|
|
# false exec condition: systemd-run should exit immediately with status code: 1
|
|
(! systemd-run --wait \
|
|
--unit=three \
|
|
--property="Type=notify" \
|
|
--property="ExitType=cgroup" \
|
|
--property="ExecCondition=false" \
|
|
/tmp/test19-exit-cgroup.sh)
|
|
|
|
# service should exit uncleanly (main process exits with SIGKILL)
|
|
(! systemd-run --wait \
|
|
--unit=four \
|
|
--property="Type=notify" \
|
|
--property="ExitType=cgroup" \
|
|
/tmp/test19-exit-cgroup.sh 'systemctl kill --signal 9 four')
|
|
|
|
|
|
# Multiple level process tree, parent process exits quickly
|
|
cat >/tmp/test19-exit-cgroup-parentless.sh <<EOF
|
|
#!/usr/bin/env bash
|
|
set -eux
|
|
|
|
# process tree: systemd -> sleep
|
|
sleep infinity &
|
|
|
|
# process tree: systemd -> bash -> sleep
|
|
((sleep infinity); true) &
|
|
|
|
systemd-notify --ready
|
|
|
|
# Run the stop/kill command after this bash process exits
|
|
(sleep 1; \$1) &
|
|
EOF
|
|
chmod +x /tmp/test19-exit-cgroup-parentless.sh
|
|
|
|
# service should be stopped cleanly
|
|
systemd-run --wait \
|
|
--unit=five \
|
|
--property="Type=notify" \
|
|
--property="ExitType=cgroup" \
|
|
/tmp/test19-exit-cgroup-parentless.sh 'systemctl stop five'
|
|
|
|
# service should still exit cleanly despite SIGKILL (the main process already exited cleanly)
|
|
systemd-run --wait \
|
|
--unit=six \
|
|
--property="Type=notify" \
|
|
--property="ExitType=cgroup" \
|
|
/tmp/test19-exit-cgroup-parentless.sh 'systemctl kill --signal 9 six'
|
|
|
|
|
|
systemd-analyze log-level info
|