From ab26c6a401ee2c9b10529234ef65fb63f337a6ba Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Mon, 4 May 2015 12:45:50 +0100 Subject: [PATCH] Don't cache config.json --- CHANGELOG.md | 2 ++ src/bootstrap.coffee | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8157360..cb676fb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Stop caching config.json, avoids a race that could cause getting stuck repeatedly trying to register [Page] + # v0.0.13 * Bind mount /etc/resolv.conf as ro for application containers and supervisor [Praneeth] diff --git a/src/bootstrap.coffee b/src/bootstrap.coffee index c91c97f7..8bda8706 100644 --- a/src/bootstrap.coffee +++ b/src/bootstrap.coffee @@ -28,10 +28,10 @@ registerDevice = (apiKey, userId, applicationId, deviceType, uuid) -> module.exports = -> # Load config file - userConfig = require('/boot/config.json') - userConfig.deviceType ?= 'raspberry-pi' - - Promise.try -> + fs.readFileAsync('/boot/config.json', 'utf8') + .then(JSON.parse) + .then (userConfig) -> + userConfig.deviceType ?= 'raspberry-pi' if userConfig.uuid? and userConfig.registered_at? return userConfig registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType, userConfig.uuid) @@ -40,7 +40,7 @@ module.exports = -> userConfig.deviceId = device.id fs.writeFileAsync('/boot/config.json', JSON.stringify(userConfig)) .return(userConfig) - .then -> + .then (userConfig) -> console.log('Finishing bootstrapping') Promise.all([ knex('config').truncate()