[systemd-devel] Quick ? about ExecStartPre and Restart

Lennart Poettering lennart at poettering.net
Fri Jul 5 13:27:04 PDT 2013


On Wed, 03.07.13 15:38, Paul D. DeRocco (pderocco at ix.netcom.com) wrote:

> I'm new to systemd, and I'm confused about something. The docs include the
> following sentence under the Restart directive:
> 
> "Configures whether the service shall be restarted when the service process
> exits, is killed, or a timeout is reached. The service process may be the
> main service process, but also one of the processes specified with
> ExecStartPre=, ExecStartPost=, ExecStopPre=, ExecStopPost=, or ExecReload=."
> 
> Read literally, this suggests that if I set this to "on-success" or
> "always", and I have an ExecStartPre that runs a quick command (in my case,
> to copy my main service executable from a flash drive to a RAM drive), then
> as soon as that completes, systemd will say, "Hey, the service has
> terminated, time to restart it" and never get around to the ExecStart that
> really does the work.

This is indeed badly expressed, I added to the TODO list that we fix
this. 

So what's actually meant here is that if a command line from
ExecStartPre= *fails* this already causes a restart of the entire
daemon. But if it suceeds, then the runtime of the main daemon is what
matters, and if the main daemon dies it is restarted. 

> Is that really true? Or is that just a mistake in the docs? If it's not a
> mistake, how do I configure it so that it won't restart when the command
> launched by ExecStartPre terminates with a 0 exit code, but will restart if
> the actual service started by ExecStart terminates with a 0 exit code?
> 
> Or is there another preferable way to do this?

"on-success" and "always" do what you think they do, and the docs just
suck in this case. We need to fix the docs.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list