Change to use 204 for API, Remove extra space in upscript.sh and Make fswatch start only on EEXIST error

This commit is contained in:
Praneeth Bodduluri 2015-09-02 17:42:11 +05:30 committed by Pablo Carranza Vélez
parent 7b8ca9fd73
commit a8e1d476e3
4 changed files with 10 additions and 11 deletions

View File

@ -9,7 +9,7 @@ bodyParser = require 'body-parser'
request = require 'request'
config = require './config'
module.exports = (secret, disableCheck) ->
module.exports = (secret) ->
api = express()
api.use(bodyParser())
api.use (req, res, next) ->
@ -85,11 +85,11 @@ module.exports = (secret, disableCheck) ->
res.status(503).send(err?.message or err or 'Unknown error')
api.post '/tcp-ping', (req, res) ->
disableCheck(false)
res.status(200).send('OK\n')
utils.disableCheck(false)
res.sendStatus(204)
api.delete '/tcp-ping', (req, res) ->
disableCheck(true)
res.status(200).send('OK\n')
utils.disableCheck(true)
res.sendStatus(204)
return api

View File

@ -37,7 +37,7 @@ knex.init.then ->
console.log('Starting API server..')
secret = config.forceApiSecret ? randomstring.generate()
api(secret, utils.disableCheck).listen(config.listenPort)
api(secret).listen(config.listenPort)
# Let API know what version we are, and our api connection info.
console.log('Updating supervisor version and api info')

View File

@ -103,11 +103,10 @@ EEXIST = (err) -> err.code is 'EEXIST'
exports.connectivityCheck = _.once ->
parsedUrl = url.parse(config.apiEndpoint)
fs.mkdirAsync(config.vpnStatusPath)
.then ->
console.log('Creating directory for watching VPN status...')
.finally ->
fs.watch(config.vpnStatusPath, vpnStatusInotifyCallback)
.catch EEXIST, (err) ->
console.log('VPN status path exists.')
.then ->
fs.watch(config.vpnStatusPath, vpnStatusInotifyCallback)
# Manually trigger the call back to detect cases when VPN was switched on before the supervisor starts.
vpnStatusInotifyCallback()

View File

@ -1,4 +1,4 @@
#!/bin/bash
mkdir -p /run/openvpn/vpn_status
touch /run/openvpn/vpn_status/active
touch /run/openvpn/vpn_status/active