<html>
<head>
<base href="https://bugs.freedesktop.org/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Priority</th>
<td>medium
</td>
</tr>
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - ExecStopPost does not execute when a forking service fails to start"
href="https://bugs.freedesktop.org/show_bug.cgi?id=78240">78240</a>
</td>
</tr>
<tr>
<th>Assignee</th>
<td>systemd-bugs@lists.freedesktop.org
</td>
</tr>
<tr>
<th>Summary</th>
<td>ExecStopPost does not execute when a forking service fails to start
</td>
</tr>
<tr>
<th>QA Contact</th>
<td>systemd-bugs@lists.freedesktop.org
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux (All)
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sergiogiogio@ovi.com
</td>
</tr>
<tr>
<th>Hardware</th>
<td>x86-64 (AMD64)
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Component</th>
<td>general
</td>
</tr>
<tr>
<th>Product</th>
<td>systemd
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the QA Contact for the bug.</li>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>