Cluster exit worker after code execution

Hi I have a cluster app.

On master I'm having this piece of code:

var applicationServer = require( "./app.js" );
var spawnWorker = function(){
    var worker = cluster.fork();
    log.info("Spawning worker", worker.id+"...");
    // handle worker log messages
    worker.on("message", function(msg) {
        log.handleWorkerMessage(msg);
    });
    return worker;
}

if (cluster.isMaster) {

    log.info("Initializing mcm server...");

    // Restart worker on exit
    cluster.on("exit", function(worker, code, signal) {
        log.warn("Worker", worker.id, "died!"); 
        spawnWorker();
    }); 

    for (var i = 0; i < numCPUs; i++) {
        spawnWorker();
    }

} else {

    applicationServer.init(function( app, routes, sessionStore, socketStore, redis, io ) {

        //other code not relevant       

        log.info("Worker ready!");

    }); 

}

and inside "app.js" (applicationServer) I have this code:

    process.stdin.resume();
    process.on("exit", function(){
        log.info("Process about to exit. Closing db connections...");
        db.close();
    });

This closes the connections with mongo if I remember correctly however I can't log anything to the console. Does this means that at this state I have limited functionality ? how can I be sure that the code inside "process.exit" will always run ? I tried to create a file inside the exit callback but with no luck.

The reason I need this is because I would like each process any socket connections that handles before quiting or restarting.