diff --git a/src/app.coffee b/src/app.coffee index f10897be..510b0404 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -52,7 +52,7 @@ knex('config').select('value').where(key: 'uuid').then ([ uuid ]) -> api = require './api' application = require './application' - supervisor = require './supervisor-update' + supervisor = require './supervisor' console.log('Starting OpenVPN..') openvpn = spawn('openvpn', [ 'client.conf' ], cwd: '/data') @@ -97,3 +97,8 @@ knex('config').select('value').where(key: 'uuid').then ([ uuid ]) -> # Tell the supervisor updater that we have successfully started, so that it can do whatever it needs to. supervisor.startupSuccessful() + + # Let API know we are running a new version + application.updateDeviceInfo( + supervisor_version: supervisor.version + ) diff --git a/src/bootstrap.coffee b/src/bootstrap.coffee index accba75f..03b68d0f 100644 --- a/src/bootstrap.coffee +++ b/src/bootstrap.coffee @@ -9,6 +9,7 @@ config = require './config' csrgen = Promise.promisify require 'csr-gen' request = Promise.promisify require 'request' PlatformAPI = require 'resin-platform-api/request' +supervisor = require './supervisor' PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/') resinAPI = new PlatformAPI(PLATFORM_ENDPOINT) @@ -44,8 +45,6 @@ module.exports = -> .tap (uuid) -> userConfig.uuid = uuid .then (uuid) -> - version = utils.getSupervisorVersion() - # Generate SSL certificate keys = csrgen(uuid, company: 'Rulemotion Ltd' @@ -60,19 +59,18 @@ module.exports = -> division: '' ) - return [keys, version, uuid] - .spread (keys, version, uuid) -> + return [keys, uuid] + .spread (keys, uuid) -> console.log('UUID:', uuid) console.log('User ID:', userConfig.userId) console.log('User:', userConfig.username) - console.log('Supervisor Version:', version) + console.log('Supervisor Version:', supervisor.version) console.log('API key:', userConfig.apiKey) console.log('Application ID:', userConfig.applicationId) console.log('CSR :', keys.csr) console.log('Posting to the API..') userConfig.csr = keys.csr userConfig.uuid = uuid - userConfig.version = version return request( method: 'POST' url: url.resolve(config.apiEndpoint, 'sign_certificate?apikey=' + userConfig.apiKey) @@ -106,7 +104,7 @@ module.exports = -> { key: 'apiKey', value: userConfig.apiKey } { key: 'username', value: userConfig.username } { key: 'userId', value: userConfig.userId } - { key: 'version', value: userConfig.version } + { key: 'version', value: supervisor.version } ]) knex('app').truncate() ]) diff --git a/src/supervisor.coffee b/src/supervisor.coffee index 5896e591..c753dfc8 100755 --- a/src/supervisor.coffee +++ b/src/supervisor.coffee @@ -1,8 +1,15 @@ process.on 'uncaughtException', (e) -> console.error('Got unhandled exception', e, e?.stack) +fs = require 'fs' supervisor = require './supervisor-update' +# Parses package.json and returns resin-supervisor's version +supervisor.version = version = do -> + packageJson = fs.readFileSync(__dirname + '/../package.json', 'utf-8') + obj = JSON.parse packageJson + return obj.version + # Make sure the supervisor-update has initialised before we continue, as it will handle restarting to add mounts if # necessary. supervisor.initialised.then -> @@ -19,3 +26,5 @@ supervisor.initialised.then -> # Wait for the DB schema to be created knex.init.then -> require('./app') + +module.exports = exports = supervisor diff --git a/src/utils.coffee b/src/utils.coffee index cc84782a..a616b504 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -5,13 +5,6 @@ config = require './config' mixpanel = require 'mixpanel' request = Promise.promisifyAll require 'request' -# Parses package.json and returns resin-supervisor's version -exports.getSupervisorVersion = -> - fs.readFileAsync(__dirname + '/../package.json', 'utf-8') - .then (data) -> - obj = JSON.parse data - return obj.version - mixpanelClient = mixpanel.init(config.mixpanelToken) exports.mixpanelProperties = mixpanelProperties =