fix: "start" should wait for "stop" to remove the pid file(using Promise) (#1220)
This commit is contained in:
14
bin/cli.js
14
bin/cli.js
@@ -48,7 +48,9 @@ program.parse(process.argv);
|
||||
|
||||
|
||||
function start(options) {
|
||||
stop(options);
|
||||
stop(options)
|
||||
// wait for "stop" method to remove the pid file
|
||||
.then(function () {
|
||||
var dataDir = options.dataDir || path.join(process.env.HOME, '.cnpmjs.org');
|
||||
mkdirp.sync(dataDir);
|
||||
|
||||
@@ -88,12 +90,17 @@ function start(options) {
|
||||
});
|
||||
|
||||
fs.writeFileSync(path.join(dataDir, 'pid'), process.pid + '');
|
||||
});
|
||||
}
|
||||
|
||||
function stop(options) {
|
||||
var dataDir = options.dataDir || path.join(process.env.HOME, '.cnpmjs.org');
|
||||
var pidfile = path.join(dataDir, 'pid');
|
||||
if (fs.existsSync(pidfile)) {
|
||||
return new Promise(function (resolve) {
|
||||
if (!fs.existsSync(pidfile)) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
var pid = Number(fs.readFileSync(pidfile, 'utf8'));
|
||||
treekill(pid, function (err) {
|
||||
if (err) {
|
||||
@@ -102,8 +109,9 @@ function stop(options) {
|
||||
}
|
||||
console.log('cnpmjs.org server:%d stop', pid);
|
||||
fs.unlinkSync(pidfile);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function initDatabase(callback) {
|
||||
|
||||
Reference in New Issue
Block a user