added getSupevisorVersion

This commit is contained in:
Vasilis Souleles 2014-04-28 13:56:17 +03:00 committed by Pablo Carranza Vélez
parent b435116207
commit 10451fd27d
4 changed files with 19 additions and 6 deletions

View File

@ -13,15 +13,16 @@ console.log('Supervisor started..')
newUuid = utils.getDeviceUuid() newUuid = utils.getDeviceUuid()
oldUuid = knex('config').select('value').where(key: 'uuid') oldUuid = knex('config').select('value').where(key: 'uuid')
version = utils.getSupevisorVersion()
Promise.all([newUuid, oldUuid]) Promise.all([newUuid, oldUuid, version])
.then ([newUuid, [oldUuid]]) -> .then ([newUuid, [oldUuid], version]) ->
oldUuid = oldUuid?.value oldUuid = oldUuid?.value
if newUuid is oldUuid if newUuid is oldUuid
return true return true
console.log('New device detected. Bootstrapping..') console.log('New device detected. Bootstrapping..')
return bootstrap(newUuid) return bootstrap(newUuid, version)
.then -> .then ->
console.log('Starting OpenVPN..') console.log('Starting OpenVPN..')
openvpn = spawn('openvpn', ['client.conf'], cwd: '/data') openvpn = spawn('openvpn', ['client.conf'], cwd: '/data')

View File

@ -147,13 +147,13 @@ exports.update = ->
promises = toBeInstalled.map (imageId) -> promises = toBeInstalled.map (imageId) ->
app = remoteApps[imageId] app = remoteApps[imageId]
start(app) start(app)
.then -> .then ->
knex('app').insert(app) knex('app').insert(app)
# And restart updated apps and update db as they succeed # And restart updated apps and update db as they succeed
promises = promises.concat toBeUpdated.map (imageId) -> promises = promises.concat toBeUpdated.map (imageId) ->
app = remoteApps[imageId] app = remoteApps[imageId]
restart(app) restart(app)
.then -> .then ->
knex('app').update(app).where(imageId: app.imageId) knex('app').update(app).where(imageId: app.imageId)
# And delete all the ones to remove in one go # And delete all the ones to remove in one go
promises.push( promises.push(

View File

@ -7,7 +7,7 @@ crypto = require 'crypto'
csrgen = Promise.promisify require 'csr-gen' csrgen = Promise.promisify require 'csr-gen'
request = Promise.promisify require 'request' request = Promise.promisify require 'request'
module.exports = (uuid) -> module.exports = (uuid, version) ->
# Load config file # Load config file
config = fs.readFileAsync('/boot/config.json', 'utf8').then(JSON.parse) config = fs.readFileAsync('/boot/config.json', 'utf8').then(JSON.parse)
@ -30,6 +30,7 @@ module.exports = (uuid) ->
console.log('UUID:', uuid) console.log('UUID:', uuid)
console.log('User ID:', config.userId) console.log('User ID:', config.userId)
console.log('User:', config.username) console.log('User:', config.username)
console.log('Supervisor Version:', version)
console.log('API key:', config.apiKey) console.log('API key:', config.apiKey)
console.log('Application ID:', config.applicationId) console.log('Application ID:', config.applicationId)
console.log('CSR :', keys.csr) console.log('CSR :', keys.csr)
@ -67,6 +68,7 @@ module.exports = (uuid) ->
{key: 'apiKey', value: config.apiKey} {key: 'apiKey', value: config.apiKey}
{key: 'username', value: config.username} {key: 'username', value: config.username}
{key: 'userId', value: config.userId} {key: 'userId', value: config.userId}
{key: 'version', value: version}
]) ])
knex('app').truncate() knex('app').truncate()
]) ])

View File

@ -16,3 +16,13 @@ exports.getDeviceUuid = ->
.trim() or os.hostname() .trim() or os.hostname()
return crypto.createHash('sha1').update(serial, 'utf8').digest('hex') return crypto.createHash('sha1').update(serial, 'utf8').digest('hex')
# Parses package.json and returns resin-supervisor's version
exports.getSupervisorVersion = ->
fs.readFileAsync '../package.json'
.then (data) ->
obj = JSON.parse data
Promise.resolve obj
.then (obj) ->
return obj.version