How to Schedule Automatic Server Restarts on your Gridpane Linux server

As tech guys/gals, we know that 99% of tech issues can be solved with a simple device reset. And there’s no real benefit of leaving a server unrebooted for long periods of time other than for uptime stats (assuming you can afford the few minutes of downtime during the restart, of course). To me, this is reason enough to set an auto-restart every week, just to clear out the bugs and cobwebs that accumulated during the week.

I use Gridpane to manage my servers (which run Ubuntu 22 on my VPS server), so this guide is written with this in mind; however, I believe the steps below can be applicable to any Linux server.

Benefits of a Server Restart

In case you didn’t already know this, server restarts are helpful for:

  • System Health: Reboots clear memory, reduce fragmentation, and optimize system resources.
  • Patch Management: Some updates require reboots to take effect, helping ensure security and stability.
  • Performance Optimization: Particularly useful for applications with heavy resource usage, as it refreshes services.

Scheduling Automatic Restarts on Linux Servers

Regardless whether you’re managing your server with Gridpane, ServerAvatar, cPanel, DirectAdmin, or even without a server management software, the process for scheduling a restart on Linux is similar across distributions that use cron.

Prerequisites

  • Root Privileges: You’ll need sudo or root permissions to edit crontab configurations.
  • FTP software: I use WinSCP, but I believe any server file management software with SSH capabilities should work (you can use FTP but SSH is more secure). Alternatively, you can use the terminal, but if you knew how to do that, then you wouldn’t need this guide in the first place.

How to Schedule a Weekly Restart on Sunday at Midnight

Step 1: Open the Crontab File

Open your preferred FTP software (I use WinSCP) with root access, and navigate to the folder /etc/ and open the crontab file with your text editor.
(this file doesn’t have a suffix like .txt, it’s just crontab)

Step 2: Add the Restart Command:

Add the following line at the bottom of the file, then save and exit:

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

Here are other options you can use:

  • Daily Restart at Midnight
    0 0 * * * root /sbin/shutdown -r now
  • Weekly Restart on Monday Midnight
    0 0 * * 1 root /sbin/shutdown -r now
  • Weekly Restart on Tuesday Midnight
    0 0 * * 2 root /sbin/shutdown -r now
  • Weekly Restart on Wednesday Midnight
    0 0 * * 3 root /sbin/shutdown -r now
  • Weekly Restart on Thursday Midnight
    0 0 * * 4 root /sbin/shutdown -r now
  • Weekly Restart on Friday Midnight
    0 0 * * 5 root /sbin/shutdown -r now
  • Weekly Restart on Saturday Midnight
    0 0 * * 6 root /sbin/shutdown -r now
  • Weekly Restart on Sunday Midnight
    0 0 * * 0 root /sbin/shutdown -r now
  • Monthly Restart on the First of Every Month at Midnight
    0 0 1 * * root /sbin/shutdown -r now

 

Explanation:

  • 0 0 * * 0: Runs at 00:00 on Sunday.
  • root: The user executing the command.
  • /sbin/shutdown -r now: Reboots the system immediately.

Final Thoughts

Automating server restarts is a simple way to maintain server health and performance. Just remember to monitor the first few scheduled reboots to ensure everything operates smoothly.

Hope this helps!

 

Thumbnail pic courtesy of Freepik

Share via
Copy link
Powered by Social Snap