Added logs and changed exec to spawn

This commit is contained in:
Petros Angelatos 2013-07-19 17:40:18 +01:00
parent 4587b232fc
commit 7bb3d4b9eb

View File

@ -2,7 +2,7 @@ fs = require('fs')
async = require('async') async = require('async')
request = require('request') request = require('request')
posix = require('posix') posix = require('posix')
{exec} = require('child_process') {exec,spawn} = require('child_process')
API_ENDPOINT = 'http://paras.rulemotion.com:1337' API_ENDPOINT = 'http://paras.rulemotion.com:1337'
HAKI_PATH = '/home/haki' HAKI_PATH = '/home/haki'
@ -75,23 +75,43 @@ updateRepo = (callback) ->
tasks2 = [ tasks2 = [
(callback) -> (callback) ->
if fs.existsSync('package.json') console.log("Checking for package.json")
exec('npm install', cwd: 'hakiapp', callback) if fs.existsSync('hakiapp/package.json')
console.log("Found, npm installing")
ps = spawn('sudo', ['-u', 'haki', 'npm', 'install'],
cwd: 'hakiapp'
stdio: [0, 1, 2]
)
ps.on('exit', callback)
ps.on('error', callback)
else else
console.log("No package.json")
callback() callback()
(callback) -> (callback) ->
if fs.existsSync('Procfile') console.log("Checking for Procfile")
exec('foreman start', cwd: 'hakiapp', callback) if fs.existsSync('hakiapp/Procfile')
console.log("Found Procfile, starting app..")
ps = spawn('foreman', ['start'],
cwd: 'hakiapp'
stdio: [0, 1, 2]
uid: posix.getpwnam('haki').uid
)
ps.on('exit', callback)
ps.on('error', callback)
else else
console.log("No Procfile found")
callback() callback()
] ]
async.waterfall(tasks1, (error, hash) -> async.waterfall(tasks1, (error, hash) ->
console.log("Checking for new version..")
if hash isnt state.gitHead if hash isnt state.gitHead
console.log("New version found #{state.gitHead}->#{hash}")
state.gitHead = hash state.gitHead = hash
fs.writeFileSync('state.json', JSON.stringify(state)) fs.writeFileSync('state.json', JSON.stringify(state))
async.series(tasks2, (callback) -> setTimeout(callback, POLLING_INTERVAL)) async.series(tasks2, (callback) -> setTimeout(callback, POLLING_INTERVAL))
else else
console.log("No new version found")
setTimeout(callback, POLLING_INTERVAL) setTimeout(callback, POLLING_INTERVAL)
) )