Merge pull request #120 from resin-io/restart-policy

Container restart policy specification.
This commit is contained in:
Pablo Carranza Vélez 2016-06-07 13:00:11 -03:00
commit 9c0042c2d5
2 changed files with 20 additions and 0 deletions

View File

@ -1,3 +1,5 @@
* Add restart policies and change default to auto-restart [Aleksis]
# v1.10.1
* Switch to docker-delta library to use deltas v2 [petrosagg]

View File

@ -228,11 +228,13 @@ application.start = start = (app) ->
if portList?
portList.forEach (port) ->
ports[port + '/tcp'] = [ HostPort: port ]
restartPolicy = createRestartPolicy({ name: env['RESIN_APP_RESTART_POLICY'], maximumRetryCount: env['RESIN_APP_RESTART_RETRIES'] })
container.startAsync(
Privileged: true
NetworkMode: 'host'
PortBindings: ports
Binds: binds
RestartPolicy: restartPolicy
)
.catch (err) ->
statusCode = '' + err.statusCode
@ -261,6 +263,22 @@ application.start = start = (app) ->
.finally ->
device.updateState(status: 'Idle')
validRestartPolicies = [ 'no', 'always', 'on-failure', 'unless-stopped' ]
# Construct a restart policy based on its name and maximumRetryCount.
# Both arguments are optional, and the default policy is "always".
#
# Throws exception if an invalid policy name is given.
# Returns a RestartPolicy { Name, MaximumRetryCount } object
createRestartPolicy = ({ name, maximumRetryCount }) ->
if not name?
name = 'always'
if not (name in validRestartPolicies)
throw new Error("Invalid restart policy: #{name}")
policy = { Name: name }
if name is 'on-failure' and maximumRetryCount?
policy.MaximumRetryCount = maximumRetryCount
return policy
getEnvironment = do ->
envApiEndpoint = url.resolve(config.apiEndpoint, '/environment')