From 504e05326fc3c70dc097608279bec3db9c7c27c5 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Mon, 9 Feb 2015 21:32:29 -0800 Subject: [PATCH] Delete mongod.lock file when starting Meteor When we try to kill old running versions of mongod, then we may have to resort to killing the process without it having an opportunity to close gracefully, so we need to also delete the lock file if we want to be able to start mongod again. This is made especially worse on Windows, where `process.kill` always kills a process non-gracefully. Should fix https://github.com/meteor/windows-preview/issues/34, and some self-test failures. --- tools/run-mongo.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/run-mongo.js b/tools/run-mongo.js index 386c52b2e5..b8e76853b9 100644 --- a/tools/run-mongo.js +++ b/tools/run-mongo.js @@ -187,14 +187,11 @@ var findMongoPort = function (appDir) { // // This is a big hammer for dealing with still running mongos, but // smaller hammers have failed before and it is getting tiresome. -var findMongoAndKillItDead = function (port) { +var findMongoAndKillItDead = function (port, dbPath) { var pids = findMongoPids(null, port); - if (! pids.length) - return; // nothing to kill - // Go through the list serially. There really should only ever be - // one but we're not taking any chances. + // at most one but we're not taking any chances. _.each(pids, function (processInfo) { var pid = processInfo.pid; @@ -224,6 +221,14 @@ var findMongoAndKillItDead = function (port) { // for the user. throw new Error("Can't kill running mongo (pid " + pid + ")."); }); + + // If we had to kill mongod with SIGKILL, or on Windows where all calls to + // `process.kill` work like SIGKILL, mongod will not have the opportunity to + // close gracefully. Delete a lock file that may have been left over. + var mongodLockFile = files.pathJoin(dbPath, "mongod.lock"); + if (files.exists(mongodLockFile)) { + files.unlink(mongodLockFile) + } }; var StoppedDuringLaunch = function () {}; @@ -307,7 +312,7 @@ var launchMongo = function (options) { var procExitHandler; if (options.allowKilling) { - findMongoAndKillItDead(port); + findMongoAndKillItDead(port, dbPath); } if (options.multiple) {