Check System Logs First
Find why the server rebooted:
# Last boot reason
sudo last reboot
sudo last -x | grep shutdown
# Kernel message before reboot
sudo dmesg | tail -50
sudo journalctl --list-boots
sudo journalctl -b -1 -n 100
Common Causes
1. Out of Memory (OOM Killer)
Kernel kills processes and may cause instability:
sudo dmesg | grep -i "out of memory"
sudo dmesg | grep -i "oom"
sudo grep -i "killed process" /var/log/kern.log
Fix: Add RAM or optimize memory usage.
2. Hardware Issues (Dedicated/Cloud)
sudo dmesg | grep -i "error"
sudo smartctl -a /dev/sda
sudo mcelog
For VPS: contact support for host node issues.
3. Kernel Panic
sudo journalctl -k | grep -i "panic"
sudo dmesg | grep -i "panic"
Fix: update kernel or rollback changes.
4. Cron Jobs Running Reboot Commands
grep -r "reboot" /etc/cron*
grep -r "shutdown" /etc/cron*
sudo crontab -l
5. Overheating (Physical Servers)
sudo apt install lm-sensors -y
sudo sensors
6. Power Issues
VPS usually does not face power issues; contact provider support.
Prevent Random Reboots
sudo apt install linux-crashdump -y
sudo apt install monit -y
echo "#!/bin/bash
echo "$(date): System reboot detected" >> /var/log/reboot.log" | sudo tee /etc/profile.d/reboot-logger.sh
🔴 If reboots happen frequently, contact support immediately with logs.