Supervisor

This commit is contained in:
Petros Aggelatos 2013-07-18 13:20:27 +03:00
parent 5f2e80ea76
commit 422f5f5c0b
4 changed files with 45 additions and 12 deletions

View File

@ -1,8 +0,0 @@
`
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '0.0.0.0');
console.log('Server running at http://0.0.0.0:1337/');
`

4
state.json Normal file
View File

@ -0,0 +1,4 @@
{
"virgin": true,
"uuid": null
}

41
supervisor.coffee Executable file
View File

@ -0,0 +1,41 @@
fs = require('fs')
async = require('async')
request = require('request')
API_ENDPOINT = 'http://paras.rulemotion.com:1337'
try
state = require('state.json')
catch e
console.error(e)
process.exit()
bootstrapTasks = [
(callback) ->
try
callback(null, require('/mnt/config.json'))
catch error
callback(error)
(config, callback) ->
request.post("#{API_ENDPOINT}/associate", {
user: config.id
}, (error, response, body) ->
if error
return callback(error)
try
body = JSON.parse(body)
catch error
callback(error)
state.virgin = false
state.uuid = body.uuid
fs.writeFileSync('state.json', JSON.strigify(state))
callback(null)
)
]

View File

@ -1,4 +0,0 @@
#!/usr/bin/env node
var coffee = require("coffee-script");
var app = require("./app");