[systemd-devel] customized shutdown service needed

Burkhard Kayser kayser-b-2011 at t-online.de
Wed Feb 29 13:12:32 PST 2012


Hi Lennart,
based on your recommendation I tried the following service.

[Unit]
Description=my private startup service

Requires=local-fs.target syslog.service nfs.service
After=local-fs.target syslog.service nfs.service

[Service]
ExecStart=/etc/init.d/my_startup start
ExecStop=/etc/init.d/my_startup stop
Type=oneshot
RemainAfterExit=yes
TimeoutSec=600

[Install]
WantedBy=multi-user.target


This service is started at the very end of the boot sequence. But
stopped too late during shutdown.

cat var/log/messages ...

Feb 29 21:48:43 Linux1 sshd[1758]: Exiting on signal 15
Feb 29 21:48:43 Linux1 avahi-daemon[638]: avahi-daemon 0.6.30 exiting.
Feb 29 21:48:43 Linux1 systemd[1]: Unit mnt-Server-etc.mount entered
failed state.
Feb 29 21:48:43 Linux1 umount[1920]: umount: /var/lib/nfs/rpc_pipefs:
device is busy.
Feb 29 21:48:43 Linux1 umount[1920]: (In some cases useful info about
processes that use
Feb 29 21:48:43 Linux1 systemd[1]: Unit mnt-Server-Download.mount
entered failed state.
Feb 29 21:48:43 Linux1 systemd[1]: Unit srv-mywiki.mount entered failed
state.
Feb 29 21:48:43 Linux1 umount[1920]: the device is found by lsof(8) or
fuser(1))
Feb 29 21:48:43 Linux1 systemd[1]: var-lib-nfs-rpc_pipefs.mount mount
process exited, code=exited status=1
Feb 29 21:48:43 Linux1 systemd[1]: Unit mnt-Server-tmp.mount entered
failed state.
Feb 29 21:48:43 Linux1 logger: starting /etc/init.d/my_shutdown start
(1) 1941 ...
Feb 29 21:48:43 Linux1 logger: starting /etc/init.d/my_startup stop (1)
1937 ...
Feb 29 21:48:43 Linux1 my_shutdown[1941]: + case "$1" in
Feb 29 21:48:43 Linux1 my_shutdown[1941]: + echo 'Wed Feb 29 21:48:43
CET 2012: /etc/init.d/my_shutdown start'
Feb 29 21:48:43 Linux1 my_shutdown[1941]: ++ date
Feb 29 21:48:43 Linux1 my_startup[1937]: + echo stop
Feb 29 21:48:43 Linux1 my_startup[1937]: + /usr/bin/truecrypt --text --list
Feb 29 21:48:43 Linux1 my_shutdown[1941]: + D='Wed Feb 29 21:48:43 CET 2012'
Feb 29 21:48:43 Linux1 my_shutdown[1941]: + echo 'Wed Feb 29 21:48:43
CET 2012: /etc/init.d/my_shutdown start done'
Feb 29 21:48:43 Linux1 my_shutdown[1941]: + logger
'/etc/init.d/my_shutdown done'
Feb 29 21:48:43 Linux1 logger: /etc/init.d/my_shutdown done
Feb 29 21:48:43 Linux1 httpd2[1955]: httpd2: Could not reliably
determine the server's fully qualified domain name, using 192.168.1.27
for ServerName
Feb 29 21:48:43 Linux1 sshd[1705]: Received signal 15; terminating.
Feb 29 21:48:43 Linux1 ntpd[1736]: ntpd exiting on signal 15
Feb 29 21:48:43 Linux1 my_startup[1937]: Error: No volumes mounted.
Feb 29 21:48:43 Linux1 my_startup[1937]: + /usr/bin/truecrypt --text
--non-interactive --dismount /mnt/tc
Feb 29 21:48:43 Linux1 my_startup[1937]: Error: No such volume is mounted.
Feb 29 21:48:43 Linux1 my_startup[1937]: + echo 'stop done'
Feb 29 21:48:43 Linux1 my_startup[1937]: + logger
'/etc/init.d/my_startup done'
Feb 29 21:48:43 Linux1 logger: /etc/init.d/my_startup done
Feb 29 21:48:43 Linux1 kernel: Kernel logging (proc) stopped.
Feb 29 21:48:43 Linux1 rsyslogd: [origin software="rsyslogd"
swVersion="5.8.5" x-pid="619" x-info="http://www.rsyslog.com"] exiting
on signal 15.

I do have several scripts which shall be executed once the machine is
fully up and running and just before the shutdown sequence starts
stopping any service. This was so far working fine with legacy SysV init.

Is there any similar replacement within systemd?

Regards
Burkhard




On 29/02/12 17:10, Lennart Poettering wrote:
> 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
>


More information about the systemd-devel mailing list