← 返回
未分类 中文

Openclaw Keepalive

Keep OpenClaw gateway running 24/7 on a laptop or workstation. Use when: (1) user reports gateway disconnects or crashes, (2) user asks how to make OpenClaw...
保持OpenClaw网关在笔记本或工作站上24小时全天候运行。使用场景:(1)用户报告网关断开或崩溃;(2)用户询问如何让OpenClaw保持运行...
lgy2020 lgy2020 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 492
下载
💾 1
安装
1
版本
#latest

概述

OpenClaw Gateway Keepalive

Ensure the OpenClaw gateway process stays running across reboots, crashes, sleep, and network interruptions.

Quick Start (Recommended)

Register as a system service with one command (all platforms):

openclaw gateway install

Effects:

  • ✅ Auto-start on boot — no terminal needed
  • ✅ Runs in background — survives terminal close
  • ✅ Survives screen lock — independent of user session
  • ✅ Auto-restart on crash — OS-level process supervision

Verify:

openclaw gateway status

Expected output:

  • Service: Scheduled Task (registered)
  • RPC probe: ok
  • Port: [127.0.0.1:18789]

Commands

CommandDescription
----------------------
openclaw gateway installRegister as system service (one-time)
openclaw gateway uninstallRemove system service
openclaw gateway startStart gateway manually
openclaw gateway stopStop gateway
openclaw gateway restartRestart gateway
openclaw gateway statusCheck gateway status
openclaw logs --followTail real-time logs

Platform Differences

Windows

  • Registers via Task Scheduler (schtasks)
  • Service name: OpenClaw Gateway
  • Survives screen lock and user session disconnect

macOS

  • Registers via launchd plist
  • Supports KeepAlive=true for auto-restart

Linux

  • Registers via systemd service
  • Supports Restart=on-failure policy

Prevent Sleep (Critical)

The gateway requires the computer to stay awake. Configure power settings:

Windows

# List current power plans
powercfg /list

# Never sleep when plugged in
powercfg /change standby-timeout-ac 0

# Allow display off but keep system awake
powercfg /change monitor-timeout-ac 10

macOS

# Prevent system sleep
sudo pmset -a sleep 0

# Prevent disk sleep
sudo pmset -a disksleep 0

# Allow display off but keep system running
sudo pmset -a displaysleep 10

Linux

# Disable suspend
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

Network Recovery

The gateway's WebSocket connection auto-reconnects after network interruptions using exponential backoff (1s → 2s → 4s → ...).

Manual restart if needed:

openclaw gateway restart

Troubleshooting

Gateway Unresponsive

openclaw gateway status    # Check process status
openclaw logs --follow     # View real-time logs
openclaw gateway restart   # Attempt restart

Service Not Registered

openclaw gateway install   # Re-register
openclaw gateway status    # Verify

Frequent Crashes

  1. Check logs with openclaw logs --follow for crash cause
  2. Ensure sufficient memory (Node.js process needs at least 512MB free)
  3. Check for port conflicts (default: 18789)
  4. Update to latest version

Advanced: External Process Supervisors

If gateway install is not stable enough, use external tools:

Option A: pm2 (Recommended, Cross-Platform)

npm install -g pm2
pm2 start openclaw -- gateway start
pm2 save
pm2 startup  # Generate startup command

Option B: NSSM (Windows Only)

nssm install OpenClaw "C:\Program Files\nodejs\node.exe" "openclaw gateway start"
nssm set OpenClaw AppExit Default Restart
nssm start OpenClaw

Option C: Windows Task Scheduler (Manual)

# Create auto-start task with 1-minute restart on failure
schtasks /create /tn "OpenClaw Gateway" /tr "openclaw gateway start" /sc onstart /rl highest /f

# Or use Task Scheduler GUI for finer restart policies

Healthcheck Scripts

Schedule these with cron or Task Scheduler for periodic health checks with auto-restart.

Windows (healthcheck.cmd)

@echo off
REM OpenClaw Gateway Healthcheck Script (Windows)
REM Run periodically via Task Scheduler or cron
REM Exit code 0 = healthy, 1 = failed to recover

echo [%date% %time%] Checking OpenClaw Gateway status...

openclaw gateway status >nul 2>&1
if %errorlevel% neq 0 (
    echo [%date% %time%] Gateway not responding. Attempting restart...
    openclaw gateway restart >nul 2>&1
    timeout /t 5 >nul
    openclaw gateway status >nul 2>&1
    if %errorlevel% neq 0 (
        echo [%date% %time%] CRITICAL: Gateway failed to restart!
        exit /b 1
    ) else (
        echo [%date% %time%] Gateway restarted successfully.
        exit /b 0
    )
) else (
    echo [%date% %time%] Gateway is running normally.
    exit /b 0
)

Linux/macOS (healthcheck.sh)

#!/bin/bash
# OpenClaw Gateway Healthcheck Script (Linux/macOS)
# Usage: bash healthcheck.sh - can be scheduled via cron
# Example cron: */5 * * * * /path/to/healthcheck.sh >> /var/log/openclaw-healthcheck.log 2>&1

TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')

echo "[$TIMESTAMP] Checking OpenClaw Gateway status..."

if openclaw gateway status > /dev/null 2>&1; then
    echo "[$TIMESTAMP] Gateway is running normally."
    exit 0
else
    echo "[$TIMESTAMP] Gateway not responding. Attempting restart..."
    openclaw gateway restart > /dev/null 2>&1
    sleep 5
    
    if openclaw gateway status > /dev/null 2>&1; then
        echo "[$TIMESTAMP] Gateway restarted successfully."
        exit 0
    else
        echo "[$TIMESTAMP] CRITICAL: Gateway failed to restart!"
        exit 1
    fi
fi

Save to a location of your choice and schedule:

  • Windows: Task Scheduler → Run every 5 minutes
  • Linux/macOS: /5 * /path/to/healthcheck.sh >> /var/log/openclaw-healthcheck.log 2>&1

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-02 09:54 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

it-ops-security

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装后可防止您和您的用户受到提示注入、数据泄露及恶意行为的侵害。
★ 116 📥 31,031
it-ops-security

Free Ride - Unlimited free AI

shaivpidadi
管理OpenClaw的OpenRouter免费AI模型,自动按质量排名模型,配置速率限制备用方案,并更新opencla...
★ 472 📥 78,676
it-ops-security

OpenClaw Backup

alex3alex
备份与恢复 OpenClaw 数据。适用于创建备份、设置自动备份计划、从备份恢复或管理备份轮转。处理 ~/.openclaw 目录归档并包含适当的排除规则。
★ 90 📥 31,095