@misterhuydo/sentinel 1.4.91 → 1.4.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/.cairn/views/fb78ac_upgrade.js +1 -1
- package/lib/generate.js +7 -1
- package/lib/upgrade.js +39 -1
- package/package.json +1 -1
|
@@ -62,7 +62,7 @@ module.exports = async function upgrade() {
|
|
|
62
62
|
const { version: installed } = require(path.join(npmRootEarly, '@misterhuydo', 'sentinel', 'package.json'));
|
|
63
63
|
if (installed !== current) {
|
|
64
64
|
ok(`Upgraded: ${current} → ${installed} — re-running with new version...`);
|
|
65
|
-
const newBin = path.join(
|
|
65
|
+
const newBin = path.join(npmRootEarly, '..', '..', 'bin', 'sentinel');
|
|
66
66
|
const r = spawnSync(newBin, ['upgrade'], { stdio: 'inherit' });
|
|
67
67
|
process.exit(r.status || 0);
|
|
68
68
|
}
|
package/lib/generate.js
CHANGED
|
@@ -312,6 +312,12 @@ for project_dir in "$WORKSPACE"/*/; do
|
|
|
312
312
|
done
|
|
313
313
|
echo "[sentinel] $stopped project(s) stopped"
|
|
314
314
|
`, { mode: 0o755 });
|
|
315
|
+
// watchdog.sh - restarts any project that has stopped unexpectedly.
|
|
316
|
+
// Auto-installed as a cron job by `sentinel upgrade`.
|
|
317
|
+
fs.writeFileSync(path.join(workspace, 'watchdog.sh'),
|
|
318
|
+
"#!/usr/bin/env bash\n# Sentinel watchdog - auto-restart any project that has stopped unexpectedly.\n# Runs every minute via cron. Safe to run manually at any time.\nWORKSPACE=\"$(cd \"$(dirname \"$0\")\" && pwd)\"\nNON_PROJECT=\"code repos logs issues workspace\"\nfor project_dir in \"$WORKSPACE\"/*/; do\n [[ -d \"$project_dir\" ]] || continue\n name=$(basename \"$project_dir\")\n echo \" $NON_PROJECT \" | grep -qw \"$name\" && continue\n [[ -f \"$project_dir/start.sh\" ]] || continue\n [[ -f \"$project_dir/config/sentinel.properties\" ]] || continue\n PID_FILE=\"$project_dir/sentinel.pid\"\n if [[ -f \"$PID_FILE\" ]] && kill -0 \"$(cat \"$PID_FILE\")\" 2>/dev/null; then\n continue # running fine\n fi\n echo \"[watchdog] $(date -u +%Y-%m-%dT%H:%M:%SZ) $name is down - restarting\"\n bash \"$project_dir/start.sh\"\ndone\n",
|
|
319
|
+
{ mode: 0o755 });
|
|
315
320
|
}
|
|
316
|
-
|
|
321
|
+
|
|
322
|
+
|
|
317
323
|
module.exports = { writeExampleProject, generateProjectScripts, generateWorkspaceScripts };
|
package/lib/upgrade.js
CHANGED
|
@@ -146,13 +146,51 @@ module.exports = async function upgrade() {
|
|
|
146
146
|
warn('Could not regenerate project scripts: ' + e.message);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
// Install watchdog cron job if not already present
|
|
150
|
+
const watchdog = path.join(defaultWorkspace, 'watchdog.sh');
|
|
151
|
+
const logsDir = path.join(defaultWorkspace, 'logs');
|
|
152
|
+
if (fs.existsSync(watchdog)) {
|
|
153
|
+
info('Installing watchdog cron job...');
|
|
154
|
+
try {
|
|
155
|
+
const existing = execSync('crontab -l 2>/dev/null || true', { encoding: 'utf8' });
|
|
156
|
+
if (existing.includes('watchdog.sh')) {
|
|
157
|
+
ok('Watchdog cron job already installed');
|
|
158
|
+
} else {
|
|
159
|
+
const cronLine = `* * * * * ${watchdog} >> ${logsDir}/watchdog.log 2>&1`;
|
|
160
|
+
const newCron = existing.trimEnd() + '\n' + cronLine + '\n';
|
|
161
|
+
execSync(`echo ${JSON.stringify(newCron)} | crontab -`);
|
|
162
|
+
ok('Watchdog cron job installed (runs every minute)');
|
|
163
|
+
}
|
|
164
|
+
} catch (e) {
|
|
165
|
+
warn('Could not install watchdog cron: ' + e.message);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
149
169
|
const startAll = path.join(defaultWorkspace, 'startAll.sh');
|
|
150
170
|
const stopAll = path.join(defaultWorkspace, 'stopAll.sh');
|
|
151
171
|
if (fs.existsSync(stopAll) && fs.existsSync(startAll)) {
|
|
152
172
|
info('Restarting Sentinel...');
|
|
153
173
|
spawnSync('bash', [stopAll], { stdio: 'inherit' });
|
|
154
174
|
spawnSync('bash', [startAll], { stdio: 'inherit' });
|
|
155
|
-
|
|
175
|
+
// Verify restart succeeded — give processes 4 seconds to write PID files
|
|
176
|
+
execSync('sleep 4 || true');
|
|
177
|
+
let allUp = true;
|
|
178
|
+
try {
|
|
179
|
+
const entries = fs.readdirSync(defaultWorkspace, { withFileTypes: true });
|
|
180
|
+
const NON = new Set(['logs', 'code', 'repos', 'workspace', 'issues']);
|
|
181
|
+
for (const e of entries) {
|
|
182
|
+
if (!e.isDirectory() || e.name.startsWith('.') || NON.has(e.name)) continue;
|
|
183
|
+
const pidFile = path.join(defaultWorkspace, e.name, 'sentinel.pid');
|
|
184
|
+
if (!fs.existsSync(path.join(defaultWorkspace, e.name, 'config', 'sentinel.properties'))) continue;
|
|
185
|
+
if (!fs.existsSync(pidFile)) { allUp = false; continue; }
|
|
186
|
+
const pid = fs.readFileSync(pidFile, 'utf8').trim();
|
|
187
|
+
try { execSync(`kill -0 ${pid}`); } catch (_) {
|
|
188
|
+
warn(`${e.name} may have crashed after restart — watchdog will recover it within 1 minute`);
|
|
189
|
+
allUp = false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} catch (_) {}
|
|
193
|
+
if (allUp) ok('Sentinel restarted');
|
|
156
194
|
} else {
|
|
157
195
|
warn('No startAll.sh found — restart manually');
|
|
158
196
|
}
|