Created
April 22, 2016 21:50
-
-
Save evantahler/1d8e212f6b6247b0c32499e3df8ec430 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// load in the actionHero class | |
var actionHero = require(__dirname + "/../api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero; | |
var cluster = require('cluster'); | |
// if there is no config.js file in the application's root, then actionHero will load in a collection of default params. You can overwrite them with params.configChanges | |
var params = {}; | |
params.configChanges = {}; | |
// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe. | |
params.initFunction = function(api, next){ | |
next(); | |
} | |
// start the server! | |
var startServer = function(next){ | |
if(cluster.isWorker){ process.send("starting"); } | |
actionHero.start(params, function(api_from_callback){ | |
api = api_from_callback; | |
api.log("Boot Sucessful @ worker #" + process.pid, "green"); | |
if(typeof next == "function"){ | |
if(cluster.isWorker){ process.send("started"); } | |
next(api); | |
} | |
}); | |
} | |
// handle signals from master if running in cluster | |
if(cluster.isWorker){ | |
process.on('message', function(msg) { | |
if(msg == "start"){ | |
process.send("starting"); | |
startServer(function(){ | |
process.send("started"); | |
}); | |
} | |
if(msg == "stop"){ | |
process.send("stopping"); | |
actionHero.stop(function(){ | |
api = null; | |
process.send("stopped"); | |
process.exit(); | |
}); | |
} | |
if(msg == "restart"){ | |
process.send("restarting"); | |
actionHero.restart(function(success, api_from_callback){ | |
api = api_from_callback; | |
process.send("restarted"); | |
}); | |
} | |
}); | |
} | |
// start the server! | |
startServer(function(api){ | |
api.log("Successfully Booted!", ["green", "bold"]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment