⏲️ 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
- SSH into your VPS:
ssh root@your-server-ip
- Open the root user’s crontab:
crontab -e
- Add the following line to reboot the server every Sunday at 3:30 AM:
30 3 * * 0 /sbin/reboot
- Save and exit:
- If using
nano
: PressCTRL + X
, thenY
, thenEnter
- If using
vi
: PressEsc
, type:wq
, thenEnter
🧰 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

⏰ Step 3: Schedule the Health Check Script
- Edit the crontab:
crontab -e
- 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
Only logged-in users can submit reports.
Discover more from HelpZone
Subscribe to get the latest posts sent to your email.