Last active
November 9, 2015 13:31
-
-
Save ryandesign/c3be714c9590d3d1b6bc to your computer and use it in GitHub Desktop.
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>EnvironmentVariables</key> | |
<dict> | |
<key>NODE_ENV</key> | |
<string>production</string> | |
</dict> | |
<key>Label</key> | |
<string>com.example.simple</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/opt/local/bin/node</string> | |
<string>master.js</string> | |
</array> | |
<key>Sockets</key> | |
<dict> | |
<key>HTTPSocket</key> | |
<dict> | |
<key>SockFamily</key> | |
<string>IPv4v6</string> | |
<key>SockServiceName</key> | |
<integer>3000</integer> | |
</dict> | |
</dict> | |
<key>WorkingDirectory</key> | |
<string>/path/to/simple</string> | |
</dict> | |
</plist> |
This file contains 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
var cluster = require('cluster'); | |
cluster.setupMaster({ | |
exec: 'server.js' | |
}); | |
var env = {}; | |
if (!process.env.PORT) { | |
env.LAUNCHD_SOCKET = require('node-launchd').getSocketFileDescriptorForName('HTTPSocket'); | |
} | |
var numWorkers = require('os').cpus().length; | |
for (var i = 0; i < numWorkers; ++i) { | |
cluster.fork(env); | |
} | |
cluster.on('exit', exited); | |
function exited(worker, code, signal) { | |
console.log('worker ' + worker.process.pid + ' exited'); | |
} |
This file contains 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
var http = require('http'); | |
function app(req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('worker ' + process.pid + '\n'); | |
} | |
var server = http.createServer(app); | |
var portOrHandle = process.env.PORT || { | |
fd: +process.env.LAUNCHD_SOCKET || require('node-launchd').getSocketFileDescriptorForName('HTTPSocket') | |
}; | |
server.listen(portOrHandle, listening); | |
function listening() { | |
console.log('worker ' + process.pid + ' listening'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment