[systemd-devel] proper way for shutdown script

Lennart Poettering lennart at poettering.net
Wed Oct 5 12:52:34 UTC 2016

On Wed, 05.10.16 14:37, Xen (list at xenhideout.nl) wrote:

> Lennart Poettering schreef op 05-10-2016 13:16:
> >Why does nss-ldap require something like this? Sounds strange to me...
> Thanks man. I was just gonna charge you $40 for missed time... ;-).
> There are services during startup that are going to hang if you configure
> nsswitch.conf to also use ldap for e.g. passwd or group.
> What this means is that in ldap.conf they have enabled something that will
> refuse ldap lookup for those kinds of users.
> The script I mentioned adds this to the ldap.conf:
> nss_initgroups_ignoreusers
> _apt,avahi,avahi-autoipd,backup,bin,colord,daemon,dnsmasq,games,gnats,hplip,irc,kernoops,list,lp,mail,man,messagebus,news,proxy,pulse,root,rtkit,saned,sddm,sshd,sync,sys,syslog,systemd-bus-proxy,systemd-network,systemd-resolve,systemd-timesync,unscd,usbmux,uucp,uuidd,whoopsie,www-data

Urgs, what an ugly approach...
> I found a solution on Arch forums that would do:
> [Unit]
> Description=rawr
> [Service]
> Type=oneshot
> ExecStart=/bin/true
> ExecStop=/usr/bin/touch /usr/local/somefile.txt
> RemainAfterExit=yes
> [Install]
> WantedBy=sysinit.target
> And this works. But now the service must be started first before it will be
> called on shutdown... :-/.
> Which pollutes the boot-up log and there is really no reason for it?

It's the way to go on systemd. With current systemd you should be able
to leave out the ExecStart=/bin/true bit, if you only care about

But as I understood you actually wanted to run something both at boot
and at shutdown, hence why would you not make use of ExecStart= as
well here?

Note that the above unit file you posted is a bit contradictory: if
you plug something into sysinit.target then your service should be an
early-boot service, and those have to have the DefaultDependencies=no
setting, as they need to configure their preicse ordering manually,
instead of relying on the generic dependencies.

hence, either change the Wantedby= setting to
WantedBy=multi-user.target and make the service a proper late-boot
service, or also set DefaultDEpendencies=no and add the appropriate,
manual early-boot dependencies.


Lennart Poettering, Red Hat

More information about the systemd-devel mailing list