Skip to content

Instantly share code, notes, and snippets.

@germanlinux
Created February 3, 2014 20:36
agent pour forever
http = require 'http'
exec = require('child_process').exec
tab=[]
teste_ligne_utile = (result) ->
cperr = 0
cpok = 0
cp = 0
res ={}
while cp < result.length - 2
tmp = result[cp + 2]
tmatch = tmp.match(/\d+:\d+:\d+/)
tab_match = tmatch[0].split(':')
if tab_match[0] == '0' and tab_match[1] == '0' and tab_match[2] == '0'
cperr+=1
else
cpok += 1
cp += 1
res = {ok : cpok , ko : cperr}
command = (res)-> exec('forever list',
(error,stdout, stderr) ->
tab = stdout.split('data')
rep = JSON.stringify( teste_ligne_utile(tab))
res.end(rep)
)
monserveur = http.createServer (req, res) ->
if (req.url == '/check_safe' && req.method.toLowerCase() == 'get')
res.writeHead(200, {'content-type': 'application/json'})
command(res)
monserveur.listen 8888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment