Bug 78240

Summary: ExecStopPost does not execute when a forking service fails to start
Product: systemd Reporter: sergiogiogio
Component: generalAssignee: systemd-bugs
Status: NEW --- QA Contact: systemd-bugs
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
i915 platform: i915 features:

Description sergiogiogio 2014-05-04 05:08:54 UTC

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
(Arch Linux)

Steps to reproduce:
1- Create a .service file such as below:
ExecStart=/bin/bash -c 'false& echo $! > /var/run/testExecStopPost.pid'
ExecStopPost=/usr/bin/echo ExecStopPost ran

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)
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.