linux reboot and shutdown command
If you are managing your Linux machines you are aware of some useful shutdown/ powercycle commands. You might have used one of the commands to reboot/ powercycle or shutdown a box: reboot, halt, shutdown, poweroff, telinit
bitarray>ls -rplt /sbin/|egrep "halt|shutdown|reboot" lrwxrwxrwx 1 root root 14 Mar 8 17:51 shutdown -> /bin/systemctl lrwxrwxrwx 1 root root 14 Mar 8 17:51 reboot -> /bin/systemctl lrwxrwxrwx 1 root root 14 Mar 8 17:51 halt -> /bin/systemctl lrwxrwxrwx 1 root root 14 Mar 8 17:51 telinit -> /bin/systemctl bitarray>
so they all point to systemctl (since 2014). You need to be root to shutdown the system.
How to schedule a shutdown?
- shutdown now # will shutdown now graceful shutdown for all processes
- shutdown 10 # shutdown after 10 mins
- shutdown 23:59 # shutdown at time 23:59
- shutdown -c # cancel shutdown
- shutdown -r # reboot the machine
- shutdown -P # poweroff the machine (it won’t get started)
remember when shutdown time is < 5mins then no users will be allowed to login.
In systemd reboot, halt, poweroff, telinit, and shutdown are same systemctl command.
example# setting shutdown after 100 mins
bitarray>date Fri Aug 24 19:35:33 EDT 2018 bitarray>shutdown 100 Shutdown scheduled for Fri 2018-08-24 21:15:38 EDT, use 'shutdown -c' to cancel.
Canceling shutdown
shutdown -c
bitarray>shutdown -c Broadcast message from root@hostmaster (Fri 2018-08-24 19:37:23 EDT): The system shutdown has been cancelled at Fri 2018-08-24 19:38:23 EDT! bitarray>
How do we know if there is a scheduled shutdown?
just do a ps -ef and you will see the shutdown process
bitarray>ps -ef|grep shut root 8446 1 0 19:35 ? 00:00:00 /usr/lib/systemd/systemd-shutdownd
During the shutdown, all processes are sent TERM signal (for a graceful exit).
How to check previous shutdowns:
#last -x|grep shutdown shutdown system down 3.10.0-693.11.6. Sun Aug 19 19:15 - 19:15 (00:00) shutdown system down 3.10.0-693.11.6. Thu Aug 16 19:35 - 19:36 (00:01) shutdown system down 3.10.0-693.11.6. Wed Aug 15 20:25 - 20:34 (00:08) shutdown system down 3.10.0-693.11.6. Thu Jul 12 19:06 - 19:06 (00:00) shutdown system down 3.10.0-693.11.6. Thu Jan 25 15:06 - 20:08 (05:02) shutdown system down 3.10.0-514.21.2. Thu Jan 25 13:27 - 13:28 (00:00)
You must be logged in to post a comment.
+ There are no comments
Add yours