mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-01 00:45:23 +00:00
Merge pull request #120 from resin-io/restart-policy
Container restart policy specification.
This commit is contained in:
commit
9c0042c2d5
@ -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]
|
||||
|
@ -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')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user