diff --git a/CHANGELOG.md b/CHANGELOG.md index 157d60ea..8668abcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v7.1.17 - 2018-03-19 + +* Document that the update lock can be forced on reboots and shutdowns #591 [Pablo Carranza Velez] +* Force reboots and shutdowns if lock override is enabled #591 [Pablo Carranza Velez] + ## v7.1.16 - 2018-03-16 * In /v1/apps/:appId/stop, wait for the service to exit before responding #593 [Pablo Carranza Velez] diff --git a/docs/API.md b/docs/API.md index 82c54de2..09cfb3df 100644 --- a/docs/API.md +++ b/docs/API.md @@ -108,7 +108,9 @@ $ curl -X POST --header "Content-Type:application/json" \ ### POST /v1/reboot -Reboots the device +Reboots the device. This will first try to stop applications, and fail if there is an update lock. +An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from +the dashboard). When successful, responds with 202 accepted and a JSON object: ```json @@ -119,6 +121,9 @@ When successful, responds with 202 accepted and a JSON object: ``` (This is implemented in Go) +#### Request body +Can contain a `force` property, which if set to `true` will cause the update lock to be overridden. + #### Examples: From the app on the device: ```bash @@ -142,7 +147,9 @@ $ curl -X POST --header "Content-Type:application/json" \ ### POST /v1/shutdown -**Dangerous**. Shuts down the device. +**Dangerous**. Shuts down the device. This will first try to stop applications, and fail if there is an update lock. +An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from +the dashboard). When successful, responds with 202 accepted and a JSON object: ```json @@ -153,6 +160,9 @@ When successful, responds with 202 accepted and a JSON object: ``` (This is implemented in Go) +#### Request body +Can contain a `force` property, which if set to `true` will cause the update lock to be overridden. + #### Examples: From the app on the device: ```bash diff --git a/package.json b/package.json index 09c76493..5b97f03a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "resin-supervisor", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", - "version": "7.1.16", + "version": "7.1.17", "license": "Apache-2.0", "repository": { "type": "git", diff --git a/src/device-state.coffee b/src/device-state.coffee index dfca9cee..b3ec2800 100644 --- a/src/device-state.coffee +++ b/src/device-state.coffee @@ -45,9 +45,11 @@ createDeviceStateRouter = (deviceState) -> router.use(bodyParser.urlencoded(extended: true)) router.use(bodyParser.json()) - router.post '/v1/reboot', (req, res) -> - force = validation.checkTruthy(req.body.force) - deviceState.executeStepAction({ action: 'reboot' }, { force }) + rebootOrShutdown = (req, res, action) -> + deviceState.config.get('lockOverride') + .then (lockOverride) -> + force = validation.checkTruthy(req.body.force) or validation.checkTruthy(lockOverride) + deviceState.executeStepAction({ action }, { force }) .then (response) -> res.status(202).json(response) .catch (err) -> @@ -57,17 +59,11 @@ createDeviceStateRouter = (deviceState) -> status = 500 res.status(status).json({ Data: '', Error: err?.message or err or 'Unknown error' }) + router.post '/v1/reboot', (req, res) -> + rebootOrShutdown(req, res, 'reboot') + router.post '/v1/shutdown', (req, res) -> - force = validation.checkTruthy(req.body.force) - deviceState.executeStepAction({ action: 'shutdown' }, { force }) - .then (response) -> - res.status(202).json(response) - .catch (err) -> - if err instanceof updateLock.UpdatesLockedError - status = 423 - else - status = 500 - res.status(status).json({ Data: '', Error: err?.message or err or 'Unknown error' }) + rebootOrShutdown(req, res, 'shutdown') router.get '/v1/device/host-config', (req, res) -> hostConfig.get()