[systemd-devel] customized shutdown service needed

Lennart Poettering lennart at poettering.net
Wed Feb 29 08:10:55 PST 2012


On Sun, 26.02.12 17:24, Burkhard Kayser (kayser-b-2011 at t-online.de) wrote:

>    Hello,
>    I do need a customized shutdown service which performs some clean up
>    tasks, e.g. stopping virtual machines,  before the shutdown service of
>    systemd actually starts.
>    The shutdown of the system shall be delayed until my script is
>    terminated.

Well, the intended mode of operation here is that services that are
started at boot are shut down at shutdown. Hence normally you would
place any code you want to run at shutdown in the ExecStop= of the
service in question.

A number of services are run only at shutdown, and have no counterpart
at boot-up. These are "special", and live outside the default depndency
logic, and need to be marked with DefaultDependencies=no for that. When
exactly they are run depends on how you configure things. One possible
option here is to order them between shutdown.target and final.target,
which makes the server to be started after all normal services are shut
down, but before we actually do the low-level termination. If such a
service shell complete before we continue with the shut down you need to
use Type=oneshot.

>      Before=shutdown.service halt.service

There is no shutdown.service. And halt.service is most likely not what
you want to use, since it's responsible for actually halting the machine
(as opposed to reboot or power it off)

>      DefaultDependencies=no
> 
>      [Service]
>      ExecStart=/etc/init.d/my_shutdown start

This is not a SysV script, you should not place it in this directory.

>      Type=oneshot
>      RemainAfterExit=true

RemainAfterExit= makes little sense here.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list