Skip to content

Commit

Permalink
auto-restart mongo if it dies.
Browse files Browse the repository at this point in the history
  • Loading branch information
amark committed Nov 13, 2013
1 parent 0ee6ba7 commit f6b7aa4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mongous.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ con = function() {
return con.c.write(com.binary(MasterCmd, 2004, 0), 'binary'); // this makes us the master of Mongo

});
var start = (function(m){
function start(m){
var spawn = require('child_process').spawn,
config = [];
log("starting Mongod");
Expand All @@ -91,6 +91,7 @@ con = function() {
var mongod = spawn('mongod',config);
mongod.on('exit',function(c,s){
log("Mongod exited");
start(m); // comment this out if you don't want auto-restart on exit. I'll add an option for it later.
});
mongod.stderr.on('data',function(d){
log(d.toString());
Expand All @@ -101,7 +102,7 @@ con = function() {
m.open(con.host,con.port);
}
}, m));
});
};
con.c.addListener('error', __bind(function(e) {
if(e && e.code == 'ECONNREFUSED'){
if((require('fs').existsSync||require('path').existsSync)('/usr/local/bin/mongod')) start(this);
Expand Down

0 comments on commit f6b7aa4

Please sign in to comment.