Bug#964967: systemd: ExecStartPost executed even if ExecStart fails immediately
Drexl Johannes
johannes.drexl at lrz.de
Mon Jul 13 16:04:33 BST 2020
Package: systemd
Version: 241-7~deb10u4
Severity: normal
Dear Maintainer,
tests on systemd environment variables under certain conditions got me puzzled,
and I guess this would be considered a bug.
A systemd service will execute all ExecStartPost statements, even if the
corresponding service configured with ExecStart has bailed out with error code.
One can test it with a [Service] section like that:
Type=exec
User=debian
Group=debian
# Test
ExecStartPre=/bin/true
ExecStart=/bin/false
ExecStartPost=/bin/echo "StartPost Beginn"
ExecStartPost=/bin/sleep 5
ExecStartPost=/bin/printenv
ExecStartPost=/bin/true
ExecStop=/bin/echo "Stop Beginn"
ExecStop=/bin/printenv
ExecStop=/bin/true
ExecStopPost=/bin/echo "StopPost Beginn"
ExecStopPost=/bin/printenv
This will result in a situation captured in journal:
Jul 13 16:57:29 primus systemd[1]: test.service: Main process exited, code=exite
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit test.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Jul 13 16:57:29 primus echo[24742]: StartPost Beginn
Jul 13 16:57:34 primus printenv[24744]: LANG=en_US.UTF-8
Jul 13 16:57:34 primus printenv[24744]: PATH=/usr/local/sbin:/usr/local/bin:/usr
Jul 13 16:57:34 primus printenv[24744]: HOME=/home/debian
Jul 13 16:57:34 primus printenv[24744]: LOGNAME=debian
Jul 13 16:57:34 primus printenv[24744]: USER=debian
Jul 13 16:57:34 primus printenv[24744]: SHELL=/bin/bash
Jul 13 16:57:34 primus printenv[24744]: INVOCATION_ID=e9c25c8c677743b19cf95abe7c
Jul 13 16:57:34 primus printenv[24744]: JOURNAL_STREAM=9:2458318
Jul 13 16:57:34 primus echo[24746]: StopPost Beginn
As is clearly visible, Systemd knows the main process bailed out prior
to Systemd beginning to execute even the first ExecStartPost statement.
Although I might miss out some really important thoughts on why it was
decided as such, I find it a little confusing, because all ExecStop
statements are skipped as can be read in the documentation.
-- Package-specific info:
-- System Information:
Debian Release: 10.4
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 4.19.0-9-amd64 (SMP w/8 CPU cores)
Kernel taint flags: TAINT_WARN
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages systemd depends on:
ii adduser 3.118
ii libacl1 2.2.53-4
ii libapparmor1 2.13.2-10
ii libaudit1 1:2.8.4-3
ii libblkid1 2.33.1-0.1
ii libc6 2.28-10
ii libcap2 1:2.25-2
ii libcryptsetup12 2:2.1.0-5+deb10u2
ii libgcrypt20 1.8.4-5
ii libgnutls30 3.6.7-4+deb10u4
ii libgpg-error0 1.35-1
ii libidn11 1.33-2.2
ii libip4tc0 1.8.2-4
ii libkmod2 26-1
ii liblz4-1 1.8.3-1
ii liblzma5 5.2.4-1
ii libmount1 2.33.1-0.1
ii libpam0g 1.3.1-5
ii libseccomp2 2.3.3-4
ii libselinux1 2.8-1+b1
ii libsystemd0 241-7~deb10u4
ii mount 2.33.1-0.1
ii util-linux 2.33.1-0.1
Versions of packages systemd recommends:
ii dbus 1.12.16-1
ii libpam-systemd 241-7~deb10u4
Versions of packages systemd suggests:
ii policykit-1 0.105-25
pn systemd-container <none>
Versions of packages systemd is related to:
pn dracut <none>
ii initramfs-tools 0.133+deb10u1
ii udev 241-7~deb10u4
-- Configuration Files:
/etc/systemd/timesyncd.conf changed [not included]
-- no debconf information
More information about the Pkg-systemd-maintainers
mailing list