fix: rewrite clawd.service on upgrade; bump to 1.2.6

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
stswangzhiping
2026-05-04 18:46:37 +08:00
parent 7761b438d3
commit 45e1370ca5
2 changed files with 49 additions and 14 deletions

View File

@@ -63,20 +63,55 @@ if [ "$NO_RESTART" = true ]; then
exit 0
fi
# Patch service file if ReadWritePaths is missing /etc/hosts or /etc/hostname
NODE_BIN=$(command -v node)
INSTALL_DIR="/opt/clawd"
CONFIG_DIR="/etc/clawd"
ENV_FILE="$CONFIG_DIR/env"
SERVICE_FILE="/etc/systemd/system/$SERVICE"
if [ -f "$SERVICE_FILE" ]; then
if ! grep -q "/etc/hosts" "$SERVICE_FILE" || ! grep -q "/etc/hostname" "$SERVICE_FILE"; then
echo "==> Patching $SERVICE_FILE: adding /etc/hosts /etc/hostname to ReadWritePaths ..."
sed -i 's|ReadWritePaths=\(.*\)/tmp\(.*\)|ReadWritePaths=\1/tmp\2 /etc/hosts /etc/hostname|' "$SERVICE_FILE"
# If the pattern didn't match (different format), append directly
if ! grep -q "/etc/hosts" "$SERVICE_FILE"; then
sed -i 's|ReadWritePaths=.*|& /etc/hosts /etc/hostname|' "$SERVICE_FILE"
fi
systemctl daemon-reload
echo "==> daemon-reload done"
fi
fi
echo "==> Writing service file: $SERVICE_FILE"
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=Claw Box Daemon
Documentation=https://git.cutos.ai/claw-daemon/clawd
After=NetworkManager.service
Wants=NetworkManager.service
[Service]
Type=simple
NotifyAccess=all
EnvironmentFile=$ENV_FILE
ExecStart=$NODE_BIN $INSTALL_DIR/bin/clawd.js
WorkingDirectory=$INSTALL_DIR
Restart=always
RestartSec=5
StartLimitInterval=300
StartLimitBurst=10
TimeoutStopSec=10
KillMode=mixed
KillSignal=SIGTERM
MemoryMax=256M
CPUQuota=50%
TasksMax=64
ProtectSystem=full
ReadWritePaths=$CONFIG_DIR /tmp /etc/hosts /etc/hostname
StandardOutput=journal
StandardError=journal
SyslogIdentifier=clawd
WatchdogSec=60
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
echo "==> daemon-reload done"
echo "==> Restarting service: $SERVICE"
systemctl restart "$SERVICE"