Skip to content

Commit

Permalink
Adds Upstart version detection and separate conf, fixes sysv script, …
Browse files Browse the repository at this point in the history
…compatible service stopping
  • Loading branch information
excieve authored and buger committed Apr 20, 2018
1 parent df99f64 commit 7c8b291
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 37 deletions.
2 changes: 1 addition & 1 deletion install/inits/systemd/system/tyk-gateway-lua.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Group=root
# exist, it continues onward.
EnvironmentFile=-/etc/default/tyk-gateway
EnvironmentFile=-/etc/sysconfig/tyk-gateway
ExecStart=/opt/tyk-gateway/tyk-lua --conf=/opt/tyk-gateway/tyk.conf
ExecStart=/opt/tyk-gateway/tyk-lua --conf /opt/tyk-gateway/tyk.conf
Restart=always
WorkingDirectory=/opt/tyk-gateway
RuntimeDirectory=tyk
Expand Down
2 changes: 1 addition & 1 deletion install/inits/systemd/system/tyk-gateway-python.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Group=root
# exist, it continues onward.
EnvironmentFile=-/etc/default/tyk-gateway
EnvironmentFile=-/etc/sysconfig/tyk-gateway
ExecStart=/opt/tyk-gateway/tyk-python --conf=/opt/tyk-gateway/tyk.conf
ExecStart=/opt/tyk-gateway/tyk-python --conf /opt/tyk-gateway/tyk.conf
Restart=always
WorkingDirectory=/opt/tyk-gateway
RuntimeDirectory=tyk
Expand Down
2 changes: 1 addition & 1 deletion install/inits/systemd/system/tyk-gateway.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Group=root
# exist, it continues onward.
EnvironmentFile=-/etc/default/tyk-gateway
EnvironmentFile=-/etc/sysconfig/tyk-gateway
ExecStart=/opt/tyk-gateway/tyk --conf=/opt/tyk-gateway/tyk.conf
ExecStart=/opt/tyk-gateway/tyk --conf /opt/tyk-gateway/tyk.conf
Restart=always
WorkingDirectory=/opt/tyk-gateway
RuntimeDirectory=tyk
Expand Down
9 changes: 1 addition & 8 deletions install/inits/sysv/init.d/tyk-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export PATH

name=tyk-gateway
program=/opt/tyk-gateway/tyk
args='--conf=/opt/tyk-gateway/tyk.conf'
args='--conf /opt/tyk-gateway/tyk.conf'
pidfile="/var/run/tyk-gateway.pid"

[ -r /etc/default/$name ] && . /etc/default/$name
Expand All @@ -36,13 +36,6 @@ emit() {
}

