Avoid ICMP on connectivity check.

This commit is contained in:
Lorenzo Stoakes 2014-09-30 18:53:21 +01:00 committed by Pablo Carranza Vélez
parent 6c7f891a2a
commit aa4ff76581
2 changed files with 12 additions and 8 deletions

View File

@ -10,6 +10,7 @@ module.exports = config =
configMountPoint: process.env.CONFIG_MOUNT_POINT ? '/mnt/mmcblk0p1/config.json'
ledFile: process.env.LED_FILE ? '/sys/class/leds/led0/brightness'
successMessage: 'SUPERVISOR OK'
heartbeatEndpoint: 'http://image.resin.io/ping'
config.remoteImage = config.registryEndpoint + '/' + config.localImage

View File

@ -3,7 +3,7 @@ _ = require 'lodash'
fs = Promise.promisifyAll require 'fs'
config = require './config'
mixpanel = require 'mixpanel'
ping = require 'ping'
request = Promise.promisifyAll require 'request'
# Parses package.json and returns resin-supervisor's version
exports.getSupervisorVersion = ->
@ -55,10 +55,13 @@ exports.blink = (ms = 200) ->
.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
# Helps in checking connectivity by pseudo-pinging our endpoint.
exports.checkConnectivity = ->
# We avoid using ICMP as this traffic is sometimes restricted/dropped. Good
# ol' port 80 HTTP should always be available :-)
request
.getAsync(config.heartbeatEndpoint)
.then ([ response ]) ->
return response.statusCode in [ 200, 304 ]
.catch ->
return false