I’ve put together a simple Bash script you can use to monitor your OpenClaw gateway. Since you’re already comfortable with HTML and PHP, you can easily run this on your server as a cron job to ensure your automation stay online.
Monitoring & Alerting Script
This script checks if the gateway process is running and if the default port (18789) is listening. If it fails, it attempts a restart and logs the event.
#!/bin/bash
# Configuration
LOG_FILE=”$HOME/.openclaw/monitor.log”
PORT=18789
RESTART_CMD=”openclaw gateway restart”
# 1. Check if the process is running
if ! pgrep -f “openclaw” > /dev/null; then
echo “$(date): ERROR – OpenClaw process not found. Attempting restart…” >> “$LOG_FILE”
$RESTART_CMD
exit 1
fi
# 2. Check if the Port is active (requires netstat or lsof)
if ! lsof -i :$PORT > /dev/null; then
echo “$(date): ERROR – Port $PORT is not responding. Restarting gateway…” >> “$LOG_FILE”
$RESTART_CMD
exit 1
fi
echo “$(date): OpenClaw is healthy.” >> “$LOG_FILE”
How to Automate It
To make this run every 5 minutes, add it to your crontab:
* Open your crontab editor: crontab -e
* Add this line at the bottom (replace /path/to/script.sh with your actual path):
*/5 * * * * /bin/bash /path/to/script.sh
Pro-Tips for Your Setup
* The “Doctor” Command: If the script keeps failing, run openclaw doctor. It’s the best way to see if a recent update broke your API configuration or environment variables.
* Dashboard Token: If you can’t access the web UI, use openclaw config get gateway.auth.token to retrieve your current access key.
* Log Cleanup: Since you mentioned creating many web pages, your logs can grow fast. Use openclaw sessions list occasionally to clear out old session data that might be slowing down the agent’s boot time.
Would you like me to help you create a PHP-based dashboard that displays this status on one of your internal web pages?
Discover more from NathanLegakis.com
Subscribe to get the latest posts sent to your email.
Leave a Reply