360 Secure SkillHub
360 安全技能中心

PM2 Gateway Restart

该 Skill 提供在 Windows 上通过 PM2 管理 OpenClaw 网关的重启、状态检查与故障恢复流程,用于解决内置命令的 FIN_WAIT_2 连接超时、端口占用和计划任务竞争问题。内容包含快速重启、完整重启、日志查看、本地端口探测以及重新注册 PM2 进程等命令,依赖 Node.js、PM2、curl 和 PowerShell 环境。

zitao666
zitao666
热度 43.77
最近更新 2026-05-11 17:36:30
分类:自动化依赖:代码执行应用场景:DevOps / 自动化脚本 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add pm2-gateway-restart
Metadata
name
pm2-gateway-restart
description
Use PM2 to reliably restart OpenClaw gateway on Windows. Use when the user wants to restart the OpenClaw gateway, fix port conflicts, or recover from a crashed gateway. This skill handles the Windows-specific issues with FIN_WAIT_2 TCP connections and scheduled task failures that plague the standard openclaw gateway start/stop commands.

PM2 Gateway Restart

This skill provides reliable gateway restart using PM2 process manager instead of the built-in openclaw gateway commands.

Why PM2?

The standard openclaw gateway start/stop commands on Windows suffer from:

  • FIN_WAIT_2 TCP connection timeouts (~60 seconds)
  • Scheduled task race conditions
  • Inconsistent startup state reporting

PM2 handles process resurrection and provides reliable restarts.

Commands

Quick Restart (Production)

pm2 restart openclaw-gateway

Wait ~15 seconds for the gateway to fully initialize, then verify with:

curl http://127.0.0.1:18789/

Full Cycle Restart (When Issues Persist)

pm2 restart openclaw-gateway; sleep 3; pm2 restart openclaw-gateway

Check Status

pm2 status
pm2 logs openclaw-gateway --lines 50

Start Gateway (If Not Running)

pm2 start "D:/Program Files/nodejs/node.exe" --name "openclaw-gateway" -- "C:/Users/Administrator/AppData/Roaming/npm/node_modules/openclaw/dist/index.js" gateway --port 18789

Troubleshooting

Port Still in Use After Restart

Wait 65 seconds for Windows TCP timeout to clear FIN_WAIT_2 connections, then:

pm2 restart openclaw-gateway

RPC Probe Fails But Gateway Listening

The RPC check may fail briefly during startup. Wait 15 seconds and retry:

curl http://127.0.0.1:18789/

PM2 Process Not Found

Reinstall the gateway process:

pm2 start "D:/Program Files/nodejs/node.exe" --name "openclaw-gateway" -- "C:/Users/Administrator/AppData/Roaming/npm/node_modules/openclaw/dist/index.js" gateway --port 18789
pm2 save

Setup (One Time)

npm install -g pm2
pm2 start "D:/Program Files/nodejs/node.exe" --name "openclaw-gateway" -- "C:/Users/Administrator/AppData/Roaming/npm/node_modules/openclaw/dist/index.js" gateway --port 18789
pm2 save