diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py index e7e27f784..741ce51d3 100755 --- a/contrib/dokku-installer.py +++ b/contrib/dokku-installer.py @@ -47,12 +47,23 @@ except subprocess.CalledProcessError: 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(): if 'onboot' not in sys.argv: return init_dir = os.getenv('INIT_DIR', '/etc/init') 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): 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") - 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) @@ -203,7 +214,7 @@ class DeleteInstallerThread(object): thread.start() 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: subprocess.call(command, shell=True) except: diff --git a/debian/postinst b/debian/postinst index 43c659402..de453d037 100755 --- a/debian/postinst +++ b/debian/postinst @@ -89,7 +89,10 @@ setup-sshcommand() { } 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" /usr/share/dokku/contrib/dokku-installer.py onboot diff --git a/debian/postrm b/debian/postrm index b37c0578d..f58c4869a 100755 --- a/debian/postrm +++ b/debian/postrm @@ -28,6 +28,8 @@ main() { fi 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-installer.conf rm -f ${DOKKU_ROOT}/.dokkurc ${DOKKU_ROOT}/dokkurc ${DOKKU_ROOT}/tls diff --git a/debian/preinst b/debian/preinst index c9a055344..3baaba9aa 100755 --- a/debian/preinst +++ b/debian/preinst @@ -7,41 +7,53 @@ if [[ -e /usr/share/debconf/confmodule ]]; then . /usr/share/debconf/confmodule 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 install) db_get "dokku/web_config" if [ "$RET" = "true" ]; then - NGINX_CONF="/etc/nginx/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 /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 + if [[ -x /usr/bin/openresty ]]; then + setup_dokku_installer "/usr/local/openresty/nginx/conf" "openresty" + else + setup_dokku_installer "/etc/nginx" "nginx" + fi fi db_get "dokku/skip_key_file"