Browse guides
Back to Guides
BeginnerConfigurationOpenClaw

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.

Sam Okafor20 minutes

#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

Featuresystemdpm2tmux
Auto-restart on crash✅✅❌
Start on boot✅✅❌ (needs script)
Log management✅ journalctl✅ Built-in❌ Manual
Resource monitoringBasic✅ Dashboard❌
Ease of setupMediumEasyEasiest
Best forProduction serversNode.js developersQuick testing
Requires rootYesNoNo

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.


systemd is built into every modern Linux distribution. It's the standard way to manage services.

#Create the Service File

bash
sudo nano /etc/systemd/system/openclaw.service
ini
[Unit]
Description=OpenClaw AI Agent
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=openclaw
WorkingDirectory=/home/openclaw/.openclaw/workspace
ExecStart=/usr/bin/openclaw gateway start --foreground
Restart=always
RestartSec=10
# Logging
StandardOutput=journal
StandardError=journal
SyslogIdentifier=openclaw
# Environment
Environment=NODE_ENV=production
# Security hardening (optional but recommended)
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/home/openclaw
# Resource limits
MemoryMax=1G
CPUQuota=80%
[Install]
WantedBy=multi-user.target

#Enable and Start

bash
# Reload systemd
sudo systemctl daemon-reload
# Enable (start on boot)
sudo systemctl enable openclaw
# Start now
sudo systemctl start openclaw
# Check status
sudo systemctl status openclaw

#Common Commands

bash
# Start / stop / restart
sudo systemctl start openclaw
sudo systemctl stop openclaw
sudo systemctl restart openclaw
# Check if running
systemctl 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

bash
npm install -g pm2

#Start OpenClaw with pm2

bash
# Start OpenClaw
pm2 start "openclaw gateway start --foreground" --name openclaw
# Save the process list (for auto-restart)
pm2 save
# Set up pm2 to start on boot
pm2 startup
# Follow the printed command (copy/paste it)

#Common Commands

bash
# Status
pm2 status
# Logs (live)
pm2 logs openclaw
# Restart
pm2 restart openclaw
# Stop
pm2 stop openclaw
# Dashboard (live monitoring)
pm2 monit

#pm2 Ecosystem File (Advanced)

For more control, create an ecosystem file:

bash
nano ecosystem.config.js
javascript
module.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'
}]
};
bash
pm2 start ecosystem.config.js
pm2 save

#Option 3: tmux (Quick and Simple)

tmux keeps OpenClaw running in a detachable terminal session. Simple but no auto-restart.

bash
# Start a new tmux session
tmux new -s openclaw
# Start OpenClaw inside the session
openclaw gateway start
# Detach from the session (Ctrl+B, then D)
# OpenClaw keeps running in the background
# Reattach later
tmux attach -t openclaw

tmux 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:

bash
tmux new -s openclaw
while 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)

bash
# Set maximum journal size
sudo nano /etc/systemd/journald.conf

Add:

ini
SystemMaxUse=500M
MaxRetentionSec=7day
bash
sudo systemctl restart systemd-journald

#For pm2

bash
# Install log rotation module
pm2 install pm2-logrotate
# Configure
pm2 set pm2-logrotate:max_size 50M
pm2 set pm2-logrotate:retain 7
pm2 set pm2-logrotate:compress true

#Monitoring and Alerting

#Simple Monitoring Script

Create a script that checks if OpenClaw is running and alerts you:

bash
nano ~/check-openclaw.sh
bash
#!/bin/bash
if ! 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!"
fi
bash
chmod +x ~/check-openclaw.sh
# Add to crontab (check every 5 minutes)
crontab -e
# Add: */5 * * * * /home/openclaw/check-openclaw.sh

#Resource Monitoring

bash
# Check memory usage
ps aux | grep openclaw
# Check with systemd
systemctl status openclaw | grep Memory
# With pm2
pm2 monit

#Handling Updates

#systemd

bash
sudo systemctl stop openclaw
npm update -g openclaw
sudo systemctl start openclaw

#pm2

bash
pm2 stop openclaw
npm update -g openclaw
pm2 restart openclaw

#Troubleshooting

#OpenClaw Keeps Crashing

bash
# Check crash logs
sudo 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

bash
# Check what's happening
top -p $(pgrep -f openclaw)
# Common causes:
# - Heartbeat set too frequently
# - Runaway cron job
# - Too many concurrent sub-agents

#Service Won't Start After Reboot

bash
# Verify it's enabled
systemctl is-enabled openclaw
# Check for boot errors
sudo journalctl -u openclaw -b
# Re-enable if needed
sudo systemctl enable openclaw

#Next Steps

Skip the trial and error

ClawDocx members get 500+ tested prompts, ready-to-install SKILL.md files, SOUL.md and CLAUDE.md templates, and an MCP server so your agent can pull all of it directly while it works.