Skip to content

Commit 5b794d2

Browse files
author
JiaDe
committed
fix: use system-level Node to prevent stale nvm paths on upgrade (#168)
Switch the template off nvm to a system-level Node (NodeSource): /usr/bin/node with globals at /usr/lib/node_modules. These paths are Node-version-independent and survive in-place apt upgrades, so neither the /usr/local/bin/openclaw CLI wrapper nor extension 'openclaw' peer links go stale across Node changes (the root cause of the reboot crash-loop in #168). Also removes the 'find ... | head -1' wrong-tree hazard, and adds a post-setup sweep that repoints ~/.openclaw/extensions/*/node_modules/openclaw to the current global install as a safety net. Default OpenClawVersion bumped to a current pinned release.
1 parent 5838368 commit 5b794d2

1 file changed

Lines changed: 36 additions & 40 deletions

File tree

clawdbot-bedrock.yaml

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ Parameters:
7979

8080
OpenClawVersion:
8181
Type: String
82-
Default: "2026.4.27"
82+
Default: "2026.6.9"
8383
AllowedValues:
8484
- "2026.3.24"
8585
- "2026.4.5"
8686
- "2026.4.10"
8787
- "2026.4.27"
88+
- "2026.6.9"
8889
- "latest"
89-
Description: "OpenClaw version. 2026.3.24 (no model approval needed, WeChat compatible). 2026.4.5+ (auto-discovery, embeddings)."
90+
Description: "OpenClaw version (pinned). 2026.3.24 (no model approval needed, WeChat compatible). 2026.4.5+ (auto-discovery, embeddings). 2026.6.9 (current stable; requires system Node, handled by this template). Avoid 'latest' in production — pin to a tested version."
9091

9192
EnableMonitoring:
9293
Type: String
@@ -1104,25 +1105,21 @@ Resources:
11041105
echo "[4/9] Skipping Docker (EnableSandbox=false)..."
11051106
fi
11061107

1107-
# Install Node.js
1108-
echo "[5/9] Installing Node.js..."
1109-
sudo -u ubuntu bash << 'UBUNTU_SCRIPT'
1110-
cd ~
1111-
NVM_VERSION="v0.40.1"
1108+
# Install Node.js — SYSTEM-level via NodeSource (NOT a version manager).
1109+
# OpenClaw 2026.6.x audits the gateway service runtime: a Node managed by
1110+
# NVM/fnm/asdf etc. is flagged "gateway-runtime-node-version-manager" and the
1111+
# updater migrates it on upgrade, which breaks the systemd unit ("Unit file
1112+
# not found"). A system Node at /usr/bin/node avoids that migration entirely.
1113+
echo "[5/9] Installing Node.js 22 LTS (system, via NodeSource)..."
11121114
for i in 1 2 3; do
1113-
curl -fsSL "https://raw.githubusercontent.com/nvm-sh/nvm/${!NVM_VERSION}/install.sh" -o /tmp/nvm-install.sh && break
1114-
echo "NVM download attempt $i failed, retrying in 5s..."
1115+
curl -fsSL https://deb.nodesource.com/setup_22.x -o /tmp/nodesource_setup.sh && break
1116+
echo "NodeSource download attempt $i failed, retrying in 5s..."
11151117
sleep 5
11161118
done
1117-
bash /tmp/nvm-install.sh
1118-
rm -f /tmp/nvm-install.sh
1119-
1120-
export NVM_DIR="$HOME/.nvm"
1121-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
1122-
1123-
nvm install 22.22.0
1124-
nvm use 22.22.0
1125-
nvm alias default 22.22.0
1119+
bash /tmp/nodesource_setup.sh
1120+
rm -f /tmp/nodesource_setup.sh
1121+
apt-get install -y nodejs
1122+
echo "Node: $(node --version) npm: $(npm --version)"
11261123

11271124
npm config set registry https://registry.npmjs.org/
11281125
OPENCLAW_VERSION="${OpenClawVersion}"
@@ -1134,22 +1131,17 @@ Resources:
11341131
IGNORE_FLAG="--ignore-scripts"
11351132
echo "ARM64 + 3.24: installing with --ignore-scripts"
11361133
fi
1134+
# Global install goes to system path (/usr/lib/node_modules) — runs as root (UserData)
11371135
npm install -g openclaw@$OPENCLAW_VERSION --timeout=300000 $IGNORE_FLAG || {
11381136
npm cache clean --force
11391137
npm install -g openclaw@$OPENCLAW_VERSION --timeout=300000 $IGNORE_FLAG
11401138
}
11411139

1142-
if ! grep -q 'NVM_DIR' ~/.bashrc; then
1143-
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
1144-
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.bashrc
1145-
fi
1146-
UBUNTU_SCRIPT
1147-
1148-
# Create openclaw wrapper
1149-
OPENCLAW_MJS=$(find /home/ubuntu/.nvm -path "*/node_modules/openclaw/openclaw.mjs" 2>/dev/null | head -1)
1150-
NODE_BIN=$(find /home/ubuntu/.nvm -name node -type f 2>/dev/null | head -1)
1151-
if [ -z "$OPENCLAW_MJS" ] || [ -z "$NODE_BIN" ]; then
1152-
echo "FATAL: openclaw or node not found"
1140+
# Create openclaw wrapper (system node + system global openclaw)
1141+
NODE_BIN=$(command -v node)
1142+
OPENCLAW_MJS="$(npm root -g)/openclaw/openclaw.mjs"
1143+
if [ ! -f "$OPENCLAW_MJS" ] || [ -z "$NODE_BIN" ]; then
1144+
echo "FATAL: openclaw or node not found (OPENCLAW_MJS=$OPENCLAW_MJS NODE_BIN=$NODE_BIN)"
11531145
exit 1
11541146
fi
11551147
echo "#!/bin/bash" > /usr/local/bin/openclaw
@@ -1258,8 +1250,6 @@ Resources:
12581250
sudo -H -u ubuntu XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus OPENCLAW_STATE_DIR="$STATE_DIR" bash -c '
12591251
export HOME=/home/ubuntu
12601252
export OPENCLAW_STATE_DIR=$OPENCLAW_STATE_DIR
1261-
export NVM_DIR="$HOME/.nvm"
1262-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
12631253
openclaw gateway install || echo "Gateway install failed"
12641254

12651255
# Fix systemd service to include OPENCLAW_STATE_DIR
@@ -1290,8 +1280,6 @@ Resources:
12901280
echo "WARNING: Gateway did not start, trying fallback..."
12911281
sudo -H -u ubuntu XDG_RUNTIME_DIR=/run/user/1000 bash -c '
12921282
export HOME=/home/ubuntu
1293-
export NVM_DIR="$HOME/.nvm"
1294-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
12951283
systemctl --user restart openclaw-gateway.service || openclaw gateway &
12961284
'
12971285
sleep 5
@@ -1301,15 +1289,27 @@ Resources:
13011289
echo "[8.5/9] Enabling messaging channels..."
13021290
sudo -H -u ubuntu bash -c '
13031291
export HOME=/home/ubuntu
1304-
export NVM_DIR="$HOME/.nvm"
1305-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
13061292
openclaw plugins enable whatsapp || echo "WhatsApp plugin enable failed"
13071293
openclaw plugins enable telegram || echo "Telegram plugin enable failed"
13081294
openclaw plugins enable discord || echo "Discord plugin enable failed"
13091295
openclaw plugins enable slack || echo "Slack plugin enable failed"
1296+
'
1297+
# Community plugins install into the system global node_modules (needs root)
13101298
npm install -g openclaw-feishu@latest --timeout=60000 2>/dev/null || echo "Feishu plugin install skipped"
13111299
npm install -g openclaw-wechat@latest --timeout=60000 2>/dev/null || echo "WeChat plugin install skipped"
1312-
'
1300+
1301+
# Safety net (issue #168): repoint extension "openclaw" peer links to the
1302+
# current global install so they never go stale across Node/openclaw upgrades.
1303+
# With system Node these paths are already stable; this guards residual/legacy
1304+
# links (e.g. left over from an nvm-based deploy that was upgraded in place).
1305+
GLOBAL_OPENCLAW="$(npm root -g)/openclaw"
1306+
sudo -H -u ubuntu GLOBAL_OPENCLAW="$GLOBAL_OPENCLAW" bash -c '
1307+
export HOME=/home/ubuntu
1308+
shopt -s nullglob
1309+
for link in /home/ubuntu/.openclaw/extensions/*/node_modules/openclaw; do
1310+
ln -sfn "$GLOBAL_OPENCLAW" "$link" && echo "repointed peer link: $link"
1311+
done
1312+
' || echo "peer-link repoint skipped"
13131313
13141314
# Copy SOUL.md
13151315
cp /opt/openclaw/SOUL.md "$STATE_DIR/SOUL.md"
@@ -1392,8 +1392,6 @@ Resources:
13921392
echo "[post] Running openclaw doctor..."
13931393
sudo -H -u ubuntu XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus bash -c '
13941394
export HOME=/home/ubuntu
1395-
export NVM_DIR="$HOME/.nvm"
1396-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
13971395
openclaw doctor --fix 2>&1 || echo "openclaw doctor completed with warnings"
13981396
'
13991397
@@ -1445,8 +1443,6 @@ Resources:
14451443
echo "$(date) Running channel connectivity check..." >> $LOG
14461444
CHANNEL_STATUS=$(sudo -H -u ubuntu bash -c '
14471445
export HOME=/home/ubuntu
1448-
export NVM_DIR="$HOME/.nvm"
1449-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
14501446
export XDG_RUNTIME_DIR=/run/user/1000
14511447
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
14521448
timeout 30 openclaw status 2>&1

0 commit comments

Comments
 (0)