A bash script that monitors critical services and automatically restarts them if they fail, ensuring high availability and preventing service downtime.
- Service Monitoring: Checks if critical services are running (SSH, Apache, MySQL, Nginx, Docker)
- Automatic Restart: Attempts to restart failed services automatically
- Detailed Logging: Records all activities with timestamps
- Status Reporting: Clear status messages for each service
- Configurable: Easy to add or remove services to monitor
- SSH - Secure shell access
- Apache2 - Web server
- MySQL - Database server
- Nginx - Web server/proxy
- Docker - Container runtime
- Clone this repository:
git clone https://github.com/scriptpy/service-monitor-script.git
cd service-monitor-script- Make the script executable:
chmod +x service-monitor-complete.sh- Run the script:
./service-monitor-complete.shThe script will:
- Check each service in the SERVICES array
- Report which services are running or failed
- Attempt to restart any failed services
- Log all activities to
/var/log/service-monitor.log - Provide clear status messages
You can modify these variables in the script:
SERVICES=("ssh" "apache2" "mysql" "nginx" "docker")- Services to monitorLOG_FILE="/var/log/service-monitor.log"- Log file location
All activities are logged with timestamps. Check the log file:
tail -f /var/log/service-monitor.logTo monitor additional services, edit the SERVICES array:
SERVICES=("ssh" "apache2" "mysql" "nginx" "docker" "postgresql" "redis")This script is part of my DevOps learning journey. I'm building real solutions as I learn, and I welcome feedback and contributions!
Need a personalized version? Contact me! I can customize this script for your specific needs, add web dashboards, or multi-server monitoring.
This README was written with AI assistance as part of my learning journey. The script itself was built through hands-on learning and real-world problem solving.
This project is open source and available under the MIT License.
If this script helped you, consider:
- ⭐ Starring this repository
- 🐛 Reporting issues
- 💡 Suggesting improvements
- ☕ Buy me a coffee (Crypto donations welcome!)
Crypto Addresses:
Bitcoin: bc1q60fgpcmem6t9j8u0qyu9yccccyf0zh7u8mqfsd
Ethereum: 0xC98765ea54BE48a9a0dFA239890b92CaA30E2464
Part of my DevOps Learning Journey - Building real solutions while learning. Follow my progress and join the journey! 🚀