From a8e1d476e357888b2c9c981fc587de92524b5e8b Mon Sep 17 00:00:00 2001 From: Praneeth Bodduluri Date: Wed, 2 Sep 2015 17:42:11 +0530 Subject: [PATCH] Change to use 204 for API, Remove extra space in upscript.sh and Make fswatch start only on EEXIST error --- src/api.coffee | 10 +++++----- src/app.coffee | 2 +- src/utils.coffee | 7 +++---- tools/dind/config/openvpn/upscript.sh | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/api.coffee b/src/api.coffee index 5b2ea022..4e1e114b 100644 --- a/src/api.coffee +++ b/src/api.coffee @@ -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 diff --git a/src/app.coffee b/src/app.coffee index 23859f72..7558631c 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -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') diff --git a/src/utils.coffee b/src/utils.coffee index 2671da58..c6066264 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -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() diff --git a/tools/dind/config/openvpn/upscript.sh b/tools/dind/config/openvpn/upscript.sh index 9ee02c2a..922a7beb 100755 --- a/tools/dind/config/openvpn/upscript.sh +++ b/tools/dind/config/openvpn/upscript.sh @@ -1,4 +1,4 @@ #!/bin/bash mkdir -p /run/openvpn/vpn_status -touch /run/openvpn/vpn_status/active +touch /run/openvpn/vpn_status/active