#!/usr/bin/env bash set -euo pipefail # Helper to generate a recommended systemd service content for openclaw gateway SERVICE_PATH="/etc/systemd/system/openclaw-gateway.service" cat <<'SERVICE' > ./openclaw-gateway.service.suggested [Unit] Description=OpenClaw Gateway After=network.target [Service] Type=simple User=openclaw2 WorkingDirectory=/home/openclaw2/openclaw2 # Ensure PATH includes node and /usr/local/bin where npm global binaries live Environment="PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" # ExecStart should point to gateway entrypoint script inside repo ExecStart=/home/openclaw2/openclaw2/scripts/gateway-entrypoint.sh Restart=on-failure RestartSec=5s LimitNOFILE=65536 [Install] WantedBy=multi-user.target SERVICE echo "Suggested service saved to ./openclaw-gateway.service.suggested" echo "Commands to apply (run as sudo):" cat <<'CMDS' sudo mv ./openclaw-gateway.service.suggested /etc/systemd/system/openclaw-gateway.service sudo systemctl daemon-reload sudo systemctl enable --now openclaw-gateway.service # If multiple instances running, list and kill duplicates: # sudo pgrep -a -f openclaw | xargs -r sudo kill sudo systemctl status openclaw-gateway.service CMDS