Bug#834164: systemd: Services are not killed after a timeout or killed immediately after ExecStop
Dark Penguin
darkpenguin at yandex.ru
Fri Aug 12 17:26:56 BST 2016
Package: systemd
Version: 215-17+deb8u4
Severity: normal
I am trying to set up a service shutdown sequence in a way that the
service is asked nicely to quit, and if it doesn't, then it's killed
after a timeout. Sounds very simple - this is very basic.
According to man systemd.service,
TimeoutStopSec=
Configures the time to wait for stop. If a service is asked to
stop, but does not terminate in the specified time, it will be
terminated forcibly via SIGTERM, and after another timeout of equal
duration with SIGKILL (see KillMode= in systemd.kill(5)).
However, with this setup:
ExecStop=<ask the service nicely>
KillMode=none
TimeoutStopSec=10s
the service is NEVER killed - even after 10s timeout.
Maybe I don't understand what's written in the manual? I just can't
believe such a basic thing could seriously be overlooked up until now...
I've also tried the same with KillMode=process (and without KillMode at
all - it defaults to control-group), hoping that maybe it will give my
service some time to shut down after ExecStop=, but it killed the
process immediately (and it went into "failed" mode for not stopping
quickly enough). Why do we have ExecStop= at all if the service is
killed immediately anyway?
This behaviour us the same in a newer version of systemd in Linux Mint
18, so it's an upstream bug. (Either that, or I really don't understand
something that simple.)
Here is a sample .service file that can be used safely to test this
behaviour.
= = = = = = =
test.service
= = = = = = =
[Unit]
Description=Test service
[Service]
ExecStart=/usr/bin/screen -h 1024 -dmS test ftp nonExistentServer
Type=forking
ExecStop=/usr/bin/screen -p 0 -S test -X eval 'stuff \"ServiceGoDie\"\015'
# Change the command to "bye" to actually let the "service" quit
# Otherwise it is supposed to fail to quit peacefully
# and be killed after 10s after "systemctl stop test"
KillMode=none
TimeoutStopSec=10s
[Install]
WantedBy=multi-user.target
= = = = = = =
-- Package-specific info:
-- System Information:
Debian Release: 8.5
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 4.1.18-aufs (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages systemd depends on:
ii acl 2.2.52-2
ii adduser 3.113+nmu3
ii initscripts 2.88dsf-59
ii libacl1 2.2.52-2
ii libaudit1 1:2.4-1+b1
ii libblkid1 2.25.2-6
ii libc6 2.19-18+deb8u4
ii libcap2 1:2.24-8
ii libcap2-bin 1:2.24-8
ii libcryptsetup4 2:1.6.6-5
ii libgcrypt20 1.6.3-2+deb8u1
ii libkmod2 18-3
ii liblzma5 5.1.1alpha+20120614-2+b3
ii libpam0g 1.1.8-3.1+deb8u1+b1
ii libselinux1 2.3-2
ii libsystemd0 215-17+deb8u4
ii mount 2.25.2-6
ii sysv-rc 2.88dsf-59
ii udev 215-17+deb8u4
ii util-linux 2.25.2-6
Versions of packages systemd recommends:
ii dbus 1.8.20-0+deb8u1
ii libpam-systemd 215-17+deb8u4
Versions of packages systemd suggests:
pn systemd-ui <none>
-- no debconf information
--
darkpenguin
More information about the Pkg-systemd-maintainers
mailing list