feat: add openresty and runit support to packaging

Our docker image uses runit instead of init/systemd, hence the added sv support on Ubuntu operating systems.
This commit is contained in:
Jose Diaz-Gonzalez committed 2019-09-16 03:03:20 -04:00
1 parent 0e219b05e9
commit a9ce738f68
4 files changed
+63 -35

No files matched your search

+14 -3
View File
@@ -47,12 +47,23 @@ except subprocess.CalledProcessError:
ufw_display = 'none' ufw_display = 'none'
nginx_dir = '/etc/nginx'
nginx_init = '/etc/init.d/nginx'
try:
command = "test -x /usr/bin/openresty"
subprocess.check_output(command, shell=True).strip()
nginx_dir = '/usr/local/openresty/nginx/conf'
nginx_init = '/etc/init.d/openresty'
except subprocess.CalledProcessError:
pass
def check_boot(): def check_boot():
if 'onboot' not in sys.argv: if 'onboot' not in sys.argv:
return return
init_dir = os.getenv('INIT_DIR', '/etc/init') init_dir = os.getenv('INIT_DIR', '/etc/init')
systemd_dir = os.getenv('SYSTEMD_DIR', '/etc/systemd/system') systemd_dir = os.getenv('SYSTEMD_DIR', '/etc/systemd/system')
nginx_dir = os.getenv('NGINX_DIR', '/etc/nginx/conf.d') nginx_conf_dir = os.getenv('NGINX_CONF_DIR', '{0}/conf.d'.format(nginx_dir))
if os.path.exists(init_dir): if os.path.exists(init_dir):
with open('{0}/dokku-installer.conf'.format(init_dir), 'w') as f: with open('{0}/dokku-installer.conf'.format(init_dir), 'w') as f:
@@ -79,7 +90,7 @@ def check_boot():
f.write(" }\n") f.write(" }\n")
f.write("}\n") f.write("}\n")
subprocess.call('rm -f /etc/nginx/sites-enabled/*', shell=True) subprocess.call('rm -f {0}/sites-enabled/*'.format(nginx_dir), shell=True)
sys.exit(0) sys.exit(0)
@@ -203,7 +214,7 @@ class DeleteInstallerThread(object):
thread.start() thread.start()
def run(self): def run(self):
command = "rm /etc/nginx/conf.d/dokku-installer.conf && /etc/init.d/nginx stop && /etc/init.d/nginx start" command = "rm {0}/conf.d/dokku-installer.conf && {1} stop && {1} start".format(nginx_dir, nginx_init)
try: try:
subprocess.call(command, shell=True) subprocess.call(command, shell=True)
except: except:
+4 -1
View File
@@ -89,7 +89,10 @@ setup-sshcommand() {
} }
setup-dokku-installer() { setup-dokku-installer() {
if [[ -f /etc/nginx/conf.d/dokku-installer.conf ]]; then NGINX_ROOT="/etc/nginx"
[[ -x /usr/bin/openresty ]] && NGINX_ROOT="/usr/local/openresty/nginx/conf"
if [[ -f "$NGINX_ROOT/conf.d/dokku-installer.conf" ]]; then
echo "Setting up dokku-installer" echo "Setting up dokku-installer"
/usr/share/dokku/contrib/dokku-installer.py onboot /usr/share/dokku/contrib/dokku-installer.py onboot
+2
View File
@@ -28,6 +28,8 @@ main() {
fi fi
if [[ "$1" == "purge" ]]; then if [[ "$1" == "purge" ]]; then
rm -f /usr/local/openresty/nginx/conf/conf.d/dokku.conf
rm -f /usr/local/openresty/nginx/conf/conf.d/dokku-installer.conf
rm -f /etc/nginx/conf.d/dokku.conf rm -f /etc/nginx/conf.d/dokku.conf
rm -f /etc/nginx/conf.d/dokku-installer.conf rm -f /etc/nginx/conf.d/dokku-installer.conf
rm -f ${DOKKU_ROOT}/.dokkurc ${DOKKU_ROOT}/dokkurc ${DOKKU_ROOT}/tls rm -f ${DOKKU_ROOT}/.dokkurc ${DOKKU_ROOT}/dokkurc ${DOKKU_ROOT}/tls
+43 -31
View File
@@ -7,41 +7,53 @@ if [[ -e /usr/share/debconf/confmodule ]]; then
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
fi fi
setup_dokku_installer() {
NGINX_BASE_PATH="$1"
NGINX_INIT_NAME="$2"
NGINX_CONF="${NGINX_BASE_PATH}/conf.d/dokku-installer.conf"
rm -f $NGINX_CONF
touch $NGINX_CONF
{
echo 'upstream dokku-installer { server 127.0.0.1:2000; }'
echo 'server {'
echo ' listen 80;'
echo ' location / {'
echo ' proxy_pass http://dokku-installer;'
echo ' }'
echo '}'
} >>$NGINX_CONF
rm -f $NGINX_BASE_PATH/sites-enabled/*
DOKKU_DISTRO="$(
. /etc/os-release >/dev/null 2>&1 || true
echo "$ID"
)"
case "$DOKKU_DISTRO" in
debian)
/usr/sbin/invoke-rc.d "$NGINX_INIT_NAME" reload || /usr/sbin/invoke-rc.d "$NGINX_INIT_NAME" start
;;
ubuntu)
if [[ -x /usr/bin/sv ]]; then
/usr/bin/sv reload "$NGINX_INIT_NAME" || /usr/bin/sv start "$NGINX_INIT_NAME"
else
"/etc/init.d/$NGINX_INIT_NAME" reload || "/etc/init.d/$NGINX_INIT_NAME" start
fi
;;
esac
}
case "$1" in case "$1" in
install) install)
db_get "dokku/web_config" db_get "dokku/web_config"
if [ "$RET" = "true" ]; then if [ "$RET" = "true" ]; then
NGINX_CONF="/etc/nginx/conf.d/dokku-installer.conf" if [[ -x /usr/bin/openresty ]]; then
setup_dokku_installer "/usr/local/openresty/nginx/conf" "openresty"
rm -f $NGINX_CONF else
touch $NGINX_CONF setup_dokku_installer "/etc/nginx" "nginx"
fi
{
echo 'upstream dokku-installer { server 127.0.0.1:2000; }'
echo 'server {'
echo ' listen 80;'
echo ' location / {'
echo ' proxy_pass http://dokku-installer;'
echo ' }'
echo '}'
} >>$NGINX_CONF
rm -f /etc/nginx/sites-enabled/*
DOKKU_DISTRO="$(
. /etc/os-release >/dev/null 2>&1 || true
echo "$ID"
)"
case "$DOKKU_DISTRO" in
debian)
NGINX_INIT="/usr/sbin/invoke-rc.d"
"$NGINX_INIT" nginx reload || "$NGINX_INIT" nginx start
;;
ubuntu)
NGINX_INIT="/etc/init.d/nginx"
"$NGINX_INIT" reload || "$NGINX_INIT" start
;;
esac
exit 0
fi fi
db_get "dokku/skip_key_file" db_get "dokku/skip_key_file"