forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodebb
executable file
·167 lines (150 loc) · 5.02 KB
/
nodebb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env node
var colors = require('colors'),
cproc = require('child_process'),
argv = require('minimist')(process.argv.slice(2)),
fs = require('fs'),
async = require('async'),
touch = require('touch'),
npm = require('npm');
var getRunningPid = function(callback) {
fs.readFile(__dirname + '/pidfile', {
encoding: 'utf-8'
}, function(err, pid) {
if (err) {
return callback(err);
}
try {
process.kill(parseInt(pid, 10), 0);
callback(null, parseInt(pid, 10));
} catch(e) {
callback(e);
}
});
};
switch(process.argv[2]) {
case 'status':
getRunningPid(function(err, pid) {
if (!err) {
process.stdout.write('\nNodeBB Running '.bold + '(pid '.cyan + pid.toString().cyan + ')\n'.cyan);
process.stdout.write('\t"' + './nodebb stop'.yellow + '" to stop the NodeBB server\n');
process.stdout.write('\t"' + './nodebb log'.yellow + '" to view server output\n');
process.stdout.write('\t"' + './nodebb restart'.yellow + '" to restart NodeBB\n\n');
} else {
process.stdout.write('\nNodeBB is not running\n'.bold);
process.stdout.write('\t"' + './nodebb start'.yellow + '" to launch the NodeBB server\n\n');
}
})
break;
case 'start':
process.stdout.write('\nStarting NodeBB\n'.bold);
process.stdout.write(' "' + './nodebb stop'.yellow + '" to stop the NodeBB server\n');
process.stdout.write(' "' + './nodebb log'.yellow + '" to view server output\n');
process.stdout.write(' "' + './nodebb restart'.yellow + '" to restart NodeBB\n\n');
// Spawn a new NodeBB process
cproc.fork(__dirname + '/loader.js', {
env: process.env
});
break;
case 'stop':
getRunningPid(function(err, pid) {
if (!err) {
process.kill(pid, 'SIGTERM');
process.stdout.write('Stopping NodeBB. Goodbye!\n')
} else {
process.stdout.write('NodeBB is already stopped.\n');
}
});
break;
case 'restart':
getRunningPid(function(err, pid) {
if (!err) {
process.kill(pid, 'SIGHUP');
} else {
process.stdout.write('NodeBB could not be restarted, as a running instance could not be found.');
}
});
break;
case 'reload':
getRunningPid(function(err, pid) {
if (!err) {
process.kill(pid, 'SIGUSR2');
} else {
process.stdout.write('NodeBB could not be reloaded, as a running instance could not be found.');
}
});
break;
case 'dev':
process.env.NODE_ENV = 'development';
cproc.fork(__dirname + '/loader.js', ['--no-daemon', '--no-silent'], {
env: process.env
});
break;
case 'log':
process.stdout.write('\nType '.red + 'Ctrl-C '.bold + 'to exit\n\n'.red);
cproc.spawn('tail', ['-F', './logs/output.log'], {
cwd: __dirname,
stdio: 'inherit'
});
break;
case 'setup':
cproc.fork('app.js', ['--setup'], {
cwd: __dirname,
silent: false
});
break;
case 'reset':
var args = process.argv.slice(0);
args.unshift('--reset');
cproc.fork('app.js', args, {
cwd: __dirname,
silent: false
});
break;
case 'upgrade':
async.series([
function(next) {
process.stdout.write('1. '.bold + 'Bringing base dependencies up to date\n'.yellow);
npm.load({
loglevel: 'silent'
}, function() {
npm.commands.install(next);
});
},
function(next) {
process.stdout.write('2. '.bold + 'Updating NodeBB data store schema\n'.yellow);
var upgradeProc = cproc.fork('app.js', ['--upgrade'], {
cwd: __dirname,
silent: false
});
upgradeProc.on('close', next)
},
function(next) {
process.stdout.write('3. '.bold + 'Storing upgrade date in "package.json"\n'.yellow);
touch(__dirname + '/package.json', {}, next);
}
], function(err) {
if (err) {
process.stdout.write('\nError'.red + ': ' + err.message + '\n');
} else {
var message = 'NodeBB Upgrade Complete!',
spaces = new Array(Math.floor(process.stdout.columns / 2) - (message.length / 2) + 1).join(' ');
process.stdout.write('\n' + spaces + message.green.bold + '\n\n');
}
});
break;
default:
process.stdout.write('\nWelcome to NodeBB\n\n'.bold);
process.stdout.write('Usage: ./nodebb {start|stop|reload|restart|log|setup|reset|upgrade|dev}\n\n');
process.stdout.write('\t' + 'start'.yellow + '\tStart the NodeBB server\n');
process.stdout.write('\t' + 'stop'.yellow + '\tStops the NodeBB server\n');
process.stdout.write('\t' + 'reload'.yellow + '\tRestarts NodeBB\n');
process.stdout.write('\t' + 'restart'.yellow + '\tRestarts NodeBB\n');
process.stdout.write('\t' + 'log'.yellow + '\tOpens the logging interface (useful for debugging)\n');
process.stdout.write('\t' + 'setup'.yellow + '\tRuns the NodeBB setup script\n');
process.stdout.write('\t' + 'reset'.yellow + '\tDisables all plugins, restores the default theme.\n');
process.stdout.write('\t' + 'upgrade'.yellow + '\tRun NodeBB upgrade scripts, ensure packages are up-to-date\n');
process.stdout.write('\t' + 'dev'.yellow + '\tStart NodeBB in interactive development mode\n');
process.stdout.write('\t' + 'watch'.yellow + '\tStart NodeBB in development mode and watch for changes\n');
process.stdout.write('\n');
break;
}