This is an automatic system for Linux. It checks if your process is running and sends status to a monitoring server.
This project helps you monitor your processes. It can:
- 🔍 Check if process is running - it looks for your process on the system
- 📊 Save logs - it writes all checks and changes to a log file
- 🔄 Detect restarts - it knows when your process restarts (PID changes)
- 🌐 Send data to server - it sends HTTP requests to your monitoring server
- ⏰ Work automatically - it checks every minute using systemd timer
This project has 4 files:
- script.sh - main monitoring script that checks the process
- test-monitoring.service - systemd service file to run the script
- test-monitoring.timer - systemd timer file for automatic running
- install_monitoring.sh - installation script (makes setup easy)
- OS: Linux with systemd (Ubuntu, Debian, CentOS, Fedora, etc.)
- Access: root user access for installation
- Programs:
bashcurl(for sending requests to monitoring server)systemd(for automatic running)
git clone <repository-url>
cd monitoring_serviceBefore installation, open file script.sh and change these settings:
PROCESS_NAME="test" # Name of your process
PROCESS_PATH="/usr/local/bin/test" # Full path to your process
MONITORING_URL="https://test.com/monitoring/test/api" # URL of your monitoring server
LOG_FILE="/var/log/monitoring.log" # Path to log filesudo ./install_monitoring.shThe installation script will do everything for you:
- Create needed directories
- Copy monitoring script to
/usr/local/bin/test-monitor.sh - Create log file
/var/log/monitoring.log - Install systemd service and timer files
- Start the monitoring system
# Check if timer is running
sudo systemctl status test-monitoring.timer
# Check last service runs
sudo systemctl status test-monitoring.service# View log file
sudo tail -f /var/log/monitoring.log
# View systemd logs
sudo journalctl -u test-monitoring.service -f# Stop monitoring
sudo systemctl stop test-monitoring.timer
# Start monitoring
sudo systemctl start test-monitoring.timer
# Restart monitoring
sudo systemctl restart test-monitoring.timer
# Disable automatic start on boot
sudo systemctl disable test-monitoring.timer
# Enable automatic start on boot
sudo systemctl enable test-monitoring.timer# Run check by hand
sudo /usr/local/bin/test-monitor.sh
# Or use systemd
sudo systemctl start test-monitoring.serviceHere is what happens:
- Systemd Timer starts when your computer boots. It runs every minute.
- Systemd Service runs the monitoring script each time the timer activates.
- Monitoring Script does these things:
- Looks for the process by name and path
- Compares current PID with previous PID (saved in
/tmp/test_monitor.pid) - Writes to log if process restarted (PID changed)
- Sends HTTP request to monitoring server
- Writes results to log file
The logs look like this:
2025-10-25 14:30:45 - Process test restarted. Old PID: 1234, New PID: 5678
2025-10-25 14:30:45 - Successfully contacted monitoring server at https://test.com/monitoring/test/api
2025-10-25 14:31:45 - Failed to contact monitoring server at https://test.com/monitoring/test/api
If you want to remove this system:
# Stop and disable timer
sudo systemctl stop test-monitoring.timer
sudo systemctl disable test-monitoring.timer
# Delete systemd files
sudo rm /etc/systemd/system/test-monitoring.service
sudo rm /etc/systemd/system/test-monitoring.timer
# Delete script
sudo rm /usr/local/bin/test-monitor.sh
# Delete PID file
sudo rm /tmp/test_monitor.pid
# Reload systemd
sudo systemctl daemon-reloadYou can keep the log file or delete it:
sudo rm /var/log/monitoring.logIf you want to monitor a different process:
-
Edit file
script.sh:- Change
PROCESS_NAMEto your process name - Change
PROCESS_PATHto your process path - Change
MONITORING_URLto your server URL
- Change
-
Install again:
sudo systemctl stop test-monitoring.timer
sudo ./install_monitoring.shBy default, the system checks every minute. To change this:
- Edit file
test-monitoring.timer - Change line
OnUnitActiveSec(for example,5minfor 5 minutes) - Install again:
sudo cp test-monitoring.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl restart test-monitoring.timer# Check errors in systemd logs
sudo journalctl -xe -u test-monitoring.timer
sudo journalctl -xe -u test-monitoring.serviceIf there are problems writing to /var/log/monitoring.log, the script will automatically use /tmp/monitoring.log.
Make sure that:
PROCESS_PATHis correct path to your process file- Your process is really running:
ps aux | grep <process_name>
- System runs as root user (needs this for system access)
- Log files can be read by all users (chmod 666)
- HTTP requests have no authentication (you can add it if you need)
This project is open-source.
Dmitrii Savchenko
📝 Important: Remember to change settings in script.sh before installation!