What is the best way to delay system shutdown by arbitrary amount of time in systemd
?
I'm trying the following unit:
root@ip-172-30-3-65:~# cat /etc/systemd/system/delay_by30.service
[Unit]
Description=Delay Shutdown by 30 sec.
#Before=apache2 nginx php5-fpm
[Service]
Type=oneshot
ExecStart=/bin/echo
ExecStop=/bin/sleep 30
[Install]
WantedBy=multi-user.target
However I'm getting very mixed up results. For the starters my ExecStop
line somehow is executed on systemctl start
and my ExecStart
on systemctl stop
, other way around than it should be. Time stamps in the journalctl
confirm this:
root@ip-172-30-3-65:~# systemctl enable delay_by30.service
Created symlink from /etc/systemd/system/multi-user.target.wants/delay_by30.service to /etc/systemd/system/delay_by30.service.
root@ip-172-30-3-65:~# systemctl start delay_by30.service
root@ip-172-30-3-65:~# systemctl stop delay_by30.service
root@ip-172-30-3-65:~# journalctl -n 4 -u delay_by30
-- Logs begin at Fri 2017-01-06 17:05:34 GMT, end at Mon 2017-01-09 15:57:34 GMT. --
Jan 09 15:55:59 ip-172-30-3-65 systemd[1]: Starting Delay Shutdown by 30 sec....
Jan 09 15:56:29 ip-172-30-3-65 systemd[1]: Started Delay Shutdown by 30 sec..
Jan 09 15:57:34 ip-172-30-3-65 systemd[1]: Stopped Delay Shutdown by 30 sec..
systemd
is instructed to should down the system, it should sleep at least 30 secs before doing so. – NarūnasK Jan 09 '17 at 16:15