In Linux system administration, it is sometimes required to restart server after the completion of some network and other major updates either relevant to software or hardware that are being carried on the server.
For example, if we are recompiling the server’s kernel that undergoes some more advanced server administration, we have to restart the machine in order to complete the compilation and have a new updated kernel version on the server. Updating server’s memory, IP allocation, NIC configuration are the key tasks that need to have server restarted once leading to their successful implementation.
Let's check how to perform a graceful restart of a Linux system using shutdown and systemctl command. Make sure you run command as root or user with sudo privileges.
Shutdown command with
-r option is used for a system reboot. By default, the system will be rebooted after 1 minute for the following command:
$ sudo shutdown -r
You can reboot immediately using
shutdown –r now or
shutdown –r 0 as following:
$ sudo shutdown –r now $ sudo shutdown –r 0 $ sudo reboot
A simple reboot command has limited usage. The shutdown command is used instead of reboot for much more advance reboot and shutdown requirements. One such situation is a scheduled restart. Following is the syntax used to reboot your system after time defines by TIME.
$ sudo shutdown –r [TIME] [MESSAGE]
Here TIME has various formats. Simplest one is “now”, already listed in previous section, and tells system to restart immediately. Other valid formats are +m, where m is the number of minutes to wait until restart and HH:MM which specifies the TIME in 24hr clock. Below are the examples and their outputs. Optional 'MESSAGE' argument can be used to notify users prior to reboot.
Reboot your system after 5 minutes with notification message 'software update' to all logined users
$ sudo shutdown –r +5 "software update" Broadcast message from me@home-pc (/dev/pts/1) at 20:49 ... The system is going down for reboot in 5 minutes!
Reboot your system after 02:00 A.M
$ sudo shutdown –r 02:00 Broadcast message from me@home-pc (/dev/pts/1) at 20:51 ... The system is going down for reboot in 309 minutes!
Canceling Linux Restart
If you want your system to discard previously scheduled restart or shutdown you can call another shutdown command with –c option and broadcast with it a message for users about the cancelation of restart. Here is the syntax and example
$ sudo shutdown –c [MESSAGE]
The previously scheduled reboot can be canceled by system administrator by issuing another shutdown command with –c option and optional message argument.
$ sudo shutdown –c “showing how to cancel scheduled reboot ” Broadcast message from me@home-pc (/dev/pts/1) at 20:59 ... showing how to cancel scheduled reboot
Restart remote server
Simply login your server with any ssh client using server authentication information and issue any of the following commands:
$ ssh firstname.lastname@example.org /sbin/reboot $ ssh email@example.com /sbin/shutdown –r now
Restart with Init Command
Init is taken from the word initialize that is widely used to initialize/start different processes in a Linux server, so this command used as a joint with runlevel 6; a number which is set for rebooting a linux server leads to get the server rebooted. The syntax is mentioned below:
[root@test ~]# init 6 or [root@test ~]# /sbin/init 6
As many modern Linux distros like Ubuntu, Debian, Centos, Fedora etc started adopting systemd, we can use systemctl command for reboot.
The following command will reboot the system immedetialy notifiying all users:
sudo systemctl reboot
--no-wall option reboot will be performed without any notification
sudo systemctl --no-wall reboot
You can add a custom message with a reason for reboot using
sudo systemctl --message="Kernel patch" reboot
Checking reboot logs
/var/log/wtmp file records all logins and logouts. One can parse this file with last command in order to access log for reboot. Below is the last command usage and its output on my system.
# last reboot reboot system boot 3.2.0-32-generic Sun Nov 4 11:00 - 22:11 (11:11) reboot system boot 3.2.0-32-generic Sat Nov 3 20:02 - 02:10 (06:08) reboot system boot 3.2.0-32-generic Sat Nov 3 17:52 - 18:56 (01:03) reboot system boot 3.2.0-32-generic Sat Nov 3 15:37 - 17:32 (01:55) reboot system boot 3.2.0-32-generic Sat Nov 3 11:00 - 11:02 (00:01) reboot system boot 3.2.0-32-generic Sat Nov 3 10:25 - 10:58 (00:32) reboot system boot 3.2.0-32-generic Fri Nov 2 20:21 - 23:25 (03:04) reboot system boot 3.2.0-32-generic Fri Nov 2 16:57 - 18:54 (01:56) reboot system boot 3.2.0-32-generic Fri Nov 2 15:22 - 16:35 (01:13) reboot system boot 3.2.0-32-generic Fri Nov 2 12:51 - 13:37 (00:46) reboot system boot 3.2.0-32-generic Thu Nov 1 20:04 - 23:55 (03:50) reboot system boot 3.2.0-32-generic Thu Nov 1 15:18 - 23:55 (08:36) reboot system boot 3.2.0-32-generic Thu Nov 1 11:42 - 13:59 (02:16) wtmp begins Thu Nov 1 11:31:44 2012
Thanks for reading this article and please which your favorite reboot command?