mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 08:20:36 +01:00
added daemon capability to ./nodebb start, npm start/stop scripts
This commit is contained in:
77
loader.js
77
loader.js
@@ -1,26 +1,65 @@
|
|||||||
var fork = require('child_process').fork,
|
"use strict";
|
||||||
start = function() {
|
|
||||||
nbb = fork('./app', process.argv.slice(2), {
|
|
||||||
env: {
|
|
||||||
'NODE_ENV': process.env.NODE_ENV
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
nbb.on('message', function(cmd) {
|
var nconf = require('nconf'),
|
||||||
if (cmd === 'nodebb:restart') {
|
fs = require('fs'),
|
||||||
nbb.on('exit', function() {
|
pidFilePath = __dirname + '/pidfile',
|
||||||
start();
|
start = function() {
|
||||||
|
var fork = require('child_process').fork,
|
||||||
|
nbb_start = function() {
|
||||||
|
nbb = fork('./app', process.argv.slice(2), {
|
||||||
|
env: {
|
||||||
|
'NODE_ENV': process.env.NODE_ENV
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
nbb.on('message', function(cmd) {
|
||||||
|
if (cmd === 'nodebb:restart') {
|
||||||
|
nbb.on('exit', function() {
|
||||||
|
nbb_start();
|
||||||
|
});
|
||||||
|
nbb.kill();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
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) {
|
||||||
stop = function() {
|
fs.unlinkSync(pidFilePath);
|
||||||
nbb.kill();
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on('SIGINT', nbb_stop);
|
||||||
|
process.on('SIGTERM', nbb_stop);
|
||||||
|
|
||||||
|
nbb_start();
|
||||||
},
|
},
|
||||||
nbb;
|
nbb;
|
||||||
|
|
||||||
process.on('SIGINT', stop);
|
nconf.argv();
|
||||||
process.on('SIGTERM', stop);
|
|
||||||
|
|
||||||
start();
|
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();
|
||||||
|
}
|
||||||
1
logs/.gitignore
vendored
Normal file
1
logs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.log
|
||||||
14
nodebb
14
nodebb
@@ -6,7 +6,19 @@
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
node loader "$@"
|
echo "Starting NodeBB";
|
||||||
|
echo " \"./nodebb stop\" to stop the NodeBB server";
|
||||||
|
echo " \"./nodebb log\" to view server output";
|
||||||
|
node loader -d "$@"
|
||||||
|
;;
|
||||||
|
|
||||||
|
stop)
|
||||||
|
echo "Stopping NodeBB. Goodbye!";
|
||||||
|
kill `cat pidfile`;
|
||||||
|
;;
|
||||||
|
|
||||||
|
log)
|
||||||
|
tail -F ./logs/output.log;
|
||||||
;;
|
;;
|
||||||
|
|
||||||
upgrade)
|
upgrade)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
},
|
},
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "./nodebb start",
|
||||||
|
"stop": "./nodebb stop",
|
||||||
"test": "mocha ./tests"
|
"test": "mocha ./tests"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -43,7 +45,8 @@
|
|||||||
"nodebb-theme-vanilla": "~0.0.14",
|
"nodebb-theme-vanilla": "~0.0.14",
|
||||||
"nodebb-theme-cerulean": "~0.0.13",
|
"nodebb-theme-cerulean": "~0.0.13",
|
||||||
"nodebb-theme-lavender": "~0.0.22",
|
"nodebb-theme-lavender": "~0.0.22",
|
||||||
"less": "^1.6.3"
|
"less": "^1.6.3",
|
||||||
|
"daemon": "~1.1.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"redis": "0.8.3",
|
"redis": "0.8.3",
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ var shutdown = function(code) {
|
|||||||
db.close();
|
db.close();
|
||||||
winston.info('[app] Database connection closed.');
|
winston.info('[app] Database connection closed.');
|
||||||
|
|
||||||
winston.info('[app] Goodbye!');
|
winston.info('[app] Shutdown complete.');
|
||||||
process.exit();
|
process.exit();
|
||||||
},
|
},
|
||||||
restart = function() {
|
restart = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user