Scheduling / descheduling linux host reboots via shutdown


Scheduling and/or descheduling linux host reboots is possible with the shutdown -r command using the time parameter (the reboot command, that I usually prefer in favour of clarity, does’nt feature the time parameter, so shutdown -r is the only choice here). Aside from discussing the quite straightforward man page of shutdown, there is two points here to register in your knowledge cells.
First, a (scheduled) shutdown -r hh24:mi execution will hangup itself into background, no need to use job-tools or an &. shutdown -r hh24:mi actually puts systemd-shutdownd in charge of serving the party, this is what you”ll want to expect to see in your running process list, looking for some command effect. Also, a running scheduled shutdown may be cancelled using shutdown -c any time before hh24:mi. Note however, that from around five minutes before hh24:mi, you’ll you’ll no longer be allowed to login the machine, essentially impeding any further control from your side.

Second, shutdown -r hh24:mi or, as we know now, systemd-shutdownd, will emit console broadcast alert messages, the wall parameter of shutdown by the way, upon command execution (with time == now for example) and for every full hour before action. So if you’ve got any other hack in place, I really saw that once, that reads anything coming in from a tty, your hack may become stuck in interpreting this. The following gives a console example of rawly anything being depicted before. The code snippets have been executed in that order, just being divided into titled sections here for readability.

[root@test-01 ~]# ps x | grep shut
29635 pts/0    S+     0:00 grep -i --color=always shut
[root@test-01 ~]# shutdown -r 22:00
Shutdown scheduled for Fri 2017-03-03 22:00:00 CET, use 'shutdown -c' to cancel.
[root@test-01 ~]# ps x | grep shut
30027 ?        Ss     0:00 /usr/lib/systemd/systemd-shutdownd
30193 pts/0    S+     0:00 grep -i --color=always shut
[root@test-01 ~]#
Broadcast message from root@test-01 (Fri 2017-03-03 12:00:00 CET):
The system is going down for reboot at Fri 2017-03-03 22:00:00 CET!
[root@test-01 ~]# shutdown -c
[root@test-01 ~]#
Broadcast message from root@test-01 (Fri 2017-03-03 12:01:18 CET):
The system shutdown has been cancelled at Fri 2017-03-03 12:02:18 CET!
[root@test-01 ~]# ps x | grep shut
 2522 pts/0    S+     0:00 grep -i --color=always shut
[root@test-01 ~]# shutdown -r 22:00
Shutdown scheduled for Fri 2017-03-03 22:00:00 CET, use 'shutdown -c' to cancel.
[root@test-01 ~]#
Broadcast message from root@test-01 (Fri 2017-03-03 13:00:00 CET):
The system is going down for reboot at Fri 2017-03-03 22:00:00 CET!

Have fun, Peter

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s