[systemd-devel] Shutdown a specific service in systemd shutdown

Bao Nguyen baondt at gmail.com
Fri May 20 04:24:40 UTC 2016


Hi Martin,

Thanks a lot for your answer.

How about if my specific script is written by SysVinit, it has LSB headers,
can we still use in LSB header the property lAfter= as in systemd to make
it start/stop orderly?

Another solution I think to make it shutdowns "order" when I read
systemd-halt.service in
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html

"Immediately before executing the actual system halt/poweroff/reboot/kexec
systemd-shutdown will run all executables in
/usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "
halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All
executables in this directory are executed in parallel, and execution of
the action is not continued before all executables finished."

Can I put a script to terminate my specific script in
/usr/lib/systemd/system-shutdown/?
As the description, the script will be run to terminate my script before
executing the actual system shutdown?

Some people on internet also tried to make a script to do something
before everything
else on shutdown with systemd like
http://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemde

How do you think if I can make a script to terminate my script before all
other services shutdown like above to make it "order"?

Thanks a lot.

Best regards,
Natsu





On Thu, May 19, 2016 at 3:57 PM, Martin Pitt <martin.pitt at ubuntu.com> wrote:

> Hello Bao,
>
> Bao Nguyen [2016-05-19 15:52 +0700]:
> > When the system is shutdown, systemd will terminate all services in
> > parallel manner, could you let me know if there is any ways to tell
> systemd
> > to shutdown a specific service first, then shutdown all remaining
> services?
>
> The concept of "first"/"last" has no well-defined meaning in any
> non-serial init systems (not even SysV init with insserv, only with
> classic SysV init with manually set priorities). I've heard requests
> like "but this needs to be started as the last thing" a lot in the
> recent years, and there's no way all the services can simultaneously
> be "last" :-)
>
> You should put sufficient After= properties into your service, so that
> it gets started after and stopped before the ones you specify. See
> man systemd.unit for details.
>
> Martin
>
> --
> Martin Pitt                        | http://www.piware.de
> Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160520/22d0c2f5/attachment.html>


More information about the systemd-devel mailing list