Why Schedule a Reboot?
In a server environment or a headless Ubuntu workstation, you often need to install kernel updates or apply heavy system configurations that require a full system restart. However, if you are working during active business hours, restarting the server immediately will disconnect all active users and interrupt database queries. Instead of staying awake until 3:00 AM to manually reboot the machine, you can use the built-in shutdown command in the Linux terminal to schedule an automated reboot for a future time, ensuring minimal downtime for your users.
Using the shutdown -r Command
The shutdown command handles both powering off and restarting the machine. To schedule a restart, you must use the -r (reboot) flag.
- Open your Terminal (Ctrl + Alt + T), or connect to your Ubuntu server via SSH.
- The syntax requires root privileges, the
-rflag, and a time variable. The time variable can be a specific hour and minute (in 24-hour format) or a relative number of minutes from now.
Method A: Reboot at a Specific Time
To schedule the server to reboot at exactly 3:00 AM local time, use the following command:
sudo shutdown -r 03:00- Press Enter and provide your administrator password. The terminal will confirm that the reboot has been scheduled.
Method B: Reboot After a Delay
If you just sent out a warning email to your team and want to give them exactly 45 minutes to save their work before the server bounces, use the + symbol:
sudo shutdown -r +45- Press Enter. The system will count down 45 minutes and then automatically restart.
Adding a Warning Message
It is best practice to broadcast a warning message to any users currently logged into the server via SSH. You can append a custom message to the end of your command in quotes:
sudo shutdown -r +15 "Applying kernel updates. System going down in 15 mins!"
How to Cancel a Scheduled Reboot
If you made a mistake or need to delay the maintenance window, you can easily abort any pending shutdown or reboot command.
- Simply run the shutdown command with the
-c(cancel) flag: sudo shutdown -c- The scheduled reboot is instantly canceled, and the server will remain online.