@drocketxx/pm2me 1.1.34 → 1.1.36
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/backend/routes/api.js +31 -1
- package/package.json +1 -1
package/backend/routes/api.js
CHANGED
|
@@ -16,6 +16,9 @@ import os from 'os';
|
|
|
16
16
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
17
17
|
const getWorkspacesDir = () => db.data.settings?.appsPath || path.resolve(__dirname, '../../apps');
|
|
18
18
|
|
|
19
|
+
// Track active build processes to prevent concurrent builds
|
|
20
|
+
const activeBuildProcesses = new Map();
|
|
21
|
+
|
|
19
22
|
const router = express.Router();
|
|
20
23
|
|
|
21
24
|
// GET all PM2 apps
|
|
@@ -396,6 +399,24 @@ export const performDeployment = async (appId, io) => {
|
|
|
396
399
|
fs.writeFileSync(path.join(targetPath, '.env'), envFileData);
|
|
397
400
|
|
|
398
401
|
if (appConfig.buildScript) {
|
|
402
|
+
// Kill any existing build process for this app
|
|
403
|
+
if (activeBuildProcesses.has(appId)) {
|
|
404
|
+
const existingProcess = activeBuildProcesses.get(appId);
|
|
405
|
+
logProcess('Killing existing build process...', true);
|
|
406
|
+
try {
|
|
407
|
+
existingProcess.kill('SIGTERM');
|
|
408
|
+
// Give it a moment to terminate gracefully
|
|
409
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
410
|
+
if (!existingProcess.killed) {
|
|
411
|
+
existingProcess.kill('SIGKILL');
|
|
412
|
+
}
|
|
413
|
+
activeBuildProcesses.delete(appId);
|
|
414
|
+
logProcess('Existing build process terminated', true);
|
|
415
|
+
} catch (killErr) {
|
|
416
|
+
logProcess(`Warning: Failed to kill existing build process: ${killErr.message}`, true);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
399
420
|
const normalizedScript = appConfig.buildScript.split('\n')
|
|
400
421
|
.map(s => s.trim())
|
|
401
422
|
.filter(Boolean)
|
|
@@ -406,13 +427,22 @@ export const performDeployment = async (appId, io) => {
|
|
|
406
427
|
logProcess('Executing Build Script', true);
|
|
407
428
|
await new Promise((resolve, reject) => {
|
|
408
429
|
const child = exec(normalizedScript, { cwd: targetPath, maxBuffer: 10 * 1024 * 1024, windowsHide: true });
|
|
430
|
+
|
|
431
|
+
// Store the build process
|
|
432
|
+
activeBuildProcesses.set(appId, child);
|
|
433
|
+
|
|
409
434
|
child.stdout.on('data', data => { io.emit(`deploy-log-${appId}`, data.toString()); fs.appendFileSync(logFilePath, data); });
|
|
410
435
|
child.stderr.on('data', data => { io.emit(`deploy-log-${appId}`, data.toString()); fs.appendFileSync(logFilePath, data); });
|
|
411
436
|
child.on('close', code => {
|
|
437
|
+
// Remove from active processes when done
|
|
438
|
+
activeBuildProcesses.delete(appId);
|
|
412
439
|
if (code !== 0) reject(new Error(`Build script exited with code ${code}`));
|
|
413
440
|
else { logProcess('Build Script Completed', true); resolve(); }
|
|
414
441
|
});
|
|
415
|
-
child.on('error', err => {
|
|
442
|
+
child.on('error', err => {
|
|
443
|
+
activeBuildProcesses.delete(appId);
|
|
444
|
+
reject(err);
|
|
445
|
+
});
|
|
416
446
|
});
|
|
417
447
|
}
|
|
418
448
|
|