Created
February 13, 2013 18:17
-
-
Save gsf/4946810 to your computer and use it in GitHub Desktop.
Zoia infrastructure
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
| var exec = require('child_process').exec; | |
| var http = require('http'); | |
| var querystring = require('querystring'); | |
| var url = require('url'); | |
| var port = process.argv[2] || 8751; | |
| http.createServer(function(request, response) { | |
| var url_parts = url.parse(request.url); | |
| if (url_parts.pathname == '/') { | |
| response.writeHead(200, {'Content-Type': 'text/plain'}); | |
| response.end('rc98'); | |
| } else if (url_parts.pathname == '/zoiaup') { | |
| if (request.method === 'POST') { | |
| var body = ''; | |
| request.on('data', function (chunk) { | |
| body = body + chunk; | |
| }); | |
| request.on('end', function () { | |
| var payload = JSON.parse(querystring.parse(body).payload); | |
| if (payload.commits.length > 0) { | |
| for (var i=0; i<payload.commits.length; i++) { | |
| var commit = payload.commits[i]; | |
| console.log('Saw supybot commit ' + commit.id); | |
| } | |
| exec("cd /home/zoia/supybot/supybot-plugins; sudo -u zoia git pull", | |
| function (error, stdout, stderr) { | |
| if (error) throw error; | |
| console.log('Pulled supybot-plugins: ' + stdout); | |
| } | |
| ); | |
| } | |
| }); | |
| response.writeHead(200, {'Content-Type': 'text/plain'}); | |
| response.end('rc98: posted\n'); | |
| } else { | |
| response.writeHead(200, {'Content-Type': 'text/plain'}); | |
| response.end('rc98\n'); | |
| } | |
| } else { | |
| response.writeHead(404, {'Content-Type': 'text/plain'}); | |
| response.end('404'); | |
| } | |
| }).listen(port); | |
| console.log('Running on port '+port); |
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
| check process zoia with pidfile /var/run/zoia.pid | |
| start program = "/usr/bin/daemon -n zoia -D /home/zoia/supybot -- su zoia -c '/usr/bin/supybot zoia.conf'" | |
| stop program = "/usr/bin/pkill -u zoia" | |
| if 3 restarts within 5 cycles then timeout |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First file is the Node.js server to handle the GitHub hook. The second is the monit conf.