1
1
/**
2
- * Our shim for nodebb production mode and PM2 compatibility.
2
+ * Our shim for nodebb and PM2 compatibility.
3
3
*/
4
4
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 && ' ;
9
8
const start = ( ) => {
10
9
console . log ( 'Starting nodebb...' ) ;
11
- exec ( nvmCmd + startCmd + '"' , ( error , stdout , stderr ) => {
10
+ exec ( nvmCmd + startCmd , ( error , stdout , stderr ) => {
12
11
if ( error ) {
13
12
console . error ( `Error starting nodebb: ${ error } ` ) ;
14
13
} else {
@@ -19,21 +18,22 @@ const start = () => {
19
18
20
19
const stop = ( ) => {
21
20
console . log ( 'Stopping nodebb...' ) ;
22
- exec ( nvmCmd + stopCmd + '"' , ( error , stdout , stderr ) => {
21
+ exec ( nvmCmd + stopCmd , ( error , stdout , stderr ) => {
23
22
if ( error ) {
24
23
console . error ( `Error stopping nodebb: ${ error } ` ) ;
25
24
} else {
26
25
console . log ( `nodebb stopped: ${ stdout } ` ) ;
27
26
}
28
- process . exit ( ) ;
29
27
} ) ;
30
28
} ;
31
29
32
30
// Start the nodebb process
33
31
start ( ) ;
34
32
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
+ }
39
39
} ) ;
0 commit comments