mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-31 16:35:23 +00:00
get full container id from /proc/1/cgroup
This commit is contained in:
parent
69e2af5aa1
commit
839b6ec7ca
@ -3,6 +3,7 @@ Docker = require 'dockerode'
|
|||||||
Promise = require 'bluebird'
|
Promise = require 'bluebird'
|
||||||
_ = require 'lodash'
|
_ = require 'lodash'
|
||||||
es = require 'event-stream'
|
es = require 'event-stream'
|
||||||
|
fs = Promise.promisifyAll(require('fs'))
|
||||||
|
|
||||||
docker = Promise.promisifyAll(new Docker(socketPath: config.dockerSocket))
|
docker = Promise.promisifyAll(new Docker(socketPath: config.dockerSocket))
|
||||||
# Hack dockerode to promisify internal classes' prototypes
|
# Hack dockerode to promisify internal classes' prototypes
|
||||||
@ -12,6 +13,17 @@ Promise.promisifyAll(docker.getContainer().__proto__)
|
|||||||
localImage = config.localImage
|
localImage = config.localImage
|
||||||
remoteImage = config.remoteImage
|
remoteImage = config.remoteImage
|
||||||
|
|
||||||
|
getContainerId = ->
|
||||||
|
fs.readFileAsync( '/proc/1/cgroup' )
|
||||||
|
.then (data) ->
|
||||||
|
data.toString().match( /:cpu:\/docker\/(.*)$/m )[ 1 ]
|
||||||
|
.catch (err) ->
|
||||||
|
return process.env.HOSTNAME
|
||||||
|
|
||||||
|
getCurrentContainer = ->
|
||||||
|
getContainerId().then (containerId) ->
|
||||||
|
docker.getContainer(containerId).inspectAsync()
|
||||||
|
|
||||||
startNewSupervisor = (currentSupervisor) ->
|
startNewSupervisor = (currentSupervisor) ->
|
||||||
console.log('Creating supervisor container:', localImage)
|
console.log('Creating supervisor container:', localImage)
|
||||||
docker.createContainerAsync(
|
docker.createContainerAsync(
|
||||||
@ -53,8 +65,7 @@ startNewSupervisor = (currentSupervisor) ->
|
|||||||
console.log('Exiting to let the new supervisor take over')
|
console.log('Exiting to let the new supervisor take over')
|
||||||
process.exit()
|
process.exit()
|
||||||
|
|
||||||
# Docker sets the HOSTNAME as the container's short id.
|
currentSupervisor = getCurrentContainer().tap (currentSupervisor) ->
|
||||||
currentSupervisor = docker.getContainer(process.env.HOSTNAME).inspectAsync().tap (currentSupervisor) ->
|
|
||||||
# The volume keys are the important bit.
|
# The volume keys are the important bit.
|
||||||
expectedVolumes = _.sortBy(_.keys(config.supervisorContainer.Volumes))
|
expectedVolumes = _.sortBy(_.keys(config.supervisorContainer.Volumes))
|
||||||
actualVolumes = _.sortBy(_.keys(currentSupervisor.Volumes))
|
actualVolumes = _.sortBy(_.keys(currentSupervisor.Volumes))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user