@lethevimlet/sshift 1.0.11 → 1.0.13

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -388,14 +388,6 @@ echo "$(date): node path: $NODE_BIN" >> "$LOG"
388
388
  echo "$(date): sshift fallback: $SSHIFT_FALLBACK" >> "$LOG"
389
389
  echo "$(date): systemd_managed: $SYSTEMD_MANAGED" >> "$LOG"
390
390
 
391
- if [ "$SYSTEMD_MANAGED" = "1" ]; then
392
- echo "$(date): Detected systemd-managed service: $SYSTEMD_UNIT" >> "$LOG"
393
- # Stop the service before updating to prevent systemd from restarting old version
394
- echo "$(date): Stopping $SYSTEMD_UNIT..." >> "$LOG"
395
- systemctl stop "$SYSTEMD_UNIT" >> "$LOG" 2>&1 || true
396
- sleep 1
397
- fi
398
-
399
391
  # Find the current sshift binary before npm changes anything
400
392
  CURRENT_SSHIFT="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$SSHIFT_FALLBACK")"
401
393
 
@@ -422,7 +414,7 @@ rm -f "$MARKER"
422
414
 
423
415
  if [ "$SYSTEMD_MANAGED" = "1" ]; then
424
416
  echo "$(date): Restarting via systemd" >> "$LOG"
425
- systemctl start "$SYSTEMD_UNIT" >> "$LOG" 2>&1
417
+ systemctl restart "$SYSTEMD_UNIT" >> "$LOG" 2>&1
426
418
  else
427
419
  # Find the sshift binary — prefer PATH lookup since npm just updated it
428
420
  SSHIFT_BIN="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$SSHIFT_FALLBACK")"
@@ -484,6 +476,23 @@ fi
484
476
  const updateEnv = { ...process.env };
485
477
  updateEnv.PATH = scriptPath;
486
478
 
479
+ // When running under systemd, spawn the update script in a transient scope
480
+ // so it survives `systemctl restart` of the sshift service. Without this,
481
+ // the script is in the same cgroup as sshift and gets killed when the
482
+ // service restarts.
483
+ if (isSystemdManaged && platform !== 'win32') {
484
+ try {
485
+ const systemdRunCheck = require('child_process').execSync('command -v systemd-run', { encoding: 'utf8' }).trim();
486
+ if (systemdRunCheck) {
487
+ console.log('[UPDATE] Using systemd-run to isolate update script from service');
488
+ spawnCommand = systemdRunCheck;
489
+ spawnArgs = ['--scope', '--unit=sshift-update', '/bin/sh', updateScriptPath];
490
+ }
491
+ } catch (e) {
492
+ // systemd-run not available, fall through to default spawn
493
+ }
494
+ }
495
+
487
496
  const updateProcess = spawn(spawnCommand, spawnArgs, {
488
497
  cwd: dataDir,
489
498
  detached: true,
@@ -500,23 +509,16 @@ fi
500
509
  updateProcess.unref();
501
510
 
502
511
  // Give the update script enough time to start before exiting.
503
- // The script runs npm install (which can take time) in the background,
504
- // but we need to wait long enough for the spawn to succeed.
505
- // When running under systemd, the update script will stop/start the service,
506
- // so we DON'T exit ourselves — the script's `systemctl stop` will kill us.
507
- // For non-systemd, we exit so the script can exec the new binary.
508
- const exitDelay = isSystemdManaged ? 500 : 2000;
512
+ // Under systemd: we exit so the service can be restarted by `systemctl
513
+ // restart` in the script. The script runs in a separate systemd scope
514
+ // so it survives the service restart.
515
+ // Non-systemd: we exit so the script can exec the new binary.
516
+ const exitDelay = isSystemdManaged ? 1000 : 2000;
509
517
  setTimeout(() => {
510
518
  if (spawnFailed) {
511
519
  console.error('[UPDATE] Update process failed to start. Keeping server running.');
512
520
  return;
513
521
  }
514
- if (isSystemdManaged) {
515
- // Under systemd, the update script will call `systemctl stop` to stop us.
516
- // We don't need to exit ourselves. Just keep running until systemd stops us.
517
- console.log('[UPDATE] Update script running under systemd. Service will be stopped by the script.');
518
- return;
519
- }
520
522
  console.log('[UPDATE] Exiting for update...');
521
523
  process.exit(0);
522
524
  }, exitDelay);