[systemd-devel] How to start a unit right after another unit terminates?
Andrei Borzenkov
arvidjaar at gmail.com
Mon Jul 16 19:04:59 UTC 2018
16.07.2018 21:32, John Ioannidis пишет:
> 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!
>
Just add After=phase1.service to phase2.service. For oneshot services
startup completes when service ExecStart* commands complete. Request to
start phase2.service will be waiting for that.
> 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!
>
>
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
More information about the systemd-devel
mailing list