start() {

# Ensure the log directory is setup correctly.
[ ! -d "/var/log/" ] && mkdir "/var/log/"
chown "$user":"$group" "/var/log/"
chmod 755 "/var/log/"


# Setup any environmental stuff beforehand


Expand Down
9 changes: 1 addition & 8 deletions install/inits/sysv/init.d/tyk-gateway-lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export PATH

name=tyk-gateway-lua
program=/opt/tyk-gateway/tyk-lua
args='--conf=/opt/tyk-gateway/tyk.conf'
args='--conf /opt/tyk-gateway/tyk.conf'
pidfile="/var/run/tyk-gateway.pid"

[ -r /etc/default/$name ] && . /etc/default/$name
Expand All @@ -36,13 +36,6 @@ emit() {
}

start() {

# Ensure the log directory is setup correctly.
[ ! -d "/var/log/" ] && mkdir "/var/log/"
chown "$user":"$group" "/var/log/"
chmod 755 "/var/log/"


# Setup any environmental stuff beforehand


Expand Down
9 changes: 1 addition & 8 deletions install/inits/sysv/init.d/tyk-gateway-python
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export PATH

name=tyk-gateway-python
program=/opt/tyk-gateway/tyk-python
args='--conf=/opt/tyk-gateway/tyk.conf'
args='--conf /opt/tyk-gateway/tyk.conf'
pidfile="/var/run/tyk-gateway.pid"

[ -r /etc/default/$name ] && . /etc/default/$name
Expand All @@ -36,13 +36,6 @@ emit() {
}

start() {

# Ensure the log directory is setup correctly.
[ ! -d "/var/log/" ] && mkdir "/var/log/"
chown "$user":"$group" "/var/log/"
chmod 755 "/var/log/"


# Setup any environmental stuff beforehand


Expand Down
32 changes: 32 additions & 0 deletions install/inits/upstart/init/0.x/tyk-gateway-lua.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
description "Tyk API Gateway (Lua)"
start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
umask 022
#nice
#chroot /
chdir /opt/tyk-gateway/
#limit core <softlimit> <hardlimit>
#limit cpu <softlimit> <hardlimit>
#limit data <softlimit> <hardlimit>
#limit fsize <softlimit> <hardlimit>
#limit memlock <softlimit> <hardlimit>
#limit msgqueue <softlimit> <hardlimit>
#limit nice <softlimit> <hardlimit>
#limit nofile <softlimit> <hardlimit>
#limit nproc <softlimit> <hardlimit>
#limit rss <softlimit> <hardlimit>
#limit rtprio <softlimit> <hardlimit>
#limit sigpending <softlimit> <hardlimit>
#limit stack <softlimit> <hardlimit>

script
# When loading default and sysconfig files, we use `set -a` to make
# all variables automatically into environment variables.
set -a
[ -r /etc/default/tyk-gateway ] && . /etc/default/tyk-gateway
[ -r /etc/sysconfig/tyk-gateway ] && . /etc/sysconfig/tyk-gateway
set +a
exec chroot --userspec root:root / sh -c "cd /opt/tyk-gateway; exec /opt/tyk-gateway/tyk-lua --conf /opt/tyk-gateway/tyk.conf" >> /var/log/tyk-gateway.stdout 2>> /var/log/tyk-gateway.stderr
end script
32 changes: 32 additions & 0 deletions install/inits/upstart/init/0.x/tyk-gateway-python.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
description "Tyk API Gateway (Python)"
start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
umask 022
#nice
#chroot /
chdir /opt/tyk-gateway/
#limit core <softlimit> <hardlimit>
#limit cpu <softlimit> <hardlimit>
#limit data <softlimit> <hardlimit>
#limit fsize <softlimit> <hardlimit>
#limit memlock <softlimit> <hardlimit>
#limit msgqueue <softlimit> <hardlimit>
#limit nice <softlimit> <hardlimit>
#limit nofile <softlimit> <hardlimit>
#limit nproc <softlimit> <hardlimit>
#limit rss <softlimit> <hardlimit>
#limit rtprio <softlimit> <hardlimit>
#limit sigpending <softlimit> <hardlimit>
#limit stack <softlimit> <hardlimit>

script
# When loading default and sysconfig files, we use `set -a` to make
# all variables automatically into environment variables.
set -a
[ -r /etc/default/tyk-gateway ] && . /etc/default/tyk-gateway
[ -r /etc/sysconfig/tyk-gateway ] && . /etc/sysconfig/tyk-gateway
set +a
exec chroot --userspec root:root / sh -c "cd /opt/tyk-gateway; exec /opt/tyk-gateway/tyk-python --conf /opt/tyk-gateway/tyk.conf" >> /var/log/tyk-gateway.stdout 2>> /var/log/tyk-gateway.stderr
end script
32 changes: 32 additions & 0 deletions install/inits/upstart/init/0.x/tyk-gateway.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
description "Tyk API Gateway"
start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
umask 022
#nice
#chroot /
chdir /opt/tyk-gateway/
#limit core <softlimit> <hardlimit>
#limit cpu <softlimit> <hardlimit>
#limit data <softlimit> <hardlimit>
#limit fsize <softlimit> <hardlimit>
#limit memlock <softlimit> <hardlimit>
#limit msgqueue <softlimit> <hardlimit>
#limit nice <softlimit> <hardlimit>
#limit nofile <softlimit> <hardlimit>
#limit nproc <softlimit> <hardlimit>
#limit rss <softlimit> <hardlimit>
#limit rtprio <softlimit> <hardlimit>
#limit sigpending <softlimit> <hardlimit>
#limit stack <softlimit> <hardlimit>

script
# When loading default and sysconfig files, we use `set -a` to make
# all variables automatically into environment variables.
set -a
[ -r /etc/default/tyk-gateway ] && . /etc/default/tyk-gateway
[ -r /etc/sysconfig/tyk-gateway ] && . /etc/sysconfig/tyk-gateway
set +a
exec chroot --userspec root:root / sh -c "cd /opt/tyk-gateway; exec /opt/tyk-gateway/tyk --conf /opt/tyk-gateway/tyk.conf" >> /var/log/tyk-gateway.stdout 2>> /var/log/tyk-gateway.stderr
end script
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stop on runlevel [!2345]

respawn
umask 022
#nice
#nice
chroot /
chdir /opt/tyk-gateway/
#limit core <softlimit> <hardlimit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stop on runlevel [!2345]

respawn
umask 022
#nice
#nice
chroot /
chdir /opt/tyk-gateway/
#limit core <softlimit> <hardlimit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stop on runlevel [!2345]

respawn
umask 022
#nice
#nice
chroot /
chdir /opt/tyk-gateway/
#limit core <softlimit> <hardlimit>
Expand Down
15 changes: 11 additions & 4 deletions install/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ if [ -d "$SYSTEMD" ] && systemctl status > /dev/null 2> /dev/null; then
fi

if [ -d "$UPSTART" ]; then
echo "Found upstart"
[ -f /etc/default/tyk-gateway ] || cp $DIR/inits/upstart/default/tyk-gateway /etc/default/
cp $DIR/inits/upstart/init/tyk-gateway.conf /etc/init/
cp $DIR/inits/upstart/init/tyk-gateway-lua.conf /etc/init/
cp $DIR/inits/upstart/init/tyk-gateway-python.conf /etc/init/
if [[ "$(initctl version)" =~ .*upstart[[:space:]]1\..* ]]; then
echo "Found upstart 1.x+"
cp $DIR/inits/upstart/init/1.x/tyk-gateway.conf /etc/init/
cp $DIR/inits/upstart/init/1.x/tyk-gateway-lua.conf /etc/init/
cp $DIR/inits/upstart/init/1.x/tyk-gateway-python.conf /etc/init/
else
echo "Found upstart 0.x"
cp $DIR/inits/upstart/init/0.x/tyk-gateway.conf /etc/init/
cp $DIR/inits/upstart/init/0.x/tyk-gateway-lua.conf /etc/init/
cp $DIR/inits/upstart/init/0.x/tyk-gateway-python.conf /etc/init/
fi
exit
fi

Expand Down
6 changes: 3 additions & 3 deletions install/post_remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fi
if [ -f "/etc/init/tyk-gateway.conf" ]; then
echo "Found upstart"
echo "Stopping the service"
service tyk-gateway stop
service tyk-gateway-python stop
service tyk-gateway-lua stop
stop tyk-gateway
stop tyk-gateway-python
stop tyk-gateway-lua
echo "Removing the service"
rm /etc/init/tyk-gateway.conf
rm /etc/init/tyk-gateway-python.conf
Expand Down

0 comments on commit 7c8b291

Please sign in to comment.