mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-26 08:31:22 +01:00
fix: #10086, if pidfile is empty delete
This commit is contained in:
24
loader.js
24
loader.js
@@ -187,6 +187,7 @@ Loader.stop = function () {
|
|||||||
killWorkers();
|
killWorkers();
|
||||||
|
|
||||||
// Clean up the pidfile
|
// Clean up the pidfile
|
||||||
|
console.log('stop called');
|
||||||
if (nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
|
if (nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
|
||||||
fs.unlinkSync(pidFilePath);
|
fs.unlinkSync(pidFilePath);
|
||||||
}
|
}
|
||||||
@@ -208,12 +209,25 @@ fs.open(pathToConfig, 'r', (err) => {
|
|||||||
|
|
||||||
if (nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
|
if (nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
|
||||||
if (file.existsSync(pidFilePath)) {
|
if (file.existsSync(pidFilePath)) {
|
||||||
|
let pid = 0;
|
||||||
try {
|
try {
|
||||||
const pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
|
pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
|
||||||
process.kill(pid, 0);
|
if (pid) {
|
||||||
process.exit();
|
process.kill(pid, 0);
|
||||||
} catch (e) {
|
console.info(`Process "${pid}" from pidfile already running, exiting`);
|
||||||
fs.unlinkSync(pidFilePath);
|
process.exit();
|
||||||
|
} else {
|
||||||
|
console.info(`Invalid pid "${pid}" from pidfile, deleting pidfile`);
|
||||||
|
fs.unlinkSync(pidFilePath);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === 'ESRCH') {
|
||||||
|
console.info(`Process "${pid}" from pidfile not found, deleting pidfile`);
|
||||||
|
fs.unlinkSync(pidFilePath);
|
||||||
|
} else {
|
||||||
|
console.error(err.stack);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user