Kong: how to let kong start automatically

Created on 30 Apr 2017  路  14Comments  路  Source: Kong/kong

Following is my /etc/rc.d/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/local/bin/kong start > /home/ec2-user/log

And the kong doesn't start, following is /home/ec2-user/log

[ec2-user@ip-172-16-1-127 ~]$ cat log
ulimit is currently set to "1024". For better performance set it to at least "4096" using "ulimit -n"
[ec2-user@ip-172-16-1-127 ~]$ kong health
serf........not running
nginx.......not running

Error: Kong is not running at /usr/local/kong

  Run with --v (verbose) or --vv (debug) for more details
[ec2-user@ip-172-16-1-127 ~]$ kong health -v
2017/04/30 05:37:03 [verbose] Kong: 0.10.1
2017/04/30 05:37:03 [verbose] reading config file at /etc/kong/kong.conf
2017/04/30 05:37:03 [verbose] prefix in use: /usr/local/kong
2017/04/30 05:37:03 [verbose] reading config file at /usr/local/kong/.kong_env
2017/04/30 05:37:03 [verbose] prefix in use: /usr/local/kong
2017/04/30 05:37:03 [info] serf........not running
2017/04/30 05:37:03 [info] nginx.......not running
2017/04/30 05:37:03 [info] 
Error: 
/usr/local/share/lua/5.1/kong/cmd/health.lua:38: Kong is not running at /usr/local/kong
stack traceback:
    [C]: in function 'assert'
    /usr/local/share/lua/5.1/kong/cmd/health.lua:38: in function 'cmd_exec'
    /usr/local/share/lua/5.1/kong/cmd/init.lua:88: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:88>
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/kong/cmd/init.lua:88: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:45>
    /usr/local/bin/kong:5: in function 'file_gen'
    init_worker_by_lua:38: in function <init_worker_by_lua:36>
    [C]: in function 'pcall'
    init_worker_by_lua:45: in function <init_worker_by_lua:43>

What does following error mean and how to enable auto start? thx
Error:
/usr/local/share/lua/5.1/kong/cmd/health.lua:38: Kong is not running at /usr/local/kong

Most helpful comment

you can use systemd for Control kong service.
First create kong.service file :

> # vi /usr/lib/systemd/system/kong.service

and then put this lines in file :

[Unit]
Description= kong service
After=syslog.target network.target


[Service]
User=root
Group=root
Type=forking
ExecStart=/usr/local/bin/kong start
ExecReload=/usr/local/bin/kong reload
ExecStop=/usr/local/bin/kong stop

[Install]
WantedBy=multi-user.target


now you can Control kong by systemd :

# systemctl start kong
# systemctl stop kong
# systemctl enable kong

All 14 comments

you can use systemd for Control kong service.
First create kong.service file :

> # vi /usr/lib/systemd/system/kong.service

and then put this lines in file :

[Unit]
Description= kong service
After=syslog.target network.target


[Service]
User=root
Group=root
Type=forking
ExecStart=/usr/local/bin/kong start
ExecReload=/usr/local/bin/kong reload
ExecStop=/usr/local/bin/kong stop

[Install]
WantedBy=multi-user.target


now you can Control kong by systemd :

# systemctl start kong
# systemctl stop kong
# systemctl enable kong

Hi, hos7ein
Thank you for your quick response.
But I'm using amazon linux which is more like centos 6 and not based on systemd

I wish there was support for a PID file or foreground operation so Kong can be properly controlled by something like systemd or supervisord instead of its own faulty implementation...

@gjedeer there's already discussion for this: #928. And, systemd and supervisord are not the only init/process management processes available :) Kong at it's core seeks to be as platform agnostic as possible; indeed, it's up the distribution to maintain the daemon.

@iwasnobody what do you see in /usr/local/kong/logs/error.log? stdout isn't going to contain anything useful.

@p0pr0ck5 thanks! The current model looks good for the old good sysv init, but I have consistently found Kong dead and had to restart it manually. I'd rather use a supervising process manager than write scripts to connect to Kong's port and restart it if it's dead.

@p0pr0ck5 nothing in /usr/local/kong/logs/error.log

@iwasnobody are you sure /etc/rc.d/rc.local is getting executed?

@p0pr0ck5
the command in rc.local is changed and kong can be started in shell manually with the following command:
/usr/local/bin/kong start > /home/ec2-user/log

Since /home/ec2-user/log has shown
ulimit is currently set to "1024". For better performance set it to at least "4096" using "ulimit -n"
which will also popup when start kong manually

I guess the command in rc.local is definitely be executed.

@iwasnobody it sounds like you want to check your system config settings, kernel logs, etc. If you're able to start up kong normally via the CLI, then this issue isn't with Kong running, but your system configuration, which we cannot help with.

Closing this following no response. BTW for sysvinit systems its probably easier to just write an init script: https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

@hos7ein Thanks very much !.
I have made it auto startup and able to do the operations using systemctl .
It's perfectly working on Centos 7.5

your welcome @knowledgeshare99

you can use systemd for Control kong service.
First create kong.service file :

> # vi /usr/lib/systemd/system/kong.service

and then put this lines in file :

[Unit]
Description= kong service
After=syslog.target network.target


[Service]
User=root
Group=root
Type=forking
ExecStart=/usr/local/bin/kong start
ExecReload=/usr/local/bin/kong reload
ExecStop=/usr/local/bin/kong stop

[Install]
WantedBy=multi-user.target

now you can Control kong by systemd :

# systemctl start kong
# systemctl stop kong
# systemctl enable kong

Need to start after database service
After=syslog.target network.target postgresql.service

@eurodomenii in this case you're assuming to be using a PostgreSQL database. But Kong supports Cassandra and db-less mode too. Here's my suggestion:

[Unit]
Description=Kong
Documentation=https://docs.konghq.com
After=syslog.target network.target

[Service]
User=root
Group=root
Type=forking
ExecStart=/usr/local/bin/kong start
ExecReload=/usr/local/bin/kong reload
ExecStop=/usr/local/bin/kong stop

LimitAS=infinity
LimitRSS=infinity
LimitCORE=infinity
LimitNOFILE=4096

# All environment variables prefixed with `KONG_` and capitalized will override
# the settings specified in the `/etc/kong/kong.conf.default` file.
#
# Example:
#   `plugins` setting -> `KONG_PLUGINS` env variable
#
# Please refer to https://docs.konghq.com/latest/configuration for details.
#
#Environment=KONG_PLUGINS=bundled
#Environment=KONG_PREFIX=/usr/local/kong/

# Please be careful when linking non environment files using the
# EnvironmentFile directive as the systemd parser will only recognize
# environment variables assignments. For example, if you specify the file
# `/etc/kong/kong.conf.default`, it could contain some non environment
# variables assignments. In this case systemd will not allow the Kong service
# to be started. For this reason, we recommend specifying a different
# EnvironmentFile other than the default files `/etc/kong/kong.conf.default`
# and `/etc/kong.conf`:
#EnvironmentFile=-/etc/kong/kong_env.conf

[Install]
WantedBy=multi-user.target

What do you think @p0pr0ck5 @hos7ein

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daviesf1 picture daviesf1  路  39Comments

jeremyjpj0916 picture jeremyjpj0916  路  65Comments

jeremyjpj0916 picture jeremyjpj0916  路  81Comments

subnetmarco picture subnetmarco  路  97Comments

ahmadnassri picture ahmadnassri  路  59Comments