mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 21:57:54 +00:00
Syntax cleanup pass.
This commit is contained in:
parent
70eef70be2
commit
f39b51885d
@ -11,7 +11,7 @@ utils.mixpanelTrack('Supervisor start')
|
||||
|
||||
connectivityState = true # Used to prevent multiple messages when disconnected
|
||||
|
||||
ensureConnected = (continuous=false) ->
|
||||
ensureConnected = (continuous = false) ->
|
||||
utils.checkConnectivity()
|
||||
.then (connected) ->
|
||||
if not connected
|
||||
@ -34,7 +34,7 @@ ensureConnected = (continuous=false) ->
|
||||
, 10 * 1000) # Every 10 seconds perform this check.
|
||||
|
||||
|
||||
knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
|
||||
if not uuid?.value
|
||||
console.log('New device detected. Bootstrapping..')
|
||||
ensureConnected().then ->
|
||||
@ -51,7 +51,7 @@ knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
supervisor = require './supervisor-update'
|
||||
|
||||
console.log('Starting OpenVPN..')
|
||||
openvpn = spawn('openvpn', ['client.conf'], cwd: '/data')
|
||||
openvpn = spawn('openvpn', [ 'client.conf' ], cwd: '/data')
|
||||
|
||||
# Prefix and log all OpenVPN output
|
||||
openvpn.stdout.on 'data', (data) ->
|
||||
@ -71,7 +71,7 @@ knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
.then (apps) ->
|
||||
Promise.all(apps.map(application.start))
|
||||
.catch (error) ->
|
||||
console.error("Error starting apps:", error)
|
||||
console.error('Error starting apps:', error)
|
||||
.then ->
|
||||
console.log('Starting periodic check for updates..')
|
||||
setInterval(->
|
||||
@ -98,4 +98,4 @@ knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
ensureConnected(true)
|
||||
|
||||
# Let the previous supervisor know that we started successfully
|
||||
console.log(config.successMessage)
|
||||
console.log(config.successMessage)
|
||||
|
@ -27,13 +27,13 @@ pubnub = PUBNUB.init(config.pubnub)
|
||||
publish = do ->
|
||||
publishQueue = []
|
||||
|
||||
knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
|
||||
uuid = uuid.value
|
||||
channel = "device-#{uuid}-logs"
|
||||
|
||||
# Redefine original function
|
||||
publish = (message) ->
|
||||
pubnub.publish({channel, message})
|
||||
pubnub.publish({ channel, message })
|
||||
|
||||
# Replay queue now that we have initialised the publish function
|
||||
publish(args...) for args in publishQueue
|
||||
@ -111,7 +111,7 @@ exports.start = start = (app) ->
|
||||
|
||||
stream.on('end', resolve)
|
||||
.then ->
|
||||
console.log("Creating container:", app.imageId)
|
||||
console.log('Creating container:', app.imageId)
|
||||
updateDeviceInfo(status: 'Starting')
|
||||
ports = {}
|
||||
if portList?
|
||||
@ -120,7 +120,7 @@ exports.start = start = (app) ->
|
||||
|
||||
docker.createContainerAsync(
|
||||
Image: app.imageId
|
||||
Cmd: ['/bin/bash', '-c', '/start']
|
||||
Cmd: [ '/bin/bash', '-c', '/start' ]
|
||||
Tty: true
|
||||
Volumes:
|
||||
'/data': {}
|
||||
@ -182,7 +182,7 @@ exports.update = update = ->
|
||||
knex('config').select('value').where(key: 'uuid')
|
||||
knex('app').select()
|
||||
])
|
||||
.then ([[apiKey], [uuid], apps]) ->
|
||||
.then ([ [ apiKey ], [ uuid ], apps ]) ->
|
||||
apiKey = apiKey.value
|
||||
uuid = uuid.value
|
||||
resinAPI.get(
|
||||
@ -195,7 +195,7 @@ exports.update = update = ->
|
||||
apikey: apiKey
|
||||
)
|
||||
.then (remoteApps) ->
|
||||
console.log("Remote apps")
|
||||
console.log('Remote apps')
|
||||
remoteApps = _.filter(remoteApps, 'commit')
|
||||
remoteApps = _.map remoteApps, (app) ->
|
||||
env =
|
||||
@ -217,21 +217,22 @@ exports.update = update = ->
|
||||
remoteImages = _.keys(remoteApps)
|
||||
console.log(remoteImages)
|
||||
|
||||
console.log("Local apps")
|
||||
console.log('Local apps')
|
||||
apps = _.indexBy(apps, 'imageId')
|
||||
localApps = _.mapValues(apps, (app) -> _.pick(app, ['appId', 'commit', 'imageId', 'env']))
|
||||
localApps = _.mapValues apps, (app) ->
|
||||
_.pick(app, [ 'appId', 'commit', 'imageId', 'env' ])
|
||||
localImages = _.keys(localApps)
|
||||
console.log(localImages)
|
||||
|
||||
console.log("Apps to be removed")
|
||||
console.log('Apps to be removed')
|
||||
toBeRemoved = _.difference(localImages, remoteImages)
|
||||
console.log(toBeRemoved)
|
||||
|
||||
console.log("Apps to be installed")
|
||||
console.log('Apps to be installed')
|
||||
toBeInstalled = _.difference(remoteImages, localImages)
|
||||
console.log(toBeInstalled)
|
||||
|
||||
console.log("Apps to be updated")
|
||||
console.log('Apps to be updated')
|
||||
toBeUpdated = _.intersection(remoteImages, localImages)
|
||||
toBeUpdated = _.filter toBeUpdated, (imageId) ->
|
||||
return !_.isEqual(remoteApps[imageId], localApps[imageId])
|
||||
|
@ -14,7 +14,7 @@ module.exports = config =
|
||||
config.remoteImage = config.registryEndpoint + '/' + config.localImage
|
||||
|
||||
config.supervisorContainer =
|
||||
Volumes:
|
||||
Volumes:
|
||||
'/boot/config.json': {}
|
||||
'/data': {}
|
||||
'/run/docker.sock': {}
|
||||
|
@ -16,7 +16,7 @@ remoteImage = config.remoteImage
|
||||
getContainerId = ->
|
||||
fs.readFileAsync( '/proc/1/cgroup' )
|
||||
.then (data) ->
|
||||
data.toString().match( /:cpu:\/docker\/(.*)$/m )[ 1 ]
|
||||
data.toString().match( /:cpu:\/docker\/(.*)$/m )[1]
|
||||
.catch (err) ->
|
||||
return process.env.HOSTNAME
|
||||
|
||||
@ -28,7 +28,7 @@ startNewSupervisor = (currentSupervisor) ->
|
||||
console.log('Creating supervisor container:', localImage)
|
||||
docker.createContainerAsync(
|
||||
Image: localImage
|
||||
Cmd: ['/start']
|
||||
Cmd: [ '/start' ]
|
||||
Volumes: config.supervisorContainer.Volumes
|
||||
Env: currentSupervisor.Config.Env
|
||||
)
|
||||
@ -86,7 +86,8 @@ exports.initialised = currentSupervisor.then (currentSupervisor) ->
|
||||
|
||||
supervisorUpdating = Promise.resolve()
|
||||
exports.update = ->
|
||||
# Make sure only one attempt to update the full supervisor is running at a time, ignoring any errors from previous update attempts
|
||||
# Make sure only one attempt to update the full supervisor is running at
|
||||
# a time, ignoring any errors from previous update attempts.
|
||||
supervisorUpdating = supervisorUpdating.catch(->).then ->
|
||||
utils.mixpanelTrack('Supervisor update check')
|
||||
console.log('Fetching supervisor:', remoteImage)
|
||||
|
@ -3,7 +3,8 @@ process.on 'uncaughtException', (e) ->
|
||||
|
||||
supervisor = require './supervisor-update'
|
||||
|
||||
# Make sure the supervisor-update has initialised before we continue, as it will handle restarting to add mounts if necessary.
|
||||
# Make sure the supervisor-update has initialised before we continue, as it will
|
||||
# handle restarting to add mounts if necessary.
|
||||
supervisor.initialised.then ->
|
||||
knex = require './db'
|
||||
|
||||
|
@ -12,14 +12,14 @@ exports.start = (appId) ->
|
||||
return apps[appId] = apps[appId].catch ->
|
||||
port = nextPort++
|
||||
knex('app').select().where({appId})
|
||||
.then ([app]) ->
|
||||
.then ([ app ]) ->
|
||||
if !app?
|
||||
throw new Error('App not found')
|
||||
tty.createServer
|
||||
shell: './src/enterContainer.sh'
|
||||
shellArgs: do ->
|
||||
i = 0
|
||||
return (session) -> [app.containerId, session.id, i++]
|
||||
return (session) -> [ app.containerId, session.id, i++ ]
|
||||
.listenAsync(port, null)
|
||||
.then ->
|
||||
ngrok.connectAsync(port)
|
||||
|
@ -17,7 +17,7 @@ mixpanelClient = mixpanel.init(config.mixpanelToken)
|
||||
exports.mixpanelProperties = mixpanelProperties =
|
||||
username: require('/boot/config.json').username
|
||||
|
||||
exports.mixpanelTrack = (event, properties={}) ->
|
||||
exports.mixpanelTrack = (event, properties = {}) ->
|
||||
console.log('Event:', event, JSON.stringify(properties))
|
||||
# Mutation is bad, and it should feel bad
|
||||
properties = _.assign(_.cloneDeep(properties), mixpanelProperties)
|
||||
@ -35,7 +35,9 @@ exports.findIpAddrs = ->
|
||||
|
||||
# We only care about LOCAL routes (not UNICAST or BROADCAST)
|
||||
if line.match(/LOCAL$/)
|
||||
# Then we make sure the previous line was an ending branch (and hence contains an IP - 127.0.0.0 has BROADCAST and LOCAL entries)
|
||||
# Then we make sure the previous line was an ending branch (and
|
||||
# hence contains an IP - 127.0.0.0 has BROADCAST and LOCAL
|
||||
# entries)
|
||||
if prevLine.match(/^\|--/)
|
||||
# Then we remove the ending branch bit
|
||||
maybeAddr = prevLine.replace(/^\|--/, '').trim()
|
||||
@ -56,8 +58,8 @@ exports.blink = (ms = 200) ->
|
||||
|
||||
# Helps in checking connectivity by pinging the given site.
|
||||
exports.checkConnectivity = (host = '8.8.8.8') ->
|
||||
ping.sys.promise_probe(host,
|
||||
timeout: 1
|
||||
extra: ["-c 1"]
|
||||
).then (res) ->
|
||||
return res.alive
|
||||
ping.sys.promise_probe(host,
|
||||
timeout: 1
|
||||
extra: [ '-c 1' ]
|
||||
).then (res) ->
|
||||
return res.alive
|
||||
|
Loading…
Reference in New Issue
Block a user