Skip to content

Commit

Permalink
closes #71
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Mar 12, 2015
1 parent daad0f8 commit b1718c2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
54 changes: 45 additions & 9 deletions bin/kong
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
export KONG_HOME="$(echo $SCRIPT_DIR | sed -e 's/\/[^\/]*$//')"

# Properties
export KONG_CONF=$KONG_HOME/kong.yml
NGINX_TMP=$KONG_HOME/nginx_tmp
if [ -f /etc/kong.yml ]; then
export KONG_CONF=/etc/kong.yml
printf "Giving priority to configuration stored at "$KONG_CONF" - To override use -c option\n"
else
export KONG_CONF=$KONG_HOME/kong.yml
fi

nginx_output=$(lua -e "print(require('yaml').load(require('kong.tools.utils').read_file('$KONG_CONF')).output)")
if [ "$nginx_output" == "nil" ]; then
export NGINX_TMP=$KONG_HOME/nginx_tmp
else
export NGINX_TMP=$nginx_output
fi

PID=$NGINX_TMP/nginx.pid

######################
Expand Down Expand Up @@ -48,27 +60,48 @@ function show_help {
\trestart restart Kong
\t it is equivalent to executing 'stop' and 'start' in succession
\tmigrate performs a database migration, execute this operation carefully
\tversion output version informations and exit
\n"
}

function show_version {
printf "Kong Version 0.1\n"
printf "Kong version: 0.0.1beta-1\n"
}

function start {
function print_start_error {
printf "Starting Kong"
printf "$(tput setaf 1) [$1]\n$(tput sgr 0)"
}

function start {
if [ -f $PID ]; then
if ps -p $(cat $PID) > /dev/null
then
print_start_error "ALREADY RUNNING"
exit 1
fi
fi

printf "Kong (configuration at "$KONG_CONF" output at "$NGINX_TMP")\n"

mkdir -p $NGINX_TMP/logs &> /dev/null
if [ $? -ne 0 ]; then
printf "Cannot operate on $NGINX_TMP - Make sure you have the right permissions.\n\n"
print_start_error "ERROR"
exit 1
fi

mkdir -p $NGINX_TMP/logs
touch $NGINX_TMP/logs/error.log
touch $NGINX_TMP/logs/access.log
$KONG_HOME/scripts/config.lua -c $KONG_CONF -o $NGINX_TMP nginx
nginx -p $NGINX_TMP -c $NGINX_TMP/nginx.conf

if [ $? -eq 0 ]; then
printf "Starting Kong"
printf "$(tput setaf 2) [OK]\n$(tput sgr 0)"
else
printf "$(tput setaf 1) [ERROR]\n$(tput sgr 0)"
printf "\nYou can check what error has been returned by looking at the error log file"
printf "\nYou can get more information about this error by checking the error log file.\n\n"
print_start_error "ERROR"
exit 1
fi
}
Expand Down Expand Up @@ -136,11 +169,14 @@ case "$@" in
stop)
stop
;;
restart)
restart
;;
migrate)
migrate
;;
restart)
restart
version)
show_version
;;
*)
show_help
Expand Down
3 changes: 3 additions & 0 deletions kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ plugins_available:
- ratelimiting
- networklog

# Uncomment the following line to setup a custom output directory
output: /var/log/kong2

# Specify the DAO to use
database: cassandra

Expand Down
9 changes: 9 additions & 0 deletions spec/integration/server/server_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local yaml = require "yaml"
local utils = require "kong.tools.utils"
local spec_helper = require "spec.spec_helpers"
local constants = require "kong.constants"
local stringy = require "stringy"

local TEST_CONF = "kong_TEST.yml"
local SERVER_CONF = "kong_TEST_SERVER.yml"
Expand All @@ -20,6 +22,13 @@ end

describe("#server-cli", function()

describe("CLI", function()
it("should return the right version", function()
local result, exit_code = spec_helper.os_execute(spec_helper.KONG_BIN.." -v")
assert.are.same("Kong version: "..constants.VERSION, stringy.strip(result))
end)
end)

describe("Plugins Check", function()

setup(function()
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ local configuration, dao_factory = utils.load_configuration_and_dao(TEST_CONF_FI
local migrations = Migrations(dao_factory)
local faker = Faker(dao_factory)

local _M = {}
local _M = {
KONG_BIN = KONG_BIN
}

_M.CONF_FILE = TEST_CONF_FILE
_M.PROXY_URL = PROXY_URL
Expand Down

0 comments on commit b1718c2

Please sign in to comment.