监控用户会话空闲状态,在可配置的空闲时间后自动停止 OpenClaw Gateway,以节省资源与成本。
Monitors session activity between users and the bot, and automatically stops the OpenClaw Gateway when all sessions have been idle continuously beyond the configured threshold.
~/.openclaw/agents/main/sessions/) every 10 seconds for their last modification time (mtime)openclaw gateway stop~/.openclaw/logs/idle-shutdown.logsleep-based polling uses negligible system resources, making it suitable for low-power devices and headless servers alike.bash
# 1. Copy the script
cp scripts/idle-shutdown.sh ~/.openclaw/workspace/scripts/
chmod +x ~/.openclaw/workspace/scripts/idle-shutdown.sh
# 2. Create the systemd service file
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/openclaw-idle-watch.service << 'EOF'
[Unit]
Description=OpenClaw idle gateway shutdown watcher
After=openclaw-gateway.service
BindsTo=openclaw-gateway.service
PartOf=openclaw-gateway.service
[Service]
Type=simple
ExecStart=%h/.openclaw/workspace/scripts/idle-shutdown.sh
Restart=on-failure
RestartSec=10s
Environment=HOME=%h
# Adjust this PATH if your openclaw binary lives elsewhere
Environment=PATH=%h/.local/bin:%h/bin:/usr/local/bin:/usr/bin:/bin
Environment=OPENCLAW_BIN=openclaw
[Install]
WantedBy=default.target
EOF
# 3. Enable and start the service
systemctl --user daemon-reload
systemctl --user enable openclaw-idle-watch.service
systemctl --user start openclaw-idle-watch.service
Customize behavior via environment variables:
VariableDefaultDescriptionIDLE_SECONDS120Idle threshold (seconds)POLL_SECONDS10Polling interval (seconds)SESSIONS_DIR``~/.openclaw/agents/main/sessionsSession directoryLOG_FILE``~/.openclaw/logs/idle-shutdown.logLog file pathOPENCLAW_BIN``openclawopenclaw binary path
bash
systemctl --user stop openclaw-idle-watch.service
systemctl --user disable openclaw-idle-watch.service
rm ~/.config/systemd/user/openclaw-idle-watch.service
rm ~/.openclaw/workspace/scripts/idle-shutdown.sh
openclaw-gateway.service (BindsTo + PartOf)