How To Set Up For VPS Automatic Reboots and Health Checks

⏲️ Estimated reading time: 2 min

Set Up For VPS Automatic Reboots and Health Checks with Cron

Ensure your VPS remains stable and responsive by setting up automatic reboots and health checks using Cron. This guide shows you how to automate routine maintenance and detect service failures on AlmaLinux 9 with cPanel.


✨ Keep your VPS running smoothly by setting up automatic reboots and health monitoring using Cron. Learn how to schedule reboots and restart critical services like Apache or MySQL if they go down.


🔧 Why Automate VPS Maintenance?

Scheduled reboots and health checks:

  • Prevent downtime from memory leaks or stale processes
  • Automatically recover failed services
  • Minimize the need for manual intervention

⏱️ Step 1: Schedule Automatic Reboots with Cron

  1. SSH into your VPS:
ssh root@your-server-ip
  1. Open the root user’s crontab:
crontab -e
  1. Add the following line to reboot the server every Sunday at 3:30 AM:
30 3 * * 0 /sbin/reboot
  1. Save and exit:
  • If using nano: Press CTRL + X, then Y, then Enter
  • If using vi: Press Esc, type :wq, then Enter

🧰 Step 2: Create a Health Check Script

This script will monitor Apache and MySQL, restarting them if they are down and sending email alerts.

A. Install mailx (for alerts)

dnf install mailx -y

B. Create the health check script:

nano /usr/local/bin/healthcheck.sh

Paste this content:

#!/bin/bash

# Check Apache
if ! systemctl is-active --quiet httpd; then
    echo "Apache was down. Restarted." | mail -s "Apache Restarted on VPS" your@email.com
    systemctl restart httpd
fi

# Check MySQL
if ! systemctl is-active --quiet mysqld; then
    echo "MySQL was down. Restarted." | mail -s "MySQL Restarted on VPS" your@email.com
    systemctl restart mysqld
fi

C. Make it executable:

chmod +x /usr/local/bin/healthcheck.sh

How To Set Up For VPS Automatic Reboots and Health Checks

⏰ Step 3: Schedule the Health Check Script

  1. Edit the crontab:
crontab -e
  1. Add this line to run the health check every 5 minutes:
*/5 * * * * /usr/local/bin/healthcheck.sh

🔍 Optional Enhancements

  • Use a secure token if triggering scripts via URL
  • Log output to a file for audit purposes
  • Extend script to monitor more services (e.g., NGINX, PostgreSQL)

📩 Do you have questions or suggestions? Leave a comment or contact us!

🏷️ Tags: VPS, AlmaLinux, cPanel, Cron, Reboot, Health Check, Server Monitoring, Automation, Apache, MySQL

📣 Hashtags: #VPS, #AlmaLinux, #cPanel, #CronJobs, #ServerAutomation, #HealthCheck, #Apache, #MySQL, #DevOps, #LinuxTips

Report an issue (max 5 words):

Only logged-in users can submit reports.


Discover more from HelpZone

Subscribe to get the latest posts sent to your email.

Want to support us? Let friends in on the secret and share your favorite post!

Photo of author

Flo

How To Set Up For VPS Automatic Reboots and Health Checks

Published

Welcome to HelpZone.blog, your go-to hub for expert insights, practical tips, and in-depth guides across technology, lifestyle, business, entertainment, and more! Our team of passionate writers and industry experts is dedicated to bringing you the latest trends, how-to tutorials, and valuable advice to enhance your daily life. Whether you're exploring WordPress tricks, gaming insights, travel hacks, or investment strategies, HelpZone is here to empower you with knowledge. Stay informed, stay inspired because learning never stops! 🚀

👍 Like us on Facebook!

Closing in 10 seconds

Leave a Reply