Instance scripts: read node - arguments from argv[2]

`node -` puts '-' in argv[1], so the registry snippets in add-instance.sh
and remove-instance.sh were one slot off: they wrote the registry to a file
named "-" in the working directory, with the instances.json path as the
instance name, a null port and the port as the db. scripts/instances.json
was never created, so the updater and start-all only ever knew instance 1 —
after an update, instance 2 and up kept running old code against the new
build until someone ran `pm2 restart all`.

Devices that already ran add-instance.sh need their scripts/instances.json
written by hand (and the stray "-" file deleted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-09-23 20:18:33 -05:00
co-authored by Claude Opus 5.5
parent dd73222e00
commit ccad48cf0a
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -68,7 +68,8 @@ command -v pm2 >/dev/null 2>&1 || die "PM2 not installed - run install-autostart
# ── registry: create with the legacy entry, refuse duplicates, append ─────── # ── registry: create with the legacy entry, refuse duplicates, append ───────
node - "$REGISTRY" "$PM2_NAME" "$PORT" "$DB_REL" <<'NODE' node - "$REGISTRY" "$PM2_NAME" "$PORT" "$DB_REL" <<'NODE'
const { existsSync, readFileSync, writeFileSync } = require('node:fs'); const { existsSync, readFileSync, writeFileSync } = require('node:fs');
const [, file, name, port, db] = process.argv; // `node -` puts '-' in argv[1], so the arguments start at argv[2].
const [file, name, port, db] = process.argv.slice(2);
const entries = existsSync(file) const entries = existsSync(file)
? JSON.parse(readFileSync(file, 'utf8')) ? JSON.parse(readFileSync(file, 'utf8'))
: [{ name: 'autofirmer', port: 3000, db: 'autotrader.sqlite' }]; : [{ name: 'autofirmer', port: 3000, db: 'autotrader.sqlite' }];
+2 -1
View File
@@ -23,7 +23,8 @@ PM2_NAME="autofirmer-$N"
node - "$REGISTRY" "$PM2_NAME" <<'NODE' node - "$REGISTRY" "$PM2_NAME" <<'NODE'
const { readFileSync, writeFileSync } = require('node:fs'); const { readFileSync, writeFileSync } = require('node:fs');
const [, file, name] = process.argv; // `node -` puts '-' in argv[1], so the arguments start at argv[2].
const [file, name] = process.argv.slice(2);
const entries = JSON.parse(readFileSync(file, 'utf8')); const entries = JSON.parse(readFileSync(file, 'utf8'));
if (!entries.some((e) => e.name === name)) { console.error(` [X] ${name} is not registered`); process.exit(1); } if (!entries.some((e) => e.name === name)) { console.error(` [X] ${name} is not registered`); process.exit(1); }
writeFileSync(file, JSON.stringify(entries.filter((e) => e.name !== name), null, 4) + '\n'); writeFileSync(file, JSON.stringify(entries.filter((e) => e.name !== name), null, 4) + '\n');