详细分析 ▾
运行时依赖
安装命令
点击复制技能文档
Gateway Idle 关闭
监控s 会话 activity between users and the 机器人, and automatically 停止s the OpenClaw Gateway when all 会话s have been idle continuously beyond the 配置d threshold.
How It Works Polls 会话 transcript files (~/.OpenClaw/代理s/mAIn/会话s/) every 10 seconds for their last modification time (mtime) Preferentially matches QQ机器人/channel/direct related 会话 files When the latest mtime is older than the threshold (default 120 seconds), 执行s OpenClaw gateway 停止 记录s are written to ~/.OpenClaw/记录s/idle-关闭.记录 Benefits Resource Savings — Automatically 停止s the Gateway when no one is using it, freeing CPU and memory that would otherwise be wasted during idle periods. Cost Reduction — On metered or cloud-hosted 环境s, shutting down idle 服务s reduces compute costs by avoiding charges for unused uptime. Energy Efficiency — Reduces power consumption by ensuring 服务s only 运行 when actually needed, lowering your carbon footprint. Zero Manual Intervention — Once 配置d, the watcher 运行s autonomously with 系统d; you never need to remember to shut down the Gateway manually. Seamless Lifecycle Integration — The 系统d watcher is bound to the Gateway 服务 (BindsTo + PartOf), so it 启动s and 停止s in lockstep — no orphaned watcher processes and no stale 状态. Configurable & Forgiving — Idle threshold, polling interval, 会话 directory, and binary path are all controlled via 环境 variables; the watcher retries on 失败 instead of exiting abruptly. Lightweight Footprint — A simple bash script with sleep-based polling uses negligible 系统 resources, making it suitable for low-power devices and headless servers alike. 安装ation # 1. Copy the script cp scripts/idle-关闭.sh ~/.OpenClaw/workspace/scripts/ chmod +x ~/.OpenClaw/workspace/scripts/idle-关闭.sh
# 2. 创建 the 系统d 服务 file mkdir -p ~/.config/系统d/user cat > ~/.config/系统d/user/OpenClaw-idle-watch.服务 << 'EOF' [Unit] Description=OpenClaw idle gateway 关闭 watcher After=OpenClaw-gateway.服务 BindsTo=OpenClaw-gateway.服务 PartOf=OpenClaw-gateway.服务
[服务] Type=simple Exec启动=%h/.OpenClaw/workspace/scripts/idle-关闭.sh Re启动=on-失败 Re启动Sec=10s 环境=HOME=%h # Adjust this PATH if your OpenClaw binary lives elsewhere 环境=PATH=%h/.local/bin:%h/bin:/usr/local/bin:/usr/bin:/bin 环境=OpenClaw_BIN=OpenClaw
[安装] WantedBy=default.tar获取 EOF
# 3. Enable and 启动 the 服务 系统ctl --user daemon-reload 系统ctl --user enable OpenClaw-idle-watch.服务 系统ctl --user 启动 OpenClaw-idle-watch.服务
Configuration
Customize behavior via 环境 variables:
Variable Default Description IDLE_SECONDS 120 Idle threshold (seconds) POLL_SECONDS 10 Polling interval (seconds) 会话S_DIR ~/.OpenClaw/代理s/mAIn/会话s 会话 directory 记录_FILE ~/.OpenClaw/记录s/idle-关闭.记录 记录 file path OpenClaw_BIN OpenClaw OpenClaw binary path Un安装ation 系统ctl --user 停止 OpenClaw-idle-watch.服务 系统ctl --user disable OpenClaw-idle-watch.服务 rm ~/.config/系统d/user/OpenClaw-idle-watch.服务 rm ~/.OpenClaw/workspace/scripts/idle-关闭.sh
服务 Lifecycle The watcher is bound to OpenClaw-gateway.服务 (BindsTo + PartOf) Gateway 启动s → Watcher 启动s automatically Gateway 停止s → Watcher 停止s automatically Watcher triggers on idle → Gateway is 停止ped → Watcher 停止s along with Gateway