[systemd-devel] How to start a unit right after another unit terminates?

John Ioannidis systemd-devel at tla.org
Mon Jul 16 18:32:11 UTC 2018


Assume I have a one-shot service, *phase1.service*, which runs for a while
and then terminates. I want to have a *phase2.service* start up when phase1
terminates.

I cannot change anything in phase1.service's systemd files or code or
anything, or I would not be asking this question!

A dirty workaround is to just have phase2 start before phase1 and run this
script (wait until phase1 starts up, then wait until it finishes, then do
its thing):

    while ! systemctl status phase1.service > /dev/null
    do
      sleep 10 # still waiting for phase1 to start up
    done
    while systemctl status phase1.service > /dev/null
    do
      sleep 10 # still waiting for phase1 to finish
    done
    # now do the phase2 work

There has to be a better way of doing this, but I can't figure it out.
Google/Bing/SO searches return lots of other workarounds, mostly for user
sessions, which is not the case here.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20180716/fdd9e63b/attachment.html>


More information about the systemd-devel mailing list