[systemd-devel] proper way for shutdown script
Lennart Poettering
lennart at poettering.net
Wed Oct 5 11:16:27 UTC 2016
On Wed, 05.10.16 12:47, Xen (list at xenhideout.nl) wrote:
> Hi,
>
> the libnss-ldap package on my system used to contain (and still contains) a
> script that is run on system reboot and shutdown and installs itself into
> SysV directories for runlevel 0 and 6.
>
> However on SystemD I believe these are not run? What would be the proper way
> to run them?
Why does nss-ldap require something like this? Sounds strange to me...
What you probably want to do is write a single unit file with an
ExecStart= and an ExecStop= line invoking the right bits to call
during boot and those for shutdown. You want to set Type=oneshot and
RemainAfterExit=yes.
[Unit]
Description=Wuffwuffwuff
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/my-startup-script
ExecStop=/usr/bin/my-shutdown-script
[Install]
WantedBy=multi-user.target
The above should be good enough if your scripts may run during the
normal start-up phase and normal shutdown phase, i.e. after all basic
initialization of the system (such as device probing, kernel config,
and mounting of file systems is done) is completed, in parallel to
normal system services.
If you however, need this stuff during early boot, i.e. before other
regular services are started things get more complicated, as you need
DefaultDependencies=no in this case, and declare precisely before and
after which other early-boot initiatlization services you want to be
started...
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list