Skip to content

Commit de40118

Browse files
committed
stop fix
1 parent 99e25d0 commit de40118

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

nodeapp/nodebb.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module.exports = {
3232
if (nodeapp.hasOwnProperty('_debugPort')) {
3333
nodeapp.script = 'app.js';
3434
}
35+
nodeapp.shutdown_with_message = true;
36+
nodeapp.kill_timeout = 3000;
3537
return [nodeapp];
3638
})()
3739
}

nodeapp/nodebb.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/**
2-
* Our shim for nodebb production mode and PM2 compatibility.
2+
* Our shim for nodebb and PM2 compatibility.
33
*/
44
const { exec } = require('child_process');
5-
const startCmd = 'nodebb start';
6-
const stopCmd = 'nodebb stop';
7-
const nvmCmd = 'bash -c "export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh && nvm use && ';
8-
5+
const startCmd = './nodebb start';
6+
const stopCmd = './nodebb stop';
7+
const nvmCmd = 'cd ' + __dirname + ' && export NVM_DIR=/opt/nvm && . /opt/nvm/nvm.sh && nvm use && ';
98
const start = () => {
109
console.log('Starting nodebb...');
11-
exec(nvmCmd + startCmd + '"', (error, stdout, stderr) => {
10+
exec(nvmCmd + startCmd, (error, stdout, stderr) => {
1211
if (error) {
1312
console.error(`Error starting nodebb: ${error}`);
1413
} else {
@@ -19,21 +18,22 @@ const start = () => {
1918

2019
const stop = () => {
2120
console.log('Stopping nodebb...');
22-
exec(nvmCmd + stopCmd + '"', (error, stdout, stderr) => {
21+
exec(nvmCmd + stopCmd, (error, stdout, stderr) => {
2322
if (error) {
2423
console.error(`Error stopping nodebb: ${error}`);
2524
} else {
2625
console.log(`nodebb stopped: ${stdout}`);
2726
}
28-
process.exit();
2927
});
3028
};
3129

3230
// Start the nodebb process
3331
start();
3432

35-
// Listen for SIGINT signal
36-
process.on('SIGINT', () => {
37-
console.log('Received SIGINT signal, stopping nodebb...');
38-
stop();
33+
// Listen for custom 'shutdown' message from the parent process
34+
process.on('message', (message) => {
35+
if (message === 'shutdown') {
36+
console.log('Received shutdown message, stopping...');
37+
stop();
38+
}
3939
});

0 commit comments

Comments
 (0)