Spaces:
Running
Running
Service Monitoring & Auto-Recovery Guide
This guide explains how to ensure the Visa Photo Maker services (Frontend & Backend) remain online and automatically recover from crashes or stops.
1. Watchdog Script
A simple bash script scripts/watchdog.sh has been created to check the health of your services every minute.
- Location:
scripts/watchdog.sh - What it does:
- Checks if Port 13002 (Backend) is open.
- Checks if Port 13001 (Frontend) is open.
- If a port is closed, it triggers
pm2 restart <app_name>. - Logs all incidents to
watchdog.login the project root.
2. Setup Instructions
Step 1: Make Script Executable
Run this in your terminal:
chmod +x scripts/watchdog.sh
Step 2: Test the Script
Run it manually once to make sure it works (it should be silent if everything is OK):
./scripts/watchdog.sh
Step 3: Enable Auto-Run (Crontab)
To make it run every minute automatically:
Open your crontab editor:
crontab -eAdd the following line at the bottom of the file: (Update the path if you moved the project)
* * * * * /home/ubuntu/code/visa_photo_maker/scripts/watchdog.shSave and exit (usually
Ctrl+O,Enter,Ctrl+Xif using nano).
3. Viewing Logs
To see if the watchdog has restarted anything, check the log file:
tail -f watchdog.log
4. Other Protections Enabled
Besides this script, the following PM2 protections are already active:
- Memory Limit: Backend restarts if it exceeds 2GB RAM.
- Backoff Restart: If the app crashes repeatedly, PM2 waits 100ms+ before restarting to prevent CPU spikes.
- 4 Workers: The backend runs 4 parallel instances to utilize the quad-core CPU.