|
|
@ -1,5 +1,11 @@
|
|
|
|
var fork = require('child_process').fork,
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var nconf = require('nconf'),
|
|
|
|
|
|
|
|
fs = require('fs'),
|
|
|
|
|
|
|
|
pidFilePath = __dirname + '/pidfile',
|
|
|
|
start = function() {
|
|
|
|
start = function() {
|
|
|
|
|
|
|
|
var fork = require('child_process').fork,
|
|
|
|
|
|
|
|
nbb_start = function() {
|
|
|
|
nbb = fork('./app', process.argv.slice(2), {
|
|
|
|
nbb = fork('./app', process.argv.slice(2), {
|
|
|
|
env: {
|
|
|
|
env: {
|
|
|
|
'NODE_ENV': process.env.NODE_ENV
|
|
|
|
'NODE_ENV': process.env.NODE_ENV
|
|
|
@ -9,18 +15,51 @@ var fork = require('child_process').fork,
|
|
|
|
nbb.on('message', function(cmd) {
|
|
|
|
nbb.on('message', function(cmd) {
|
|
|
|
if (cmd === 'nodebb:restart') {
|
|
|
|
if (cmd === 'nodebb:restart') {
|
|
|
|
nbb.on('exit', function() {
|
|
|
|
nbb.on('exit', function() {
|
|
|
|
start();
|
|
|
|
nbb_start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
nbb.kill();
|
|
|
|
nbb.kill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
stop = function() {
|
|
|
|
nbb_stop = function() {
|
|
|
|
nbb.kill();
|
|
|
|
nbb.kill();
|
|
|
|
|
|
|
|
if (fs.existsSync(pidFilePath)) {
|
|
|
|
|
|
|
|
var pid = parseInt(fs.readFileSync(pidFilePath, { encoding: 'utf-8' }), 10);
|
|
|
|
|
|
|
|
if (process.pid === pid) {
|
|
|
|
|
|
|
|
fs.unlinkSync(pidFilePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process.on('SIGINT', nbb_stop);
|
|
|
|
|
|
|
|
process.on('SIGTERM', nbb_stop);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nbb_start();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nbb;
|
|
|
|
nbb;
|
|
|
|
|
|
|
|
|
|
|
|
process.on('SIGINT', stop);
|
|
|
|
nconf.argv();
|
|
|
|
process.on('SIGTERM', stop);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nconf.get('d')) {
|
|
|
|
|
|
|
|
// Check for a still-active NodeBB process
|
|
|
|
|
|
|
|
if (fs.existsSync(pidFilePath)) {
|
|
|
|
|
|
|
|
console.log('\n Error: Another NodeBB is already running!');
|
|
|
|
|
|
|
|
process.exit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialise logging streams
|
|
|
|
|
|
|
|
var outputStream = fs.createWriteStream(__dirname + '/logs/output.log');
|
|
|
|
|
|
|
|
outputStream.on('open', function(fd) {
|
|
|
|
|
|
|
|
// Daemonize
|
|
|
|
|
|
|
|
require('daemon')({
|
|
|
|
|
|
|
|
stdout: fd
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write its pid to a pidfile
|
|
|
|
|
|
|
|
fs.writeFile(__dirname + '/pidfile', process.pid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
start();
|
|
|
|
start();
|
|
|
|
|
|
|
|
}
|