mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-21 03:25:46 +00:00
Make Blinkable LED configurable + Move blink to utils + Check connectivity before bootstrap + Blink LED on loss of connection
This commit is contained in:
parent
3975939181
commit
e7216618ad
@ -6,6 +6,7 @@ WORKDIR /app
|
||||
|
||||
ENV SUPERVISOR_IMAGE resin/x86-supervisor
|
||||
ENV CONFIG_MOUNT_POINT /boot/config.json
|
||||
ENV LED_FILE /dev/null
|
||||
|
||||
RUN rm -rf node_modules
|
||||
RUN npm install --unsafe-perm --production
|
||||
|
@ -17,6 +17,7 @@
|
||||
"knex": "~0.5.1",
|
||||
"lodash": "~2.4.1",
|
||||
"mixpanel": "0.0.20",
|
||||
"ping": "0.1.8",
|
||||
"pubnub": "~3.6.4",
|
||||
"request": "~2.22.0",
|
||||
"resin-platform-api": "git+ssh://git@bitbucket.org:rulemotion/resin-platform-api.git#v0.2.3",
|
||||
|
@ -7,16 +7,9 @@ supervisor = require './supervisor-update'
|
||||
|
||||
api = express()
|
||||
|
||||
LED_FILE = '/sys/class/leds/led0/brightness'
|
||||
|
||||
blink = (ms = 200) ->
|
||||
fs.writeFileAsync(LED_FILE, 1)
|
||||
.delay(ms)
|
||||
.then -> fs.writeFileAsync(LED_FILE, 0)
|
||||
|
||||
api.post '/v1/blink', (req, res) ->
|
||||
utils.mixpanelTrack('Device blink')
|
||||
interval = setInterval(blink, 400)
|
||||
interval = setInterval(utils.blink, 400)
|
||||
setTimeout(->
|
||||
clearInterval(interval)
|
||||
, 15000)
|
||||
|
@ -8,11 +8,37 @@ bootstrap = require './bootstrap'
|
||||
|
||||
utils.mixpanelTrack('Supervisor start')
|
||||
|
||||
connectivityState = true # Used to prevent multiple messages when disconnected
|
||||
|
||||
ensureConnected = (continuous=false) ->
|
||||
utils.checkConnectivity()
|
||||
.then (connected) ->
|
||||
if not connected
|
||||
if connectivityState
|
||||
console.log('Waiting for connectivity...')
|
||||
connectivityState = false
|
||||
interval = setInterval(utils.blink,200)
|
||||
Promise.delay(1000)
|
||||
.then ->
|
||||
# Clear the blinks after 1 second
|
||||
clearInterval(interval)
|
||||
ensureConnected(continuous)
|
||||
else
|
||||
if not connectivityState
|
||||
console.log('Internet Connectivity: OK')
|
||||
connectivityState = true
|
||||
if continuous
|
||||
setTimeout(->
|
||||
ensureConnected(continuous)
|
||||
, 10 * 1000) # Every 10 seconds perform this check.
|
||||
|
||||
|
||||
knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
if not uuid?.value
|
||||
console.log('New device detected. Bootstrapping..')
|
||||
utils.mixpanelTrack('Device bootstrap')
|
||||
bootstrap()
|
||||
ensureConnected().then ->
|
||||
utils.mixpanelTrack('Device bootstrap')
|
||||
bootstrap()
|
||||
else
|
||||
uuid.value
|
||||
.then (uuid) ->
|
||||
@ -67,3 +93,6 @@ knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
setInterval(updateIpAddr, 5 * 60 * 1000) # Every 5 mins
|
||||
updateIpAddr()
|
||||
|
||||
console.log('Starting connectivity check..')
|
||||
ensureConnected(true)
|
||||
|
||||
|
@ -8,6 +8,7 @@ module.exports = config =
|
||||
dockerSocket: process.env.DOCKER_SOCKET ? '/run/docker.sock'
|
||||
localImage: process.env.SUPERVISOR_IMAGE ? 'resin/rpi-supervisor'
|
||||
configMountPoint: process.env.CONFIG_MOUNT_POINT ? '/mnt/mmcblk0p1/config.json'
|
||||
ledFile: process.env.LED_FILE ? '/sys/class/leds/led0/brightness'
|
||||
|
||||
config.remoteImage = config.registryEndpoint + '/' + config.localImage
|
||||
|
||||
|
@ -3,6 +3,7 @@ _ = require 'lodash'
|
||||
fs = Promise.promisifyAll require 'fs'
|
||||
config = require './config'
|
||||
mixpanel = require 'mixpanel'
|
||||
ping = require 'ping'
|
||||
|
||||
# Parses package.json and returns resin-supervisor's version
|
||||
exports.getSupervisorVersion = ->
|
||||
@ -46,3 +47,17 @@ exports.findIpAddrs = ->
|
||||
prevLine = line
|
||||
return ipAddr
|
||||
.filter(Boolean)
|
||||
|
||||
# Helps in blinking the LED from the given end point.
|
||||
exports.blink = (ms = 200) ->
|
||||
fs.writeFileAsync(config.ledFile, 1)
|
||||
.delay(ms)
|
||||
.then -> fs.writeFileAsync(config.ledFile, 0)
|
||||
|
||||
# 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user