Skip to content

Instantly share code, notes, and snippets.

@gsf
Created February 13, 2013 18:17
Show Gist options
  • Select an option

  • Save gsf/4946810 to your computer and use it in GitHub Desktop.

Select an option

Save gsf/4946810 to your computer and use it in GitHub Desktop.
Zoia infrastructure
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);
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
@gsf
Copy link
Author

gsf commented Feb 13, 2013

First file is the Node.js server to handle the GitHub hook. The second is the monit conf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment