Skip to content

Commit

Permalink
Merge pull request #72 from Mashape/fix/folders
Browse files Browse the repository at this point in the history
closes #71
  • Loading branch information
subnetmarco committed Mar 12, 2015
2 parents daad0f8 + 09fd0ff commit 9a5ae89
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
57 changes: 47 additions & 10 deletions bin/kong
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@
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
# Setting configuration path
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

# Setting nginx output path
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 All @@ -32,6 +45,11 @@ function real_path_func {
fi
}

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

##############
# Operations #
##############
Expand All @@ -48,27 +66,43 @@ 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 {
printf "Starting Kong"
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 +170,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/kong

# Specify the DAO to use
database: cassandra

Expand Down
1 change: 1 addition & 0 deletions site/app/_includes/pages/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ nginx: |
Here is a detailed description for each entry:
* `plugins_available` describes an array of plugins that are available and can be used by the server. You can use only the plugins that are being specified here.
* `output` optionally sets the output directory of the Kong working directory and its logs. If not set the Kong installation directory will be used instead.
* `database` is the database Kong is going to use. It's `cassandra` by default and it's the only one supported at the moment.
* `databases_available` describes the configuration to use when connecting to the database.
* `send_anonymous_reports` tells if the system is allowed to send anonymous error logs to a remote logging server in order to allow the maintainers of Kong to fix potential bugs and errors.
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 9a5ae89

Please sign in to comment.