Skip to content

Commit 338611e

Browse files
committed
stop fix
1 parent 65326b5 commit 338611e

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

nodeapp/ghost.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ module.exports = {
3535
config.server.port = nodeapp._port;
3636
config.paths.contentPath = contentPath;
3737
fs.writeFileSync(file, JSON.stringify(config, null, 2));
38+
nodeapp.shutdown_with_message = true;
39+
nodeapp.kill_timeout = 3000;
3840
return [nodeapp];
3941
})()
4042
}

nodeapp/ghost.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
const { exec } = require('child_process');
55
const startCmd = 'ghost start';
66
const stopCmd = 'ghost stop';
7-
const nvmCmd = 'bash -c "export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh && nvm use && ';
8-
7+
const nvmCmd = 'cd ' + __dirname + ' && export NVM_DIR=/opt/nvm && . /opt/nvm/nvm.sh && nvm use && ';
98
const start = () => {
109
console.log('Starting ghost...');
11-
exec(nvmCmd + startCmd + '"', (error, stdout, stderr) => {
10+
exec(nvmCmd + startCmd, (error, stdout, stderr) => {
1211
if (error) {
1312
console.error(`Error starting ghost: ${error}`);
1413
} else {
@@ -19,21 +18,22 @@ const start = () => {
1918

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

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

35-
// Listen for SIGINT signal
36-
process.on('SIGINT', () => {
37-
console.log('Received SIGINT signal, stopping ghost...');
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)