@lethevimlet/sshift 1.0.4 → 1.0.5
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 +1 -1
- package/src/server/endpoints/rest/sessions.js +3 -0
- package/src/server/endpoints/ws/sftp.js +3 -1
- package/src/server/endpoints/ws/ssh.js +3 -2
- package/src/server/endpoints/ws/tabs.js +2 -0
- package/src/server/index.js +18 -3
- package/src/server/services/ssh-manager.js +22 -4
- package/src/webapp/index.html +54 -53
- package/src/webapp/js/app.js +15 -2
- package/src/webapp/sw.js +19 -2
- package/sshift +44 -2
- package/sshift-install.ps1 +1 -1
- package/sshift-install.sh +1 -1
package/package.json
CHANGED
|
@@ -76,6 +76,7 @@ function registerSessionsEndpoints(app, io) {
|
|
|
76
76
|
|
|
77
77
|
// Broadcast to all clients that the session was closed
|
|
78
78
|
io.emit('tab-closed', { sessionId });
|
|
79
|
+
io.emit('sessions-updated');
|
|
79
80
|
|
|
80
81
|
res.json({ success: true, sessionId });
|
|
81
82
|
});
|
|
@@ -106,6 +107,8 @@ function registerSessionsEndpoints(app, io) {
|
|
|
106
107
|
removeTab(sessionId);
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
io.emit('sessions-updated');
|
|
111
|
+
|
|
109
112
|
res.json({ success: true, closedCount: closedSessions.length });
|
|
110
113
|
});
|
|
111
114
|
}
|
|
@@ -44,7 +44,6 @@ function registerSFTPHandlers(socket, io) {
|
|
|
44
44
|
sticky: sticky
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
// Broadcast to all clients that a new tab was opened
|
|
48
47
|
io.emit('tab-opened', {
|
|
49
48
|
sessionId,
|
|
50
49
|
name: data.name || 'SFTP',
|
|
@@ -52,6 +51,8 @@ function registerSFTPHandlers(socket, io) {
|
|
|
52
51
|
connectionData: data
|
|
53
52
|
});
|
|
54
53
|
|
|
54
|
+
io.emit('sessions-updated');
|
|
55
|
+
|
|
55
56
|
socket.emit('sftp-connected', { sessionId });
|
|
56
57
|
} catch (err) {
|
|
57
58
|
console.error('[SFTP] Error in sftp-connect:', err.message);
|
|
@@ -135,6 +136,7 @@ function registerSFTPHandlers(socket, io) {
|
|
|
135
136
|
|
|
136
137
|
// Broadcast to all clients that tab was closed
|
|
137
138
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
139
|
+
io.emit('sessions-updated');
|
|
138
140
|
});
|
|
139
141
|
}
|
|
140
142
|
|
|
@@ -51,7 +51,6 @@ function registerSSHHandlers(socket, io) {
|
|
|
51
51
|
sticky: sticky
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
// Broadcast to all clients that a new tab was opened
|
|
55
54
|
io.emit('tab-opened', {
|
|
56
55
|
sessionId,
|
|
57
56
|
name: data.name || 'SSH',
|
|
@@ -59,6 +58,8 @@ function registerSSHHandlers(socket, io) {
|
|
|
59
58
|
connectionData: data
|
|
60
59
|
});
|
|
61
60
|
|
|
61
|
+
io.emit('sessions-updated');
|
|
62
|
+
|
|
62
63
|
socket.emit('ssh-connected', { sessionId });
|
|
63
64
|
} catch (err) {
|
|
64
65
|
console.error('[SSH] Connection failed:', err.message);
|
|
@@ -160,8 +161,8 @@ function registerSSHHandlers(socket, io) {
|
|
|
160
161
|
// Remove from open tabs and order
|
|
161
162
|
removeTab(data.sessionId);
|
|
162
163
|
|
|
163
|
-
// Broadcast to all clients that tab was closed
|
|
164
164
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
165
|
+
io.emit('sessions-updated');
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
168
|
|
|
@@ -55,10 +55,12 @@ function registerTabHandlers(socket, io) {
|
|
|
55
55
|
|
|
56
56
|
// Broadcast to all clients that tab was closed
|
|
57
57
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
58
|
+
io.emit('sessions-updated');
|
|
58
59
|
}
|
|
59
60
|
} else {
|
|
60
61
|
// Broadcast to all clients that tab was closed
|
|
61
62
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
63
|
+
io.emit('sessions-updated');
|
|
62
64
|
}
|
|
63
65
|
});
|
|
64
66
|
|
package/src/server/index.js
CHANGED
|
@@ -304,16 +304,31 @@ async function initializeServer() {
|
|
|
304
304
|
app.use('/tests', express.static(path.join(webappPath, 'tests')));
|
|
305
305
|
|
|
306
306
|
// Service Worker script - must be served from root with proper headers
|
|
307
|
+
// Version placeholder is replaced dynamically so the cache busts on each update
|
|
307
308
|
app.get('/sw.js', (req, res) => {
|
|
308
309
|
res.setHeader('Content-Type', 'application/javascript');
|
|
309
310
|
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
310
311
|
res.setHeader('Service-Worker-Allowed', '/');
|
|
311
|
-
|
|
312
|
+
const swPath = path.join(webappPath, 'sw.js');
|
|
313
|
+
fs.readFile(swPath, 'utf8', (err, data) => {
|
|
314
|
+
if (err) return res.status(500).send('/* SW load error */');
|
|
315
|
+
const version = require(path.join(__dirname, '../../package.json')).version;
|
|
316
|
+
res.send(data.replace(/__VERSION__/g, version));
|
|
317
|
+
});
|
|
312
318
|
});
|
|
313
319
|
|
|
314
|
-
// Main route
|
|
320
|
+
// Main route - no-cache so browser always checks for updates
|
|
321
|
+
// Version placeholder is replaced dynamically for cache-busting
|
|
315
322
|
app.get('/', (req, res) => {
|
|
316
|
-
res.
|
|
323
|
+
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
324
|
+
res.setHeader('Pragma', 'no-cache');
|
|
325
|
+
res.setHeader('Expires', '0');
|
|
326
|
+
const htmlPath = path.join(webappPath, 'index.html');
|
|
327
|
+
fs.readFile(htmlPath, 'utf8', (err, data) => {
|
|
328
|
+
if (err) return res.status(500).send('Error loading page');
|
|
329
|
+
const version = require(path.join(__dirname, '../../package.json')).version;
|
|
330
|
+
res.send(data.replace(/__VERSION__/g, version));
|
|
331
|
+
});
|
|
317
332
|
});
|
|
318
333
|
|
|
319
334
|
// Register REST endpoints
|
|
@@ -166,10 +166,10 @@ class SSHManager {
|
|
|
166
166
|
|
|
167
167
|
stream.on('close', () => {
|
|
168
168
|
console.log(`[SSH] Stream closed: ${sessionId}`);
|
|
169
|
-
// Flush any remaining buffered data before disconnect
|
|
170
169
|
this.flushData(sessionId);
|
|
171
170
|
this.broadcastToSession(sessionId, 'ssh-disconnected', { sessionId });
|
|
172
171
|
this.disconnect(sessionId);
|
|
172
|
+
if (this.io) this.io.emit('sessions-updated');
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
stream.on('exit', (code, signal) => {
|
|
@@ -190,6 +190,7 @@ class SSHManager {
|
|
|
190
190
|
console.error(`[SSH] Connection error: ${err.message}`);
|
|
191
191
|
socket.emit('ssh-error', { sessionId, message: err.message });
|
|
192
192
|
this.sessions.delete(sessionId);
|
|
193
|
+
if (this.io) this.io.emit('sessions-updated');
|
|
193
194
|
reject(err);
|
|
194
195
|
});
|
|
195
196
|
|
|
@@ -197,6 +198,7 @@ class SSHManager {
|
|
|
197
198
|
console.log(`[SSH] Connection closed: ${sessionId}`);
|
|
198
199
|
this.broadcastToSession(sessionId, 'ssh-disconnected', { sessionId });
|
|
199
200
|
this.sessions.delete(sessionId);
|
|
201
|
+
if (this.io) this.io.emit('sessions-updated');
|
|
200
202
|
});
|
|
201
203
|
|
|
202
204
|
try {
|
|
@@ -357,11 +359,15 @@ class SSHManager {
|
|
|
357
359
|
socket.emit('ssh-joined', {
|
|
358
360
|
sessionId: sessionId,
|
|
359
361
|
noTerminalState: !hasTerminalState,
|
|
360
|
-
controllerSocket: session.controllerSocket,
|
|
361
|
-
isController: session.controllerSocket === socket.id,
|
|
362
|
-
socketCount: session.sockets.size
|
|
362
|
+
controllerSocket: session.controllerSocket,
|
|
363
|
+
isController: session.controllerSocket === socket.id,
|
|
364
|
+
socketCount: session.sockets.size
|
|
363
365
|
});
|
|
364
366
|
|
|
367
|
+
if (this.io) {
|
|
368
|
+
this.io.emit('sessions-updated');
|
|
369
|
+
}
|
|
370
|
+
|
|
365
371
|
return true;
|
|
366
372
|
}
|
|
367
373
|
|
|
@@ -398,6 +404,10 @@ class SSHManager {
|
|
|
398
404
|
session.controllerSocket = null;
|
|
399
405
|
}
|
|
400
406
|
}
|
|
407
|
+
|
|
408
|
+
if (this.io) {
|
|
409
|
+
this.io.emit('sessions-updated');
|
|
410
|
+
}
|
|
401
411
|
}
|
|
402
412
|
|
|
403
413
|
// Take control of a session
|
|
@@ -430,6 +440,10 @@ class SSHManager {
|
|
|
430
440
|
});
|
|
431
441
|
}
|
|
432
442
|
|
|
443
|
+
if (this.io) {
|
|
444
|
+
this.io.emit('sessions-updated');
|
|
445
|
+
}
|
|
446
|
+
|
|
433
447
|
return {
|
|
434
448
|
success: true,
|
|
435
449
|
cols: session.cols,
|
|
@@ -465,6 +479,10 @@ class SSHManager {
|
|
|
465
479
|
session.controllerSocket = null;
|
|
466
480
|
}
|
|
467
481
|
|
|
482
|
+
if (this.io) {
|
|
483
|
+
this.io.emit('sessions-updated');
|
|
484
|
+
}
|
|
485
|
+
|
|
468
486
|
return { success: true };
|
|
469
487
|
}
|
|
470
488
|
|
package/src/webapp/index.html
CHANGED
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
10
10
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
11
11
|
<meta name="apple-mobile-web-app-title" content="SSHIFT">
|
|
12
|
-
<link rel="manifest" href="/manifest.json">
|
|
12
|
+
<link rel="manifest" href="/manifest.json?v=__VERSION__">
|
|
13
13
|
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
|
|
14
14
|
<link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png">
|
|
15
15
|
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png">
|
|
16
16
|
<title>SSHIFT - SSH & SFTP Terminal Client</title>
|
|
17
17
|
<!-- Local resources for offline support -->
|
|
18
|
-
<link rel="stylesheet" href="/libs/xterm/xterm.css">
|
|
19
|
-
<link rel="stylesheet" href="/libs/font-awesome/css/all.min.css">
|
|
20
|
-
<link rel="stylesheet" href="/css/style.css">
|
|
21
|
-
<script src="/libs/lucide/lucide.min.js"></script>
|
|
18
|
+
<link rel="stylesheet" href="/libs/xterm/xterm.css?v=__VERSION__">
|
|
19
|
+
<link rel="stylesheet" href="/libs/font-awesome/css/all.min.css?v=__VERSION__">
|
|
20
|
+
<link rel="stylesheet" href="/css/style.css?v=__VERSION__">
|
|
21
|
+
<script src="/libs/lucide/lucide.min.js?v=__VERSION__"></script>
|
|
22
22
|
</head>
|
|
23
23
|
<body>
|
|
24
24
|
<!-- Lock Screen Overlay (shown by default, hidden by JS if no password) -->
|
|
@@ -1138,16 +1138,16 @@
|
|
|
1138
1138
|
|
|
1139
1139
|
<!-- Scripts -->
|
|
1140
1140
|
<!-- xterm.js and addons - Local files for offline support -->
|
|
1141
|
-
<script src="/libs/xterm/xterm.js"></script>
|
|
1142
|
-
<script src="/libs/xterm/xterm-addon-fit.js"></script>
|
|
1143
|
-
<script src="/libs/xterm/xterm-addon-web-links.js"></script>
|
|
1144
|
-
<script src="/libs/xterm/xterm-addon-search.js"></script>
|
|
1145
|
-
<script src="/libs/xterm/xterm-addon-serialize.js"></script>
|
|
1146
|
-
<script src="/libs/xterm/xterm-addon-webgl.js"></script>
|
|
1147
|
-
<script src="/libs/xterm/xterm-addon-image.js"></script>
|
|
1141
|
+
<script src="/libs/xterm/xterm.js?v=__VERSION__"></script>
|
|
1142
|
+
<script src="/libs/xterm/xterm-addon-fit.js?v=__VERSION__"></script>
|
|
1143
|
+
<script src="/libs/xterm/xterm-addon-web-links.js?v=__VERSION__"></script>
|
|
1144
|
+
<script src="/libs/xterm/xterm-addon-search.js?v=__VERSION__"></script>
|
|
1145
|
+
<script src="/libs/xterm/xterm-addon-serialize.js?v=__VERSION__"></script>
|
|
1146
|
+
<script src="/libs/xterm/xterm-addon-webgl.js?v=__VERSION__"></script>
|
|
1147
|
+
<script src="/libs/xterm/xterm-addon-image.js?v=__VERSION__"></script>
|
|
1148
1148
|
|
|
1149
1149
|
<!-- Mobile terminal support -->
|
|
1150
|
-
<script src="/js/mobile-terminal.js"></script>
|
|
1150
|
+
<script src="/js/mobile-terminal.js?v=__VERSION__"></script>
|
|
1151
1151
|
|
|
1152
1152
|
<!-- Normalize addon exports - UMD pattern exports { FitAddon: class } not the class directly -->
|
|
1153
1153
|
<script>
|
|
@@ -1285,52 +1285,53 @@
|
|
|
1285
1285
|
</script>
|
|
1286
1286
|
|
|
1287
1287
|
<script src="/socket.io/socket.io.js"></script>
|
|
1288
|
-
<script src="/js/app.js"></script>
|
|
1288
|
+
<script src="/js/app.js?v=__VERSION__"></script>
|
|
1289
1289
|
<script>
|
|
1290
1290
|
if ('serviceWorker' in navigator) {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
if (
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
if (!navigator.serviceWorker.controller) {
|
|
1314
|
-
window._swStatus = 'redundant';
|
|
1315
|
-
window._swError = 'Service Worker became redundant. This usually means the certificate is not trusted.';
|
|
1316
|
-
}
|
|
1291
|
+
window.addEventListener('load', () => {
|
|
1292
|
+
navigator.serviceWorker.register('/sw.js').then((reg) => {
|
|
1293
|
+
console.log('[SSHIFT] Service Worker registered, scope:', reg.scope);
|
|
1294
|
+
window._swRegistration = reg;
|
|
1295
|
+
if (reg.active) {
|
|
1296
|
+
window._swStatus = 'active';
|
|
1297
|
+
} else if (reg.installing) {
|
|
1298
|
+
window._swStatus = 'installing';
|
|
1299
|
+
} else if (reg.waiting) {
|
|
1300
|
+
window._swStatus = 'waiting';
|
|
1301
|
+
} else {
|
|
1302
|
+
window._swStatus = 'registered';
|
|
1303
|
+
}
|
|
1304
|
+
window._swError = null;
|
|
1305
|
+
reg.addEventListener('updatefound', () => {
|
|
1306
|
+
const newWorker = reg.installing;
|
|
1307
|
+
newWorker.addEventListener('statechange', () => {
|
|
1308
|
+
if (newWorker.state === 'activated') {
|
|
1309
|
+
window._swStatus = 'active';
|
|
1310
|
+
if (navigator.serviceWorker.controller) {
|
|
1311
|
+
console.log('[SSHIFT] New service worker activated, reloading for updates');
|
|
1312
|
+
window.location.reload();
|
|
1317
1313
|
}
|
|
1318
|
-
})
|
|
1314
|
+
} else if (newWorker.state === 'redundant') {
|
|
1315
|
+
if (!navigator.serviceWorker.controller) {
|
|
1316
|
+
window._swStatus = 'redundant';
|
|
1317
|
+
window._swError = 'Service Worker became redundant. This usually means the certificate is not trusted.';
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1319
1320
|
});
|
|
1320
|
-
// Also check if the page is controlled by a SW
|
|
1321
|
-
if (navigator.serviceWorker.controller) {
|
|
1322
|
-
window._swStatus = 'active';
|
|
1323
|
-
}
|
|
1324
|
-
}).catch((err) => {
|
|
1325
|
-
console.warn('[SSHIFT] Service Worker registration failed:', err.message);
|
|
1326
|
-
window._swStatus = 'failed';
|
|
1327
|
-
window._swError = err.message;
|
|
1328
1321
|
});
|
|
1322
|
+
if (navigator.serviceWorker.controller) {
|
|
1323
|
+
window._swStatus = 'active';
|
|
1324
|
+
}
|
|
1325
|
+
}).catch((err) => {
|
|
1326
|
+
console.warn('[SSHIFT] Service Worker registration failed:', err.message);
|
|
1327
|
+
window._swStatus = 'failed';
|
|
1328
|
+
window._swError = err.message;
|
|
1329
1329
|
});
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1330
|
+
});
|
|
1331
|
+
} else {
|
|
1332
|
+
window._swStatus = 'unsupported';
|
|
1333
|
+
window._swError = 'Service Workers not supported in this browser';
|
|
1334
|
+
}
|
|
1334
1335
|
</script>
|
|
1335
1336
|
</body>
|
|
1336
1337
|
</html>
|
package/src/webapp/js/app.js
CHANGED
|
@@ -3435,6 +3435,14 @@ const wheelHandler = (e) => {
|
|
|
3435
3435
|
this.handleTabClosed(data.sessionId);
|
|
3436
3436
|
});
|
|
3437
3437
|
|
|
3438
|
+
this.socket.on('sessions-updated', () => {
|
|
3439
|
+
const modal = document.getElementById('manageSessionsModal');
|
|
3440
|
+
if (modal && modal.classList.contains('active')) {
|
|
3441
|
+
if (this._sessionsUpdateTimer) clearTimeout(this._sessionsUpdateTimer);
|
|
3442
|
+
this._sessionsUpdateTimer = setTimeout(() => this.loadSessions(), 300);
|
|
3443
|
+
}
|
|
3444
|
+
});
|
|
3445
|
+
|
|
3438
3446
|
// Handle tab order update from server
|
|
3439
3447
|
this.socket.on('tab-order', (data) => {
|
|
3440
3448
|
console.log('[SSHIFT] Tab order updated:', data.order);
|
|
@@ -5107,7 +5115,6 @@ const wheelHandler = (e) => {
|
|
|
5107
5115
|
}
|
|
5108
5116
|
|
|
5109
5117
|
initSessionsModalHandlers() {
|
|
5110
|
-
// Close button
|
|
5111
5118
|
const closeBtn = document.getElementById('closeManageSessionsModal');
|
|
5112
5119
|
if (closeBtn) {
|
|
5113
5120
|
closeBtn.addEventListener('click', () => {
|
|
@@ -5115,7 +5122,13 @@ const wheelHandler = (e) => {
|
|
|
5115
5122
|
});
|
|
5116
5123
|
}
|
|
5117
5124
|
|
|
5118
|
-
|
|
5125
|
+
const closeFooterBtn = document.getElementById('closeManageSessions');
|
|
5126
|
+
if (closeFooterBtn) {
|
|
5127
|
+
closeFooterBtn.addEventListener('click', () => {
|
|
5128
|
+
this.closeModal('manageSessionsModal');
|
|
5129
|
+
});
|
|
5130
|
+
}
|
|
5131
|
+
|
|
5119
5132
|
const closeAllBtn = document.getElementById('closeAllSessions');
|
|
5120
5133
|
if (closeAllBtn) {
|
|
5121
5134
|
closeAllBtn.addEventListener('click', () => {
|
package/src/webapp/sw.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const CACHE_NAME = 'sshift-
|
|
1
|
+
const CACHE_NAME = 'sshift-__VERSION__';
|
|
2
2
|
|
|
3
3
|
const PRECACHE_URLS = [
|
|
4
|
-
'/index.html',
|
|
5
4
|
'/css/style.css',
|
|
6
5
|
'/libs/xterm/xterm.css',
|
|
7
6
|
'/libs/font-awesome/css/all.min.css',
|
|
@@ -44,6 +43,24 @@ self.addEventListener('fetch', (event) => {
|
|
|
44
43
|
|
|
45
44
|
if (url.protocol === 'http:' || url.protocol === 'https:') {
|
|
46
45
|
if (url.pathname.startsWith('/socket.io/')) return;
|
|
46
|
+
if (url.pathname.startsWith('/api/')) return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const isNavigation = event.request.mode === 'navigate';
|
|
50
|
+
|
|
51
|
+
if (isNavigation) {
|
|
52
|
+
event.respondWith(
|
|
53
|
+
fetch(event.request)
|
|
54
|
+
.then((response) => {
|
|
55
|
+
if (response && response.status === 200) {
|
|
56
|
+
const clone = response.clone();
|
|
57
|
+
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
|
58
|
+
}
|
|
59
|
+
return response;
|
|
60
|
+
})
|
|
61
|
+
.catch(() => caches.match(event.request))
|
|
62
|
+
);
|
|
63
|
+
return;
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
event.respondWith(
|
package/sshift
CHANGED
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
|
|
33
33
|
const path = require('path');
|
|
34
34
|
const fs = require('fs');
|
|
35
|
-
const
|
|
35
|
+
const os = require('os');
|
|
36
36
|
|
|
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(
|
|
40
|
+
const pidFile = path.join(os.homedir(), '.local', 'share', 'sshift', '.sshift.pid');
|
|
41
41
|
|
|
42
42
|
// CLI argument parsing
|
|
43
43
|
const args = process.argv.slice(2);
|
|
@@ -131,6 +131,34 @@ if (!fs.existsSync(serverPath)) {
|
|
|
131
131
|
process.exit(1);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// Helper: Ensure PID file directory exists
|
|
135
|
+
function ensurePidDir() {
|
|
136
|
+
const dir = path.dirname(pidFile);
|
|
137
|
+
if (!fs.existsSync(dir)) {
|
|
138
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Helper: Write current PID to file
|
|
143
|
+
function writePidFile() {
|
|
144
|
+
ensurePidDir();
|
|
145
|
+
fs.writeFileSync(pidFile, process.pid.toString(), { mode: 0o644 });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Helper: Remove PID file
|
|
149
|
+
function cleanupPidFile() {
|
|
150
|
+
try {
|
|
151
|
+
if (fs.existsSync(pidFile)) {
|
|
152
|
+
const storedPid = parseInt(fs.readFileSync(pidFile, 'utf8').trim(), 10);
|
|
153
|
+
if (isNaN(storedPid) || storedPid === process.pid) {
|
|
154
|
+
fs.unlinkSync(pidFile);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} catch (e) {
|
|
158
|
+
// Ignore cleanup errors
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
134
162
|
// Helper: Check if sshift is running
|
|
135
163
|
function isRunning() {
|
|
136
164
|
if (fs.existsSync(pidFile)) {
|
|
@@ -265,5 +293,19 @@ if (options.dev) {
|
|
|
265
293
|
process.env.NODE_ENV = 'development';
|
|
266
294
|
}
|
|
267
295
|
|
|
296
|
+
// Write PID file before starting
|
|
297
|
+
writePidFile();
|
|
298
|
+
|
|
299
|
+
// Clean up PID file on exit
|
|
300
|
+
process.on('exit', cleanupPidFile);
|
|
301
|
+
process.on('SIGTERM', () => {
|
|
302
|
+
cleanupPidFile();
|
|
303
|
+
process.exit(0);
|
|
304
|
+
});
|
|
305
|
+
process.on('SIGINT', () => {
|
|
306
|
+
cleanupPidFile();
|
|
307
|
+
process.exit(0);
|
|
308
|
+
});
|
|
309
|
+
|
|
268
310
|
// Start the server
|
|
269
311
|
require(serverPath);
|
package/sshift-install.ps1
CHANGED
package/sshift-install.sh
CHANGED