Scheduling an automatic graceful reboot

m4f1aboy

Member
Feb 5, 2015
11
3
3
cPanel Access Level
Root Administrator
From time to time you have to reboot the server after kernel updates. Is there a way to schedule a one-time graceful reboot of the server for a specific time rather than staying up late at night to manually login and trigger the reboot? This would be a nonrecurring reboot.
 

vacancy

Well-Known Member
Sep 20, 2012
528
203
93
Turkey
cPanel Access Level
Root Administrator
The healthiest method is to use KernelCare.

Without the need to restart the system, your kernel will stay up to date with zero interruption.

If you do not want to use it, you can prepare a cron to restart the server every month.

Kernel updates are usually issued every 1-2 months. (changeable)

The update will not be active momentarily. The only negative side is this.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,243
463
Hello,

I agree with the previous posts. An unattended reboot is generally not a good idea, as you always want to make sure the system successfully boots again. Kernel Care is a useful third-party solution if you'd like to avoid reboots when upgrading a kernel:

CloudLinux - Main | New template

Thank you.
 

m4f1aboy

Member
Feb 5, 2015
11
3
3
cPanel Access Level
Root Administrator
Thanks for the information, it is greatly appreciated. It wouldn't be an unattended reboot; I have software that emails me alerts when the server goes down and when it comes back online, so if it doesn't come back online I can remote in and manually boot it up. It is aimed more towards me scheduling it so I don't forget to reboot late at night when needed. Thanks again, cheers.
 

CrazySerb

Active Member
Apr 1, 2015
34
12
58
Canada
cPanel Access Level
Root Administrator
@CrazySerb - cPanel doesn't have any plans to add a scheduled reboot feature into the product. Is that what you're looking for?
Yes, either via cPanel or some sort of a crontab command that we can issue at specific times of the week or whenever... as we have uptime monitors anyway, so if anything goes sideways during the reboot we'll know immediately.
 

vacancy

Well-Known Member
Sep 20, 2012
528
203
93
Turkey
cPanel Access Level
Root Administrator
You can add a command like this into the /var/spool/cron/root file.

0 5 * * * /sbin/shutdown -r now

This command will restart your server at 05:00 am.

UPDATE: Command edit.
 
Last edited:
  • Like
Reactions: Spirogg

ffeingol

Well-Known Member
PartnerNOC
Nov 9, 2001
713
280
363
cPanel Access Level
DataCenter Provider
You can add a command like this into the /var/spool/cron/root file.

0 5 * * * /sbin/shutdown -h now

This command will restart your server at 05:00 am.
You don't want that command. -h is halt (or shutdown). At a minimum you want shutdown -r now in the cron (-r is reboot).

The last parameter (now) is the time that you want the reboot. So you can simply do something like:

shutdown -r 23:50 and that will schedule a reboot at 23:50. man shutdown will give you all the details.
 

CrazySerb

Active Member
Apr 1, 2015
34
12
58
Canada
cPanel Access Level
Root Administrator
You don't want that command. -h is halt (or shutdown). At a minimum you want shutdown -r now in the cron (-r is reboot).

The last parameter (now) is the time that you want the reboot. So you can simply do something like:

shutdown -r 23:50 and that will schedule a reboot at 23:50. man shutdown will give you all the details.
That will do!

So if I was to add it to cron, it would be to once a day sort of a job?

Something like

0 0 * * * /sbin/shutdown -r 06:00

So that at midnight it schedules a reboot at 6am?

Would that be the equivalent of this:

0 6 * * * /sbin/shutdown -r now

??
 

CrazySerb

Active Member
Apr 1, 2015
34
12
58
Canada
cPanel Access Level
Root Administrator
Yes, those appear to do the same thing. No idea, why you would want to reboot daily, however.
Just a temporary fix for certain server / software package issues until they are resolved on the software level (certain processes ending up being locked up and only a reboot fixing them all properly). That's all.