diff --git a/bin/kong b/bin/kong index 580c2f724eef..e7e644c325d9 100755 --- a/bin/kong +++ b/bin/kong @@ -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 ###################### @@ -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 } @@ -136,11 +169,14 @@ case "$@" in stop) stop ;; + restart) + restart + ;; migrate) migrate ;; - restart) - restart + version) + show_version ;; *) show_help diff --git a/kong.yml b/kong.yml index 77f2de4312e6..bf5b81e72a67 100644 --- a/kong.yml +++ b/kong.yml @@ -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 diff --git a/spec/integration/server/server_spec.lua b/spec/integration/server/server_spec.lua index 569aa265d11f..c930284055ef 100644 --- a/spec/integration/server/server_spec.lua +++ b/spec/integration/server/server_spec.lua @@ -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" @@ -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() diff --git a/spec/spec_helpers.lua b/spec/spec_helpers.lua index 09799ffabd53..14841cc74b22 100644 --- a/spec/spec_helpers.lua +++ b/spec/spec_helpers.lua @@ -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