From 28832a2540521a542bbffa1e33b3ae8f522b0785 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 20:37:57 -0500 Subject: [PATCH] fixing bug where sometimes a pidfile was left over, and nodebb would refuse to start a daemon again. --- loader.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/loader.js b/loader.js index 2effb4ffa0..2ab9be2715 100644 --- a/loader.js +++ b/loader.js @@ -44,11 +44,18 @@ var nconf = require('nconf'), nconf.argv(); +// Start the daemon! 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(); + try { + var pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' }); + process.kill(pid, 0); + console.log('\n Error: Another NodeBB is already running!'); + process.exit(); + } catch (e) { + fs.unlinkSync(pidFilePath); + } } // Initialise logging streams