Skip to content

Commit

Permalink
netcat dependency for syslog
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Apr 23, 2015
1 parent 1388516 commit b78decc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions kong/cli/restart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ if not signal.send_signal(args.config) then
end

cutils.logger:success("Restarted")
cutils.logger:syslog("Restarted")
1 change: 1 addition & 0 deletions kong/cli/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ signal.prepare_kong(args.config)

if signal.send_signal(args.config) then
cutils.logger:success("Started")
cutils.logger:syslog("Started")
else
cutils.logger:error_exit("Could not start Kong")
end
6 changes: 2 additions & 4 deletions kong/cli/utils/signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ local kong_config_path
local kong_config
local dao_factory

local KONG_SYSLOG = "kong-hf.mashape.com"

-- Retrieve the desired Kong config file, parse it and provides a DAO factory
-- Will cache them for future retrieval
-- @param args_config Path to the desired configuration (usually from the --config CLI argument)
Expand Down Expand Up @@ -109,8 +107,8 @@ local function prepare_nginx_working_dir(args_config)
if kong_config.send_anonymous_reports then
-- If there is no internet connection, disable this feature
local socket = require "socket"
if socket.dns.toip(KONG_SYSLOG) then
nginx_config = "error_log syslog:server="..KONG_SYSLOG..":61828 error;\n"..nginx_config
if socket.dns.toip(constants.SYSLOG.ADDRESS) then
nginx_config = "error_log syslog:server="..constants.SYSLOG.ADDRESS..":"..tostring(constants.SYSLOG.PORT).." error;\n"..nginx_config
else
cutils.logger:warn("The internet connection might not be available, cannot resolve "..KONG_SYSLOG)
end
Expand Down
4 changes: 4 additions & 0 deletions kong/cli/utils/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function Logger:error_exit(str)
os.exit(1)
end

function Logger:syslog(str)
IO.os_execute("nc -w0 -u "..constants.SYSLOG.ADDRESS.." "..tostring(constants.SYSLOG.PORT).." <<< \"<14>"..str.."\"")
end

local logger = Logger()

--
Expand Down
4 changes: 4 additions & 0 deletions kong/constants.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
return {
NAME = "kong",
VERSION = "0.2.0-1",
SYSLOG = {
ADDRESS = "kong-hf.mashape.com",
PORT = 61828
},
CLI = {
GLOBAL_KONG_CONF = "/etc/kong/kong.yml",
NGINX_CONFIG = "nginx.conf",
Expand Down
2 changes: 2 additions & 0 deletions package-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ elif hash yum 2>/dev/null; then

PACKAGE_TYPE="rpm"
LUA_MAKE="linux"
FPM_PARAMS="-d nc"
elif hash apt-get 2>/dev/null; then
if [[ $EUID -eq 0 ]]; then
# If already root, install sudo just in case (Docker)
Expand All @@ -81,6 +82,7 @@ elif hash apt-get 2>/dev/null; then

PACKAGE_TYPE="deb"
LUA_MAKE="linux"
FPM_PARAMS="-d netcat"
else
echo "Unsupported platform"
exit 1
Expand Down

0 comments on commit b78decc

Please sign in to comment.