Keeping OpenClaw Running 24/7: Process Management Guide
The definitive guide to keeping your OpenClaw agent alive and healthy, comparing systemd, pm2, and tmux for always-on process management.
#The Goal: Never Miss a Message
Your OpenClaw agent should be always-on — ready to respond to messages, run cron jobs, and execute heartbeat checks. If it crashes, it should restart automatically. If your server reboots, it should come back on its own.
This guide covers three approaches, from simplest to most flexible.
#Comparison: systemd vs pm2 vs tmux
| Feature | systemd | pm2 | tmux |
|---|---|---|---|
| Auto-restart on crash | ✅ | ✅ | ❌ |
| Start on boot | ✅ | ✅ | ❌ (needs script) |
| Log management | ✅ journalctl | ✅ Built-in | ❌ Manual |
| Resource monitoring | Basic | ✅ Dashboard | ❌ |
| Ease of setup | Medium | Easy | Easiest |
| Best for | Production servers | Node.js developers | Quick testing |
| Requires root | Yes | No | No |
Our recommendation: Use systemd for production VPS/servers. Use pm2 if you want a simpler Node.js-native solution. Use tmux only for testing or temporary setups.
#Option 1: systemd (Recommended for Production)
systemd is built into every modern Linux distribution. It's the standard way to manage services.
#Create the Service File
sudo nano /etc/systemd/system/openclaw.service[Unit]Description=OpenClaw AI AgentAfter=network-online.targetWants=network-online.target[Service]Type=simpleUser=openclawWorkingDirectory=/home/openclaw/.openclaw/workspaceExecStart=/usr/bin/openclaw gateway start --foregroundRestart=alwaysRestartSec=10# LoggingStandardOutput=journalStandardError=journalSyslogIdentifier=openclaw# EnvironmentEnvironment=NODE_ENV=production# Security hardening (optional but recommended)NoNewPrivileges=trueProtectSystem=strictReadWritePaths=/home/openclaw# Resource limitsMemoryMax=1GCPUQuota=80%[Install]WantedBy=multi-user.target#Enable and Start
# Reload systemdsudo systemctl daemon-reload# Enable (start on boot)sudo systemctl enable openclaw# Start nowsudo systemctl start openclaw# Check statussudo systemctl status openclaw#Common Commands
# Start / stop / restartsudo systemctl start openclawsudo systemctl stop openclawsudo systemctl restart openclaw# Check if runningsystemctl is-active openclaw# View logs (live)sudo journalctl -u openclaw -f# View logs (last 100 lines)sudo journalctl -u openclaw -n 100# View logs (since today)sudo journalctl -u openclaw --since today# View logs (last hour)sudo journalctl -u openclaw --since "1 hour ago"#Option 2: pm2 (Node.js Process Manager)
pm2 is a popular process manager built specifically for Node.js applications. It's simpler than systemd and doesn't require root.
#Install pm2
npm install -g pm2#Start OpenClaw with pm2
# Start OpenClawpm2 start "openclaw gateway start --foreground" --name openclaw# Save the process list (for auto-restart)pm2 save# Set up pm2 to start on bootpm2 startup# Follow the printed command (copy/paste it)#Common Commands
# Statuspm2 status# Logs (live)pm2 logs openclaw# Restartpm2 restart openclaw# Stoppm2 stop openclaw# Dashboard (live monitoring)pm2 monit#pm2 Ecosystem File (Advanced)
For more control, create an ecosystem file:
nano ecosystem.config.jsmodule.exports = { apps: [{ name: 'openclaw', script: 'openclaw', args: 'gateway start --foreground', cwd: '/home/openclaw/.openclaw/workspace', restart_delay: 10000, max_restarts: 50, max_memory_restart: '512M', env: { NODE_ENV: 'production' }, // Log configuration log_date_format: 'YYYY-MM-DD HH:mm:ss', error_file: '/home/openclaw/.pm2/logs/openclaw-error.log', out_file: '/home/openclaw/.pm2/logs/openclaw-out.log', merge_logs: true, log_type: 'json' }]};pm2 start ecosystem.config.jspm2 save#Option 3: tmux (Quick and Simple)
tmux keeps OpenClaw running in a detachable terminal session. Simple but no auto-restart.
# Start a new tmux sessiontmux new -s openclaw# Start OpenClaw inside the sessionopenclaw gateway start# Detach from the session (Ctrl+B, then D)# OpenClaw keeps running in the background# Reattach latertmux attach -t openclawtmux sessions don't survive server reboots, and they won't auto-restart if OpenClaw crashes. Only use tmux for testing or temporary setups.
#Making tmux Slightly More Robust
You can add a simple restart loop:
tmux new -s openclawwhile true; do openclaw gateway start; echo "Crashed, restarting in 10s..."; sleep 10; done#Log Rotation
Logs can fill your disk over time. Set up rotation regardless of which method you use.
#For systemd (journalctl)
# Set maximum journal sizesudo nano /etc/systemd/journald.confAdd:
SystemMaxUse=500MMaxRetentionSec=7daysudo systemctl restart systemd-journald#For pm2
# Install log rotation modulepm2 install pm2-logrotate# Configurepm2 set pm2-logrotate:max_size 50Mpm2 set pm2-logrotate:retain 7pm2 set pm2-logrotate:compress true#Monitoring and Alerting
#Simple Monitoring Script
Create a script that checks if OpenClaw is running and alerts you:
nano ~/check-openclaw.sh#!/bin/bashif ! systemctl is-active --quiet openclaw; then echo "OpenClaw is DOWN at $(date)" >> /home/openclaw/openclaw-alerts.log # Optional: send a notification # curl -s "https://api.telegram.org/bot$BOT_TOKEN/sendMessage?chat_id=$CHAT_ID&text=⚠️ OpenClaw is down!"fichmod +x ~/check-openclaw.sh# Add to crontab (check every 5 minutes)crontab -e# Add: */5 * * * * /home/openclaw/check-openclaw.sh#Resource Monitoring
# Check memory usageps aux | grep openclaw# Check with systemdsystemctl status openclaw | grep Memory# With pm2pm2 monit#Handling Updates
#systemd
sudo systemctl stop openclawnpm update -g openclawsudo systemctl start openclaw#pm2
pm2 stop openclawnpm update -g openclawpm2 restart openclaw#Troubleshooting
#OpenClaw Keeps Crashing
# Check crash logssudo journalctl -u openclaw --since "1 hour ago" | grep -i error# Common causes:# - API key expired or rate limited# - Out of memory (check with: free -h)# - Network issues (check with: ping api.anthropic.com)#High CPU Usage
# Check what's happeningtop -p $(pgrep -f openclaw)# Common causes:# - Heartbeat set too frequently# - Runaway cron job# - Too many concurrent sub-agents#Service Won't Start After Reboot
# Verify it's enabledsystemctl is-enabled openclaw# Check for boot errorssudo journalctl -u openclaw -b# Re-enable if neededsudo systemctl enable openclaw#Next Steps
- Security Hardening — Lock down your server
- Cost Optimization — Optimize heartbeat and model usage
- Heartbeat & Cron Configuration — Fine-tune scheduling