@lethevimlet/sshift 1.0.21 → 1.1.1
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/README.md +29 -0
- package/package.json +25 -23
- package/src/server/endpoints/rest/system.js +159 -37
- package/sshift +20 -12
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@lethevimlet/sshift)
|
|
7
7
|
[](https://github.com/lethevimlet/sshift/pkgs/container/sshift)
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://socket.dev/npm/package/@lethevimlet/sshift)
|
|
9
10
|
|
|
10
11
|
A modern, responsive web-based SSH and SFTP terminal client built with Node.js, Express, and xterm.js. Designed for the AI coding workflow — featuring tab flash notifications that alert you when AI tools like OpenCode or Claude are waiting for your input, so you never miss a prompt while multitasking. Also features excellent TUI support, tabbed sessions, bookmarks, and mobile-friendly design.
|
|
11
12
|
|
|
@@ -124,6 +125,34 @@ npm install
|
|
|
124
125
|
npm start
|
|
125
126
|
```
|
|
126
127
|
|
|
128
|
+
## 🖥️ CLI Reference
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
sshift Start server on default port (8022)
|
|
132
|
+
sshift --dev Start in development mode (port 3000, separate PID)
|
|
133
|
+
sshift --port 8080 Start server on custom port
|
|
134
|
+
sshift --bind 127.0.0.1 Bind to specific address
|
|
135
|
+
sshift --status Check if sshift is running
|
|
136
|
+
sshift --stop Stop running instance
|
|
137
|
+
sshift --restart Restart running instance
|
|
138
|
+
sshift --dev --status Check if dev instance is running
|
|
139
|
+
sshift --dev --stop Stop dev instance
|
|
140
|
+
sshift --dev --restart Restart dev instance
|
|
141
|
+
sshift --help Show help message
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
| Flag | Shorthand | Description |
|
|
145
|
+
|------|-----------|-------------|
|
|
146
|
+
| `--port <port>` | `-p` | Server port (default: 8022, dev: 3000) |
|
|
147
|
+
| `--bind <addr>` | `-b` | Bind address (default: 0.0.0.0) |
|
|
148
|
+
| `--dev` | `-d` | Development mode — uses `devPort` from config (default 3000) and a separate PID file so dev and production instances can run side-by-side |
|
|
149
|
+
| `--stop` | `-s` | Stop running instance |
|
|
150
|
+
| `--restart` | `-r` | Restart running instance |
|
|
151
|
+
| `--status` | | Check running status |
|
|
152
|
+
| `--help` | `-h` | Show help message |
|
|
153
|
+
|
|
154
|
+
> **Note:** `--dev` sets `NODE_ENV=development`, which switches the default port from 8022 to 3000 (or `devPort` from `config.json`). It also uses a separate PID file (`.sshift-dev.pid`) so you can run a dev instance alongside production and use `--dev --status`/`--dev --stop`/`--dev --restart` to manage it independently.
|
|
155
|
+
|
|
127
156
|
## ⚙️ Configuration
|
|
128
157
|
|
|
129
158
|
SSHIFT uses a priority-based configuration system. Config files are searched in order; the first match wins.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lethevimlet/sshift",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
|
|
5
5
|
"main": "src/server/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,25 +16,26 @@
|
|
|
16
16
|
"test:integration": "jest --testPathPatterns='src/tests/integration' --forceExit",
|
|
17
17
|
"test:e2e": "jest --testPathPatterns='src/tests/e2e' --forceExit --runInBand",
|
|
18
18
|
"test:browser": "jest --testPathPatterns='src/tests/browser' --forceExit --runInBand",
|
|
19
|
-
"prepublishOnly": "echo 'Publishing to npm...'"
|
|
19
|
+
"prepublishOnly": "echo 'Publishing to npm...'",
|
|
20
|
+
"install:safe": "sfw pnpm install"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@xterm/addon-fit": "
|
|
23
|
-
"@xterm/addon-image": "
|
|
24
|
-
"@xterm/addon-search": "
|
|
25
|
-
"@xterm/addon-serialize": "
|
|
26
|
-
"@xterm/addon-web-links": "
|
|
27
|
-
"@xterm/addon-webgl": "
|
|
28
|
-
"@xterm/headless": "
|
|
29
|
-
"@xterm/xterm": "
|
|
30
|
-
"dotenv": "
|
|
31
|
-
"express": "
|
|
32
|
-
"httpolyglot": "
|
|
33
|
-
"lucide": "
|
|
34
|
-
"selfsigned": "
|
|
35
|
-
"socket.io": "
|
|
36
|
-
"ssh2": "
|
|
37
|
-
"uuid": "
|
|
23
|
+
"@xterm/addon-fit": "0.11.0",
|
|
24
|
+
"@xterm/addon-image": "0.9.0",
|
|
25
|
+
"@xterm/addon-search": "0.16.0",
|
|
26
|
+
"@xterm/addon-serialize": "0.14.0",
|
|
27
|
+
"@xterm/addon-web-links": "0.12.0",
|
|
28
|
+
"@xterm/addon-webgl": "0.19.0",
|
|
29
|
+
"@xterm/headless": "6.0.0",
|
|
30
|
+
"@xterm/xterm": "6.0.0",
|
|
31
|
+
"dotenv": "17.4.0",
|
|
32
|
+
"express": "4.18.2",
|
|
33
|
+
"httpolyglot": "0.1.2",
|
|
34
|
+
"lucide": "1.7.0",
|
|
35
|
+
"selfsigned": "5.5.0",
|
|
36
|
+
"socket.io": "4.7.2",
|
|
37
|
+
"ssh2": "1.15.0",
|
|
38
|
+
"uuid": "9.0.0"
|
|
38
39
|
},
|
|
39
40
|
"keywords": [
|
|
40
41
|
"ssh",
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
"engines": {
|
|
61
62
|
"node": ">=20.0.0"
|
|
62
63
|
},
|
|
64
|
+
"packageManager": "pnpm@10.33.4",
|
|
63
65
|
"publishConfig": {
|
|
64
66
|
"access": "public",
|
|
65
67
|
"provenance": true
|
|
@@ -76,10 +78,10 @@
|
|
|
76
78
|
"LICENSE"
|
|
77
79
|
],
|
|
78
80
|
"devDependencies": {
|
|
79
|
-
"@types/jest": "
|
|
80
|
-
"jest": "
|
|
81
|
-
"puppeteer": "
|
|
82
|
-
"socket.io-client": "
|
|
83
|
-
"ts-jest": "
|
|
81
|
+
"@types/jest": "30.0.0",
|
|
82
|
+
"jest": "30.3.0",
|
|
83
|
+
"puppeteer": "24.40.0",
|
|
84
|
+
"socket.io-client": "4.8.3",
|
|
85
|
+
"ts-jest": "29.4.9"
|
|
84
86
|
}
|
|
85
87
|
}
|
|
@@ -241,10 +241,79 @@ function registerSystemEndpoints(app, io) {
|
|
|
241
241
|
// API: Trigger update
|
|
242
242
|
app.post('/api/update', async (req, res) => {
|
|
243
243
|
try {
|
|
244
|
+
const isLocalhost = req.hostname === 'localhost' || req.hostname === '127.0.0.1' || req.hostname === '::1';
|
|
245
|
+
if (!isLocalhost && !req.headers.authorization && !req.query.token) {
|
|
246
|
+
return res.status(403).json({ error: 'Remote update requires authentication. Set a password or use localhost.' });
|
|
247
|
+
}
|
|
248
|
+
|
|
244
249
|
const { spawn, execSync } = require('child_process');
|
|
245
250
|
const platform = process.platform;
|
|
246
251
|
const dataDir = getDataDir();
|
|
247
252
|
|
|
253
|
+
// Resolve the target version by checking GitHub for the latest release
|
|
254
|
+
// This pins the exact version instead of using @latest, preventing
|
|
255
|
+
// supply chain attacks where a compromised registry could serve a
|
|
256
|
+
// different package than what was published.
|
|
257
|
+
let targetVersion = 'latest';
|
|
258
|
+
const currentPkg = require('../../../../package.json');
|
|
259
|
+
try {
|
|
260
|
+
const https = require('https');
|
|
261
|
+
const githubVersion = await new Promise((resolve, reject) => {
|
|
262
|
+
const opts = {
|
|
263
|
+
hostname: 'api.github.com',
|
|
264
|
+
path: '/repos/lethevimlet/sshift/contents/package.json',
|
|
265
|
+
method: 'GET',
|
|
266
|
+
headers: { 'User-Agent': 'sshift-update-checker', 'Accept': 'application/vnd.github.v3+json' }
|
|
267
|
+
};
|
|
268
|
+
const ghReq = https.request(opts, (ghRes) => {
|
|
269
|
+
let body = '';
|
|
270
|
+
ghRes.on('data', (chunk) => { body += chunk; });
|
|
271
|
+
ghRes.on('end', () => {
|
|
272
|
+
try {
|
|
273
|
+
if (ghRes.statusCode !== 200) return reject(new Error('GitHub API returned ' + ghRes.statusCode));
|
|
274
|
+
const parsed = JSON.parse(body);
|
|
275
|
+
const content = Buffer.from(parsed.content, 'base64').toString('utf8');
|
|
276
|
+
resolve(JSON.parse(content).version);
|
|
277
|
+
} catch (e) { reject(e); }
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
ghReq.on('error', reject);
|
|
281
|
+
ghReq.setTimeout(10000, () => { ghReq.destroy(); reject(new Error('GitHub request timed out')); });
|
|
282
|
+
ghReq.end();
|
|
283
|
+
});
|
|
284
|
+
if (githubVersion && /^\d+\.\d+\.\d+$/.test(githubVersion)) {
|
|
285
|
+
// Verify the version actually exists on the npm registry before pinning.
|
|
286
|
+
// GitHub may show a version before npm propagation completes, which would
|
|
287
|
+
// cause all install retries to fail against a non-existent version.
|
|
288
|
+
const npmAvailable = await new Promise((resolve) => {
|
|
289
|
+
const npmReq = https.request({
|
|
290
|
+
hostname: 'registry.npmjs.org',
|
|
291
|
+
path: '/@lethevimlet/sshift/' + githubVersion,
|
|
292
|
+
method: 'GET',
|
|
293
|
+
headers: { 'User-Agent': 'sshift-update-checker' }
|
|
294
|
+
}, (npmRes) => {
|
|
295
|
+
resolve(npmRes.statusCode === 200);
|
|
296
|
+
});
|
|
297
|
+
npmReq.on('error', () => resolve(false));
|
|
298
|
+
npmReq.setTimeout(10000, () => { npmReq.destroy(); resolve(false); });
|
|
299
|
+
npmReq.end();
|
|
300
|
+
});
|
|
301
|
+
if (npmAvailable) {
|
|
302
|
+
targetVersion = githubVersion;
|
|
303
|
+
console.log('[UPDATE] Pinned target version:', targetVersion);
|
|
304
|
+
} else {
|
|
305
|
+
console.warn('[UPDATE] Version', githubVersion, 'found on GitHub but not yet on npm, deferring update');
|
|
306
|
+
return res.status(503).json({
|
|
307
|
+
error: 'Update available but not yet on npm. Try again in a few minutes.',
|
|
308
|
+
localVersion: currentPkg.version,
|
|
309
|
+
remoteVersion: githubVersion
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
} catch (e) {
|
|
314
|
+
console.warn('[UPDATE] Could not resolve version from GitHub, falling back to @latest:', e.message);
|
|
315
|
+
}
|
|
316
|
+
|
|
248
317
|
// Write update marker to indicate update in progress
|
|
249
318
|
const updateMarker = path.join(dataDir, UPDATE_MARKER_FILE);
|
|
250
319
|
let oldVersion = 'unknown';
|
|
@@ -254,7 +323,8 @@ function registerSystemEndpoints(app, io) {
|
|
|
254
323
|
fs.mkdirSync(dataDir, { recursive: true });
|
|
255
324
|
fs.writeFileSync(updateMarker, JSON.stringify({
|
|
256
325
|
startTime: Date.now(),
|
|
257
|
-
oldVersion: pkg.version
|
|
326
|
+
oldVersion: pkg.version,
|
|
327
|
+
targetVersion
|
|
258
328
|
}));
|
|
259
329
|
} catch (e) {
|
|
260
330
|
console.error('[UPDATE] Failed to write update marker:', e.message);
|
|
@@ -302,36 +372,72 @@ function registerSystemEndpoints(app, io) {
|
|
|
302
372
|
const updateScriptPath = path.join(dataDir, '.sshift-update.sh');
|
|
303
373
|
const updateLogPath = path.join(dataDir, '.sshift-update.log');
|
|
304
374
|
|
|
305
|
-
|
|
306
|
-
//
|
|
307
|
-
|
|
308
|
-
|
|
375
|
+
// Detect service manager (systemd, launchd, Task Scheduler) so the
|
|
376
|
+
// update script can use the right stop/restart commands instead of exec.
|
|
377
|
+
// This prevents race conditions where the service manager restarts the
|
|
378
|
+
// old version before npm install completes.
|
|
379
|
+
let isServiceManaged = false;
|
|
380
|
+
let serviceManager = ''; // 'systemd', 'launchd', 'taskscheduler'
|
|
381
|
+
let serviceUnit = '';
|
|
309
382
|
try {
|
|
310
|
-
//
|
|
383
|
+
// Linux: check if this process is managed by systemd via cgroup
|
|
311
384
|
const myPid = process.pid;
|
|
312
385
|
const myCgroup = fs.readFileSync(`/proc/${myPid}/cgroup`, 'utf8');
|
|
313
386
|
if (myCgroup.includes('sshift')) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
387
|
+
isServiceManaged = true;
|
|
388
|
+
serviceManager = 'systemd';
|
|
389
|
+
serviceUnit = 'sshift.service';
|
|
390
|
+
console.log('[UPDATE] Detected systemd-managed process via cgroup, unit:', serviceUnit);
|
|
317
391
|
}
|
|
318
392
|
} catch (e) {
|
|
319
393
|
// /proc not available (non-Linux), ignore
|
|
320
394
|
}
|
|
321
|
-
// Fallback: check if sshift.service is active in systemd
|
|
322
|
-
if (!
|
|
395
|
+
// Fallback for Linux: check if sshift.service is active in systemd
|
|
396
|
+
if (!isServiceManaged && platform === 'linux') {
|
|
323
397
|
try {
|
|
324
398
|
const { execSync: execSync2 } = require('child_process');
|
|
325
399
|
const isActive = execSync2('systemctl is-active sshift.service 2>/dev/null', { encoding: 'utf8' }).trim();
|
|
326
400
|
if (isActive === 'active') {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
401
|
+
isServiceManaged = true;
|
|
402
|
+
serviceManager = 'systemd';
|
|
403
|
+
serviceUnit = 'sshift.service';
|
|
404
|
+
console.log('[UPDATE] Detected active systemd service:', serviceUnit);
|
|
330
405
|
}
|
|
331
406
|
} catch (e) {
|
|
332
407
|
// Not a systemd service or systemctl not available
|
|
333
408
|
}
|
|
334
409
|
}
|
|
410
|
+
// macOS: check if sshift is managed by launchd
|
|
411
|
+
if (!isServiceManaged && platform === 'darwin') {
|
|
412
|
+
try {
|
|
413
|
+
const { execSync: execSync2 } = require('child_process');
|
|
414
|
+
// Check for the sshift launchd plist (installed by sshift-install.sh)
|
|
415
|
+
const plistCheck = execSync2('launchctl list com.sshift.server 2>/dev/null', { encoding: 'utf8' }).trim();
|
|
416
|
+
if (plistCheck && plistCheck.length > 0) {
|
|
417
|
+
isServiceManaged = true;
|
|
418
|
+
serviceManager = 'launchd';
|
|
419
|
+
serviceUnit = 'com.sshift.server';
|
|
420
|
+
console.log('[UPDATE] Detected launchd-managed service:', serviceUnit);
|
|
421
|
+
}
|
|
422
|
+
} catch (e) {
|
|
423
|
+
// Not a launchd service
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
// Windows: check if sshift is in Task Scheduler
|
|
427
|
+
if (!isServiceManaged && platform === 'win32') {
|
|
428
|
+
try {
|
|
429
|
+
const { execSync: execSync2 } = require('child_process');
|
|
430
|
+
const taskCheck = execSync2('schtasks /query /tn sshift 2>nul', { encoding: 'utf8' }).trim();
|
|
431
|
+
if (taskCheck && taskCheck.includes('sshift')) {
|
|
432
|
+
isServiceManaged = true;
|
|
433
|
+
serviceManager = 'taskscheduler';
|
|
434
|
+
serviceUnit = 'sshift';
|
|
435
|
+
console.log('[UPDATE] Detected Task Scheduler task:', serviceUnit);
|
|
436
|
+
}
|
|
437
|
+
} catch (e) {
|
|
438
|
+
// Not a scheduled task
|
|
439
|
+
}
|
|
440
|
+
}
|
|
335
441
|
|
|
336
442
|
// Build PATH for the update script to ensure npm and node are findable
|
|
337
443
|
const pathDirs = [];
|
|
@@ -347,12 +453,14 @@ function registerSystemEndpoints(app, io) {
|
|
|
347
453
|
res.json({ message: 'Update started. Server will restart automatically.' });
|
|
348
454
|
|
|
349
455
|
if (platform === 'win32') {
|
|
456
|
+
const psTargetSpec = targetVersion !== 'latest' ? `@${targetVersion}` : '@latest';
|
|
350
457
|
const sshiftCmd = sshiftBinPath.includes(' ') ? `& '${sshiftBinPath}'` : `sshift`;
|
|
351
458
|
const psScript = `$ErrorActionPreference = 'Continue'
|
|
352
459
|
$MarkerPath = '${updateMarker}'
|
|
353
460
|
$LogPath = '${updateLogPath}'
|
|
354
461
|
$NodeExe = '${nodeExe}'
|
|
355
462
|
$SshiftBin = '${sshiftBinPath}'
|
|
463
|
+
$TargetSpec = '${psTargetSpec}'
|
|
356
464
|
|
|
357
465
|
# Check if running under Task Scheduler
|
|
358
466
|
$TaskName = "sshift"
|
|
@@ -374,8 +482,8 @@ try {
|
|
|
374
482
|
$NpmSuccess = $false
|
|
375
483
|
while ($NpmAttempts -lt $NpmMaxAttempts) {
|
|
376
484
|
$NpmAttempts++
|
|
377
|
-
Write-Output "$(Get-Date): npm install attempt $NpmAttempts of $NpmMaxAttempts" | Out-File -FilePath $LogPath -Append
|
|
378
|
-
& npm install -g @lethevimlet/sshift
|
|
485
|
+
Write-Output "$(Get-Date): npm install attempt $NpmAttempts of $NpmMaxAttempts (target: @lethevimlet/sshift$TargetSpec)" | Out-File -FilePath $LogPath -Append
|
|
486
|
+
& npm install -g "@lethevimlet/sshift$TargetSpec" 2>&1 | Out-File -FilePath $LogPath -Append
|
|
379
487
|
if ($LASTEXITCODE -eq 0) {
|
|
380
488
|
$NpmSuccess = $true
|
|
381
489
|
break
|
|
@@ -426,20 +534,23 @@ NPM_BIN="${npmBinPath}"
|
|
|
426
534
|
SSHIFT_FALLBACK="${sshiftBinPath}"
|
|
427
535
|
NODE_BIN="${nodeExe}"
|
|
428
536
|
OLD_VERSION="${oldVersion}"
|
|
429
|
-
|
|
430
|
-
|
|
537
|
+
TARGET_VERSION="${targetVersion}"
|
|
538
|
+
SERVICE_MANAGED="${isServiceManaged ? '1' : '0'}"
|
|
539
|
+
SERVICE_MANAGER="${serviceManager}"
|
|
540
|
+
SERVICE_UNIT="${serviceUnit}"
|
|
431
541
|
|
|
432
|
-
|
|
542
|
+
INSTALL_SPEC="@lethevimlet/sshift@${targetVersion}"
|
|
543
|
+
echo "$(date): Starting sshift update (from v${oldVersion} to ${targetVersion})..." > "$LOG"
|
|
433
544
|
echo "$(date): npm path: $NPM_BIN" >> "$LOG"
|
|
434
545
|
echo "$(date): node path: $NODE_BIN" >> "$LOG"
|
|
435
546
|
echo "$(date): sshift fallback: $SSHIFT_FALLBACK" >> "$LOG"
|
|
436
|
-
echo "$(date):
|
|
547
|
+
echo "$(date): service_managed: $SERVICE_MANAGED manager: $SERVICE_MANAGER unit: $SERVICE_UNIT" >> "$LOG"
|
|
437
548
|
|
|
438
549
|
# Find the current sshift binary before npm changes anything
|
|
439
550
|
CURRENT_SSHIFT="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$SSHIFT_FALLBACK")"
|
|
440
551
|
|
|
441
552
|
# Run npm install (with retry for registry propagation delay)
|
|
442
|
-
echo "$(date): Running npm install..." >> "$LOG"
|
|
553
|
+
echo "$(date): Running npm install $INSTALL_SPEC ..." >> "$LOG"
|
|
443
554
|
NPM_ATTEMPTS=0
|
|
444
555
|
NPM_MAX_ATTEMPTS=3
|
|
445
556
|
NPM_DELAY=30
|
|
@@ -447,7 +558,7 @@ NPM_SUCCESS=false
|
|
|
447
558
|
while [ $NPM_ATTEMPTS -lt $NPM_MAX_ATTEMPTS ]; do
|
|
448
559
|
NPM_ATTEMPTS=$((NPM_ATTEMPTS + 1))
|
|
449
560
|
echo "$(date): npm install attempt $NPM_ATTEMPTS of $NPM_MAX_ATTEMPTS" >> "$LOG"
|
|
450
|
-
if "$NPM_BIN" install -g
|
|
561
|
+
if "$NPM_BIN" install -g "$INSTALL_SPEC" >> "$LOG" 2>&1; then
|
|
451
562
|
NPM_SUCCESS=true
|
|
452
563
|
break
|
|
453
564
|
fi
|
|
@@ -463,9 +574,12 @@ if [ "$NPM_SUCCESS" != "true" ]; then
|
|
|
463
574
|
echo "npm install failed" >> "$LOG"
|
|
464
575
|
rm -f "$MARKER"
|
|
465
576
|
# Always restart the server — the old version is still installed
|
|
466
|
-
if [ "$
|
|
577
|
+
if [ "$SERVICE_MANAGED" = "1" ] && [ "$SERVICE_MANAGER" = "systemd" ]; then
|
|
467
578
|
echo "$(date): Restarting via systemd (old version)" >> "$LOG"
|
|
468
|
-
systemctl start "$
|
|
579
|
+
systemctl start "$SERVICE_UNIT" >> "$LOG" 2>&1
|
|
580
|
+
elif [ "$SERVICE_MANAGED" = "1" ] && [ "$SERVICE_MANAGER" = "launchd" ]; then
|
|
581
|
+
echo "$(date): Restarting via launchd (old version)" >> "$LOG"
|
|
582
|
+
launchctl start "$SERVICE_UNIT" >> "$LOG" 2>&1
|
|
469
583
|
else
|
|
470
584
|
echo "$(date): Restarting sshift (old version) from: $CURRENT_SSHIFT" >> "$LOG"
|
|
471
585
|
exec "$NODE_BIN" "$CURRENT_SSHIFT"
|
|
@@ -477,9 +591,15 @@ echo "$(date): npm install completed successfully" >> "$LOG"
|
|
|
477
591
|
# Remove the update marker before restart
|
|
478
592
|
rm -f "$MARKER"
|
|
479
593
|
|
|
480
|
-
if [ "$
|
|
594
|
+
if [ "$SERVICE_MANAGED" = "1" ] && [ "$SERVICE_MANAGER" = "systemd" ]; then
|
|
481
595
|
echo "$(date): Restarting via systemd" >> "$LOG"
|
|
482
|
-
systemctl restart "$
|
|
596
|
+
systemctl restart "$SERVICE_UNIT" >> "$LOG" 2>&1
|
|
597
|
+
elif [ "$SERVICE_MANAGED" = "1" ] && [ "$SERVICE_MANAGER" = "launchd" ]; then
|
|
598
|
+
echo "$(date): Restarting via launchd" >> "$LOG"
|
|
599
|
+
# launchd doesn't have restart; stop and start
|
|
600
|
+
launchctl stop "$SERVICE_UNIT" >> "$LOG" 2>&1 || true
|
|
601
|
+
sleep 1
|
|
602
|
+
launchctl start "$SERVICE_UNIT" >> "$LOG" 2>&1
|
|
483
603
|
else
|
|
484
604
|
# Find the sshift binary — prefer PATH lookup since npm just updated it
|
|
485
605
|
SSHIFT_BIN="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$SSHIFT_FALLBACK")"
|
|
@@ -506,7 +626,7 @@ fi
|
|
|
506
626
|
let spawnCommand, spawnArgs;
|
|
507
627
|
if (platform === 'win32') {
|
|
508
628
|
spawnCommand = 'powershell';
|
|
509
|
-
spawnArgs = ['-ExecutionPolicy', '
|
|
629
|
+
spawnArgs = ['-ExecutionPolicy', 'RemoteSigned', '-File', updateScriptPath.replace('.sh', '.ps1')];
|
|
510
630
|
} else {
|
|
511
631
|
spawnCommand = '/bin/sh';
|
|
512
632
|
spawnArgs = [updateScriptPath];
|
|
@@ -515,11 +635,13 @@ fi
|
|
|
515
635
|
const updateEnv = { ...process.env };
|
|
516
636
|
updateEnv.PATH = scriptPath;
|
|
517
637
|
|
|
518
|
-
// When running under systemd, spawn the update
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
|
|
638
|
+
// When running under a service manager (systemd/launchd), spawn the update
|
|
639
|
+
// script in its own scope so it survives a service restart.
|
|
640
|
+
// For systemd: use systemd-run --scope to escape the service cgroup.
|
|
641
|
+
// For launchd on macOS: no special handling needed (launchd doesn't kill
|
|
642
|
+
// child processes on stop like systemd does, it only sends SIGTERM to the
|
|
643
|
+
// main process, and our process.exit(0) handles that).
|
|
644
|
+
if (isServiceManaged && serviceManager === 'systemd' && platform !== 'win32') {
|
|
523
645
|
try {
|
|
524
646
|
const systemdRunCheck = require('child_process').execSync('command -v systemd-run', { encoding: 'utf8' }).trim();
|
|
525
647
|
if (systemdRunCheck) {
|
|
@@ -548,11 +670,11 @@ fi
|
|
|
548
670
|
updateProcess.unref();
|
|
549
671
|
|
|
550
672
|
// Give the update script enough time to start before exiting.
|
|
551
|
-
// Under systemd: we exit so
|
|
552
|
-
//
|
|
553
|
-
// so
|
|
554
|
-
//
|
|
555
|
-
const exitDelay =
|
|
673
|
+
// Under systemd: we exit so systemctl restart can bring up the new version.
|
|
674
|
+
// The script runs in a separate systemd scope so it survives the restart.
|
|
675
|
+
// Under launchd: we exit so launchd stop/start can bring up the new version.
|
|
676
|
+
// For non-managed: we exit so the script can exec the new binary.
|
|
677
|
+
const exitDelay = isServiceManaged ? 1000 : 2000;
|
|
556
678
|
setTimeout(() => {
|
|
557
679
|
if (spawnFailed) {
|
|
558
680
|
console.error('[UPDATE] Update process failed to start. Keeping server running.');
|
package/sshift
CHANGED
|
@@ -37,7 +37,6 @@ const os = require('os');
|
|
|
37
37
|
// Get the directory where this script is located
|
|
38
38
|
const scriptDir = __dirname;
|
|
39
39
|
const serverPath = path.join(scriptDir, 'src', 'server', 'index.js');
|
|
40
|
-
const pidFile = path.join(os.homedir(), '.local', 'share', 'sshift', '.sshift.pid');
|
|
41
40
|
|
|
42
41
|
// CLI argument parsing
|
|
43
42
|
const args = process.argv.slice(2);
|
|
@@ -83,6 +82,9 @@ for (let i = 0; i < args.length; i++) {
|
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
|
85
|
+
// PID file: dev instance uses a separate file so both can run side by side
|
|
86
|
+
const pidFile = path.join(os.homedir(), '.local', 'share', 'sshift', options.dev ? '.sshift-dev.pid' : '.sshift.pid');
|
|
87
|
+
|
|
86
88
|
// Show help
|
|
87
89
|
if (options.help) {
|
|
88
90
|
console.log(`
|
|
@@ -96,12 +98,15 @@ Usage:
|
|
|
96
98
|
./sshift --stop Stop running instance
|
|
97
99
|
./sshift --restart Restart running instance
|
|
98
100
|
./sshift --status Check if sshift is running
|
|
101
|
+
./sshift --dev --status Check if dev instance is running
|
|
102
|
+
./sshift --dev --stop Stop dev instance
|
|
103
|
+
./sshift --dev --restart Restart dev instance
|
|
99
104
|
./sshift --help Show this help message
|
|
100
105
|
|
|
101
106
|
Options:
|
|
102
107
|
-p, --port <port> Server port (default: 8022, dev: 3000)
|
|
103
108
|
-b, --bind <address> Bind address (default: 0.0.0.0)
|
|
104
|
-
-d, --dev Development mode
|
|
109
|
+
-d, --dev Development mode (separate PID file for --status/--stop/--restart)
|
|
105
110
|
-s, --stop Stop running instance
|
|
106
111
|
-r, --restart Restart running instance
|
|
107
112
|
--status Check running status
|
|
@@ -183,15 +188,15 @@ function isRunning() {
|
|
|
183
188
|
}
|
|
184
189
|
|
|
185
190
|
// Helper: Stop running instance
|
|
186
|
-
function stopInstance() {
|
|
191
|
+
function stopInstance(label) {
|
|
187
192
|
const status = isRunning();
|
|
188
193
|
|
|
189
194
|
if (!status.running) {
|
|
190
|
-
console.log(
|
|
195
|
+
console.log(`${label} is not running`);
|
|
191
196
|
return true;
|
|
192
197
|
}
|
|
193
198
|
|
|
194
|
-
console.log(`Stopping
|
|
199
|
+
console.log(`Stopping ${label} (PID: ${status.pid})...`);
|
|
195
200
|
|
|
196
201
|
try {
|
|
197
202
|
process.kill(status.pid, 'SIGTERM');
|
|
@@ -225,10 +230,10 @@ function stopInstance() {
|
|
|
225
230
|
fs.unlinkSync(pidFile);
|
|
226
231
|
}
|
|
227
232
|
|
|
228
|
-
console.log(
|
|
233
|
+
console.log(`${label} stopped successfully`);
|
|
229
234
|
return true;
|
|
230
235
|
} catch (e) {
|
|
231
|
-
console.error(`Error stopping
|
|
236
|
+
console.error(`Error stopping ${label}: ${e.message}`);
|
|
232
237
|
return false;
|
|
233
238
|
}
|
|
234
239
|
}
|
|
@@ -236,25 +241,28 @@ function stopInstance() {
|
|
|
236
241
|
// Handle --status
|
|
237
242
|
if (options.status) {
|
|
238
243
|
const status = isRunning();
|
|
244
|
+
const label = options.dev ? 'sshift (dev)' : 'sshift';
|
|
239
245
|
if (status.running) {
|
|
240
|
-
console.log(
|
|
246
|
+
console.log(`${label} is running (PID: ${status.pid})`);
|
|
241
247
|
process.exit(0);
|
|
242
248
|
} else {
|
|
243
|
-
console.log(
|
|
249
|
+
console.log(`${label} is not running`);
|
|
244
250
|
process.exit(1);
|
|
245
251
|
}
|
|
246
252
|
}
|
|
247
253
|
|
|
248
254
|
// Handle --stop
|
|
249
255
|
if (options.stop) {
|
|
250
|
-
const
|
|
256
|
+
const label = options.dev ? 'sshift (dev)' : 'sshift';
|
|
257
|
+
const success = stopInstance(label);
|
|
251
258
|
process.exit(success ? 0 : 1);
|
|
252
259
|
}
|
|
253
260
|
|
|
254
261
|
// Handle --restart
|
|
255
262
|
if (options.restart) {
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
const label = options.dev ? 'sshift (dev)' : 'sshift';
|
|
264
|
+
console.log(`Restarting ${label}...`);
|
|
265
|
+
stopInstance(label);
|
|
258
266
|
// Continue to start below
|
|
259
267
|
}
|
|
260
268
|
|