[systemd-devel] Generic unit file to run command on shutdown impossible?

Lennart Poettering lennart at poettering.net
Wed Sep 11 10:42:35 PDT 2013


On Sat, 10.08.13 15:59, David Mazieres expires 2013-11-08 PST (mazieres-rq54ugpgb894kkmq2swhjjbdf2 at temporary-address.scs.stanford.edu) wrote:

> I'm trying to do something that I hope is relatively simple, namely to
> run a simple kexec -l ... command on system shutdown before the /boot
> file system is unmounted.  I'm trying this on two different machines,
> both of which are running current versions of arch linux with systemd
> 204.  The machines are configured very similarly, except that one has
> a serial console and some NFS mounts, while the other does not.
> Unfortunately, I cannot find a single script that works on both
> machines.
> 
> On the machine with a serial console, the following unit file seems to
> work (in /etc/systemd/system/kexec-load at .service, enabled with
> systemctl enable kexec-load at linux).  This is a slightly modified
> version of a suggestion on the arch linux wiki:

It's usually a better idea to have this as unit that starts at bootup,
and stops at shutdown, rather than one that starts at shutdown. This is
because of the orderign semantics of start and stop jobs. The general
rule here is that if one job is started and one is stopped and there is
either After= or Before= defined between their two units, then the Stop=
is always run first, and the start second, regardless whether After or
Before was used.

After/Before= hence only declare the ordering between two start jobs,
and the ordering between two stop jobs (where the rule is that it is the
inverse of the start order), but not between a start and a stop job.

This might be confusing, but not too difficult to grok I guess..

Effectively this means that you should define a RemainAfterExit=yes
service with ExecStart=/bin/true and ExecStop= set to what you want to
run at shutdown. The requirement to set an ExecStart= is something we
will lift soon, but for now it is required.

I hope this makes some sense?

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list