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

Lennart Poettering lennart at poettering.net
Fri May 20 14:41:08 UTC 2016


On Fri, 20.05.16 11:24, Bao Nguyen (baondt at gmail.com) wrote:

> 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?

Our "sysv-generator" tool that is responsible for turning SysV
services into native systemd services understands the
"X-Start-Before:" and "X-Start-After:" LSB header file stanzas to
declare ordering. This is an extension Debian introduced that we
support too.




> 
> 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?

No, these executables are run very late, immediately before executing
the actual system halt, as the documentation says pretty explicitly...

> 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"?

The concept doesn't exist. If everybody does soemthing like that, how
are we supposed to resolve that? If you have 100 services, and all of
them want to be stopped before all others, how would you ever resolve
that?

Please simply list the right deps instead.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list