You are not logged in.
Hello
I have a .service file as per below
[Unit]
...
[Service]
Type=forking
PIDFile=<pid file>
ExecStartPre=<setup command 1>
ExecStartPre=<setup command 2>
ExecStartPre=<setup command 3>
ExecStart=<daemon startup command>
ExecStopPost=<cleanup command 1>
ExecStopPost=<cleanup command 2>
ExecStopPost=<cleanup command 3>
The ExecStartPre and ExecStart sections are executed when I run systemctl start <service> (expected).
The ExecStopPost section is executed when I run systemctl stop <service> (expected)
However, ExecStopPost section is *not* executed when ExecStart fails (and I suspect it is also not executed when ExecStartPre fails). It is not even executed when I run systemctl stop <service> when ExecStart fails.
Is there a way to:
* make systemd run ExecStopPost after failure of either ExecStart or ExecStartPre
* (at least) force systemd to run ExecStopPost even if the service is flagged as failed
Thanks in advance for any help or suggestion!
(systemd 212 +PAM -AUDIT -SELINUX -IMA -SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ +SECCOMP -APPARMOR)
Last edited by sergiogiogio (2014-05-03 00:16:40)
Offline
Looking at the man-page (@ http://www.freedesktop.org/software/sys … vice.html); this seems impossible. Without further details I think the only solution is to create a bash-script to handle this more-advanced logic
Offline
Thanks for your reply!
My understanding from the man page is that ExecStopPost is always executed even after failure:
ExecStopPost= Additional commands that are executed after the service was stopped. This includes cases where the commands configured in ExecStop= were used, where the service does not have any ExecStop= defined, or where the service exited unexpectedly. This argument takes multiple command lines, following the same scheme as described for ExecStart. Use of these settings is optional. Specifier and environment variable substitution is supported.
After further tests it appears that it only does *not* work for forking service so I submitted a bug https://bugs.freedesktop.org/show_bug.cgi?id=78240 .
Offline