@lethevimlet/sshift 1.0.16 → 1.0.17
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/package.json
CHANGED
|
@@ -308,24 +308,29 @@ function registerSystemEndpoints(app, io) {
|
|
|
308
308
|
let systemdUnit = '';
|
|
309
309
|
try {
|
|
310
310
|
// Check if this process is managed by systemd via cgroup
|
|
311
|
-
const
|
|
311
|
+
const myPid = process.pid;
|
|
312
|
+
const myCgroup = fs.readFileSync(`/proc/${myPid}/cgroup`, 'utf8');
|
|
312
313
|
if (myCgroup.includes('sshift')) {
|
|
313
314
|
isSystemdManaged = true;
|
|
314
315
|
systemdUnit = 'sshift.service';
|
|
315
|
-
console.log('[UPDATE] Detected systemd-managed process, unit:', systemdUnit);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
console.log('[UPDATE] Detected systemd-managed process via cgroup, unit:', systemdUnit);
|
|
317
|
+
}
|
|
318
|
+
} catch (e) {
|
|
319
|
+
// /proc not available (non-Linux), ignore
|
|
320
|
+
}
|
|
321
|
+
// Fallback: check if sshift.service is active in systemd
|
|
322
|
+
if (!isSystemdManaged) {
|
|
323
|
+
try {
|
|
324
|
+
const { execSync: execSync2 } = require('child_process');
|
|
325
|
+
const isActive = execSync2('systemctl is-active sshift.service 2>/dev/null', { encoding: 'utf8' }).trim();
|
|
326
|
+
if (isActive === 'active') {
|
|
320
327
|
isSystemdManaged = true;
|
|
321
328
|
systemdUnit = 'sshift.service';
|
|
322
|
-
console.log('[UPDATE] Detected systemd service:', systemdUnit);
|
|
323
|
-
} catch (e) {
|
|
324
|
-
// Not a systemd service
|
|
329
|
+
console.log('[UPDATE] Detected active systemd service:', systemdUnit);
|
|
325
330
|
}
|
|
331
|
+
} catch (e) {
|
|
332
|
+
// Not a systemd service or systemctl not available
|
|
326
333
|
}
|
|
327
|
-
} catch (e) {
|
|
328
|
-
// /proc not available (non-Linux), ignore
|
|
329
334
|
}
|
|
330
335
|
|
|
331
336
|
// Build PATH for the update script to ensure npm and node are findable
|
|
@@ -364,9 +369,25 @@ try {
|
|
|
364
369
|
} catch {}
|
|
365
370
|
|
|
366
371
|
try {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
372
|
+
$NpmAttempts = 0
|
|
373
|
+
$NpmMaxAttempts = 3
|
|
374
|
+
$NpmSuccess = $false
|
|
375
|
+
while ($NpmAttempts -lt $NpmMaxAttempts) {
|
|
376
|
+
$NpmAttempts++
|
|
377
|
+
Write-Output "$(Get-Date): npm install attempt $NpmAttempts of $NpmMaxAttempts" | Out-File -FilePath $LogPath -Append
|
|
378
|
+
& npm install -g @lethevimlet/sshift@latest 2>&1 | Out-File -FilePath $LogPath -Append
|
|
379
|
+
if ($LASTEXITCODE -eq 0) {
|
|
380
|
+
$NpmSuccess = $true
|
|
381
|
+
break
|
|
382
|
+
}
|
|
383
|
+
Write-Output "$(Get-Date): npm install attempt $NpmAttempts failed" | Out-File -FilePath $LogPath -Append
|
|
384
|
+
if ($NpmAttempts -lt $NpmMaxAttempts) {
|
|
385
|
+
Write-Output "$(Get-Date): Waiting 30s before retry..." | Out-File -FilePath $LogPath -Append
|
|
386
|
+
Start-Sleep -Seconds 30
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (-not $NpmSuccess) {
|
|
390
|
+
Write-Output "npm install failed after $NpmMaxAttempts attempts" | Out-File -FilePath $LogPath -Append
|
|
370
391
|
Remove-Item -Path $MarkerPath -Force -ErrorAction SilentlyContinue
|
|
371
392
|
if ($IsScheduled) {
|
|
372
393
|
Write-Output "Starting scheduled task (old version)" | Out-File -FilePath $LogPath -Append
|
|
@@ -417,10 +438,28 @@ echo "$(date): systemd_managed: $SYSTEMD_MANAGED" >> "$LOG"
|
|
|
417
438
|
# Find the current sshift binary before npm changes anything
|
|
418
439
|
CURRENT_SSHIFT="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$SSHIFT_FALLBACK")"
|
|
419
440
|
|
|
420
|
-
# Run npm install
|
|
441
|
+
# Run npm install (with retry for registry propagation delay)
|
|
421
442
|
echo "$(date): Running npm install..." >> "$LOG"
|
|
422
|
-
|
|
423
|
-
|
|
443
|
+
NPM_ATTEMPTS=0
|
|
444
|
+
NPM_MAX_ATTEMPTS=3
|
|
445
|
+
NPM_DELAY=30
|
|
446
|
+
NPM_SUCCESS=false
|
|
447
|
+
while [ $NPM_ATTEMPTS -lt $NPM_MAX_ATTEMPTS ]; do
|
|
448
|
+
NPM_ATTEMPTS=$((NPM_ATTEMPTS + 1))
|
|
449
|
+
echo "$(date): npm install attempt $NPM_ATTEMPTS of $NPM_MAX_ATTEMPTS" >> "$LOG"
|
|
450
|
+
if "$NPM_BIN" install -g @lethevimlet/sshift@latest >> "$LOG" 2>&1; then
|
|
451
|
+
NPM_SUCCESS=true
|
|
452
|
+
break
|
|
453
|
+
fi
|
|
454
|
+
echo "$(date): npm install attempt $NPM_ATTEMPTS failed" >> "$LOG"
|
|
455
|
+
if [ $NPM_ATTEMPTS -lt $NPM_MAX_ATTEMPTS ]; then
|
|
456
|
+
echo "$(date): Waiting ${NPM_DELAY}s before retry (npm registry propagation delay)..." >> "$LOG"
|
|
457
|
+
sleep $NPM_DELAY
|
|
458
|
+
fi
|
|
459
|
+
done
|
|
460
|
+
|
|
461
|
+
if [ "$NPM_SUCCESS" != "true" ]; then
|
|
462
|
+
echo "$(date): npm install failed after $NPM_MAX_ATTEMPTS attempts" >> "$LOG"
|
|
424
463
|
echo "npm install failed" >> "$LOG"
|
|
425
464
|
rm -f "$MARKER"
|
|
426
465
|
# Always restart the server — the old version is still installed
|