var bunyan = require('bunyan');
var fs = require('fs');
var optimist = require('optimist');
var Shard = require('./lib/shard');

///--- Mainline

var ARGV = optimist.options({
        'd': {
                alias: 'debug',
                describe: 'debug level'
        },
        'f': {
                alias: 'file',
                demand: true,
                describe: 'configuration file'
        }
}).argv;

var CFG;

var LOG = bunyan.createLogger({
        level: ARGV.d ? (ARGV.d > 1 ? 'trace' : 'debug') : 'info',
        name: 'pg-sitter',
        serializers: {
                err: bunyan.stdSerializers.err
        },
        src: ARGV.d ? true : false
});

function readConfig() {
        if (!CFG) {
                CFG = JSON.parse(fs.readFileSync(ARGV.f, 'utf8'));
                LOG.info({config: CFG, file: ARGV.f}, 'Configuration loaded');
        }

        return (CFG);
}

var cfg = readConfig();
cfg.log = LOG;
cfg.zkCfg.log = LOG;
cfg.postgresManCfg.log = LOG;
cfg.postgresManCfg.backupClientCfg.log = LOG;
cfg.postgresManCfg.snapShotterCfg.log = LOG;
cfg.heartbeaterCfg.log = LOG;

// wait 10 seconds before starting manatee - this ensures that previous
// ephemeral znodes are purged.
setTimeout(10000, start());

function start() {
        var shard = new Shard(cfg);

        shard.on('connect', function() {
                shard.init();
        });
}

process.on('uncaughtException', function (err) {
        LOG.fatal({err: err}, 'uncaughtException (exiting error code 1)');
        process.exit(1);
});

@@ -1109,168 +1109,8 @@
 G;%0A%0A
-// wait 10 seconds before starting manatee - this ensures that previous%0A// ephemeral znodes are purged.%0AsetTimeout(10000, start());%0A%0Afunction start() %7B%0A        
 var 
@@ -1134,24 +1134,16 @@
 (cfg);%0A%0A
-        
 shard.on
@@ -1163,32 +1163,24 @@
 unction() %7B%0A
-        
         shar
@@ -1193,21 +1193,11 @@
 ();%0A
-        
 %7D);
-%0A%7D
 %0A%0Apr

Revert "MANTA-152 set timeout on manatee starts"