Bug 78240 - ExecStopPost does not execute when a forking service fails to start
Summary: ExecStopPost does not execute when a forking service fails to start
Status: NEW
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-04 05:08 UTC by sergiogiogio
Modified: 2014-05-04 05:08 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sergiogiogio 2014-05-04 05:08:54 UTC
Hello,

ExecStopPost does not execute when a forking service fails to start.
On the other hand, ExecStopPost appropriately executes when a non-forking service fails to start.

Version: systemd 212
+PAM -AUDIT -SELINUX -IMA -SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ +SECCOMP -APPARMOR
(Arch Linux)

Steps to reproduce:
1- Create a .service file such as below:
------
[Unit]
Description=testExecStopPost
[Service]
Type=forking
PIDFile=/var/run/testExecStopPost.pid
ExecStart=/bin/bash -c 'false& echo $! > /var/run/testExecStopPost.pid'
ExecStopPost=/usr/bin/echo ExecStopPost ran
[Install]
WantedBy=multi-user.target
------

2- Execute the below commands:
systemctl daemon-reload
systemctl start testExecStopPost
systemctl status testExecStopPost

3- Notice that the ExecStopPost command does not execute (no 'echo' in the log):
<date> htpc systemd[1]: Starting testExecStopPost...
<date> htpc systemd[1]: PID 20110 read from file /var/run/testExecStopPost.pid does not exist or is a zombie.
<date> htpc systemd[1]: Failed to start testExecStopPost.
<date> htpc systemd[1]: Unit testExecStopPost.service entered failed state.

4- The issue is not reproducible with non-forking services. With non-forking services, ExecStopPost is correctly executed even if the service fails to start (notice the 'echo' in the logs)
------
[Service]
ExecStart=/usr/bin/false
ExecStopPost=/usr/bin/echo ExecStopPost ran
------
<date> htpc systemd[1]: Started testExecStopPost.
<date> htpc systemd[1]: testExecStopPost.service: main process exited, code=exited, status=1/FAILURE
<date> htpc echo[20242]: ExecStopPost ran
<date> htpc systemd[1]: Unit testExecStopPost.service entered failed state.

5- Indirectly related: it would be useful to have a directive to force execute ExecStopPost if ExecStartPre fails.
Rationale: ExecStopPost is typically used for cleanup, but if ExecStartPre fails, there is today no way to perform this cleanup. Systematically executing ExecStopPost is probably debatable (e.g. C++ destructors do not run if contructors fail) so having a directive, or at worst a command to force execute ExecStopPost would be useful.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.