[systemd-devel] Running a service at shutdown time before file systems are unmounted

Lennart Poettering lennart at poettering.net
Fri Aug 3 12:42:52 PDT 2012


On Fri, 27.07.12 18:08, Manuel Amador (Rudd-O) (rudd-o at rudd-o.com) wrote:

> I need to run a program right before any file system is unmounted, to
> record the current file system state on disk.
> 
> What Requires/RequiredBy, Wants/WantedBy, Before/After dependencies
> should I encode in my unit file?

Do it like this:

[Service]
ExecStart=/bin/true
ExecStop=/my/little/program
RemainAfterExit=yes

then simply enable this like any other program from multi-user.target or
so. This will make a service available that is started at boot (but is a
NOP mostly) and then stopped at shutdown before all local mounts are
gone.

Yes, this is not really a nice solution, and we can certainly improve
this. For starters the ExecStart=/bin/true is currently necessary (since
we require all services to have ExecStart), but we should make that
unnecessary, if possible. And it is indeed confusing that for starting a
service a shutdown that is ordered against the local mounts you actually
need to start it early and then stop it a shutdown. 

But anyway, hope this helps,

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list