From f385fe6bcc19ebc0c2fba5d1123b34e7c6c8b91e Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Wed, 28 Sep 2016 03:32:38 +0000 Subject: [PATCH] Add system logs for Shutdown, Reboot and Purge --- CHANGELOG.md | 2 ++ src/api.coffee | 11 ++++++++--- src/application.coffee | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0251b1f..1b012b4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Add system logs for Shutdown, Reboot and Purge [Pablo] + # v2.3.0 * Implement delete-then-download update strategy [Pablo] diff --git a/src/api.coffee b/src/api.coffee index 4f8d649e..6a9c7490 100644 --- a/src/api.coffee +++ b/src/api.coffee @@ -49,7 +49,7 @@ module.exports = (application) -> unparsedRouter.post '/v1/reboot', (req, res) -> new Promise (resolve, reject) -> - utils.mixpanelTrack('Reboot') + application.logSystemMessage('Rebooting', {}, 'Reboot') utils.gosuper.post('/v1/reboot') .on('error', reject) .on('response', -> resolve()) @@ -59,7 +59,7 @@ module.exports = (application) -> unparsedRouter.post '/v1/shutdown', (req, res) -> new Promise (resolve, reject) -> - utils.mixpanelTrack('Shutdown') + application.logSystemMessage('Shutting down', {}, 'Shutdown') utils.gosuper.post('/v1/shutdown') .on('error', reject) .on('response', -> resolve()) @@ -69,7 +69,7 @@ module.exports = (application) -> parsedRouter.post '/v1/purge', (req, res) -> appId = req.body.appId - utils.mixpanelTrack('Purge /data', appId) + application.logSystemMessage('Purging /data', { appId }, 'Purge /data') if !appId? return res.status(400).send('Missing app id') Promise.using application.lockUpdates(appId, true), -> @@ -82,8 +82,13 @@ module.exports = (application) -> .on('error', reject) .on('response', -> resolve()) .pipe(res) + .then -> + application.logSystemMessage('Purged /data', { appId }, 'Purge /data success') .finally -> application.start(app) + .catch (err) -> + application.logSystemMessage("Error purging /data: #{err}", { appId, error: err }, 'Purge /data error') + throw err .catch utils.AppNotFoundError, (e) -> return res.status(400).send(e.message) .catch (err) -> diff --git a/src/application.coffee b/src/application.coffee index f5299cc8..d0ad19e9 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -91,7 +91,9 @@ logTypes = eventName: 'Application restart' humanName: 'Restarting application' -logSystemMessage = (message, obj, eventName) -> +application = {} + +application.logSystemMessage = logSystemMessage = (message, obj, eventName) -> logger.log({ m: message, s: 1 }) utils.mixpanelTrack(eventName ? message, obj) @@ -117,8 +119,6 @@ logSpecialAction = (action, value, success) -> msg = "Applying config variable #{action} = #{value}" logSystemMessage(msg, {}, "Apply special action #{if success then "success" else "in progress"}") -application = {} - application.kill = kill = (app, updateDB = true, removeContainer = true) -> logSystemEvent(logTypes.stopApp, app) device.updateState(status: 'Stopping')