diff --git a/docs/networking/proxies/nginx.md b/docs/networking/proxies/nginx.md index 57fb1aab1..f3dcfe722 100644 --- a/docs/networking/proxies/nginx.md +++ b/docs/networking/proxies/nginx.md @@ -8,6 +8,8 @@ nginx:error-logs [-t] # Show the nginx error logs for an appl nginx:report [] [] # Displays a nginx report for one or more apps nginx:set () # Set or clear an nginx property for an app nginx:show-config # Display app nginx config +nginx:start # Starts the nginx server +nginx:stop # Stops the nginx server nginx:validate-config [] [--clean] # Validates and optionally cleans up invalid nginx configurations ``` @@ -17,7 +19,23 @@ nginx:validate-config [] [--clean] # Validates and optionally cleans up in By default, the `web` process is the only process proxied by the nginx proxy implementation. Proxying to other process types may be handled by a custom `nginx.conf.sigil` file, as generally described [below](/docs/networking/proxies/nginx.md#customizing-the-nginx-configuration) -Nginx will proxy the requests in a [round-robin balancing fashion](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream) to the different deployed (scaled) containers running the `web` proctype. This way, the host's resources can be fully leveraged for single-threaded applications (e.g. `dokku ps:scale node-js-app web=4` on a 4-core machine) +Nginx will proxy the requests in a [round-robin balancing fashion](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream) to the different deployed (scaled) containers running the `web` proctype. This way, the host's resources can be fully leveraged for single-threaded applications (e.g. `dokku ps:scale node-js-app web=4` on a 4-core machine). + +### Starting nginx + +The nginx server can be started via `nginx:start`. + +```shell +dokku nginx:start +```` + +### Stopping nginx + +The nginx server can be stopped via `nginx:stop`. + +```shell +dokku nginx:stop +```` ### Binding to specific addresses diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index 71f0a9d61..2a5d8530a 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -107,6 +107,24 @@ cmd-nginx-show-config() { cat "$DOKKU_ROOT/$APP/nginx.conf" } +cmd-nginx-stop() { + declare desc="stops the nginx server" + declare cmd="nginx:stop" + [[ "$1" == "$cmd" ]] && shift 1 + + touch "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" + fn-nginx-vhosts-nginx-init-cmd "stop" +} + +cmd-nginx-start() { + declare desc="starts the nginx server" + declare cmd="nginx:start" + [[ "$1" == "$cmd" ]] && shift 1 + + rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" + fn-nginx-vhosts-nginx-init-cmd "start" +} + cmd-nginx-validate-config() { declare desc="validates and optionally cleans up invalid nginx configurations" declare cmd="nginx:validate-config" diff --git a/plugins/nginx-vhosts/help-functions b/plugins/nginx-vhosts/help-functions index f34f32b02..53219a912 100755 --- a/plugins/nginx-vhosts/help-functions +++ b/plugins/nginx-vhosts/help-functions @@ -32,6 +32,8 @@ fn-help-content() { nginx:report [] [], Displays an nginx report for one or more apps nginx:set (), Set or clear an nginx property for an app nginx:show-config , Display app nginx config + nginx:start, Starts the nginx server + nginx:stop, Stops the nginx server nginx:validate-config [] [--clean], Validates and optionally cleans up invalid nginx configurations help_content } diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 8893d92b2..7c8f6b518 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -27,19 +27,19 @@ trigger-nginx-vhosts-install() { local mode="0440" case "$DOKKU_DISTRO" in debian | raspbian) - echo "%dokku ALL=(ALL) NOPASSWD:/usr/sbin/invoke-rc.d $NGINX_INIT_NAME reload, $NGINX_BIN -t, ${NGINX_BIN} -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/usr/sbin/invoke-rc.d $NGINX_INIT_NAME reload, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME start, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME stop, $NGINX_BIN -t, ${NGINX_BIN} -t -c *" >"$NGINX_SUDOERS_FILE" ;; ubuntu) if [[ -x /usr/bin/sv ]]; then - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/sv reload $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/sv reload $NGINX_INIT_NAME, /usr/bin/sv start $NGINX_INIT_NAME, /usr/bin/sv stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" else - echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/$NGINX_INIT_NAME reload, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/$NGINX_INIT_NAME reload, /etc/init.d/$NGINX_INIT_NAME start, /etc/init.d/$NGINX_INIT_NAME stop, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" fi ;; arch) - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload $NGINX_INIT_NAME, /usr/bin/systemctl start $NGINX_INIT_NAME, /usr/bin/systemctl stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" ;; esac @@ -76,6 +76,7 @@ trigger-nginx-vhosts-install() { # Create nginx error templates mkdir -p "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors" + chown -R "${DOKKU_SYSTEM_USER}:${DOKKU_SYSTEM_GROUP}" "${DOKKU_LIB_ROOT}/data/nginx-vhosts" cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/400-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/400-error.html" cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/404-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/404-error.html" cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/500-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/500-error.html" @@ -108,7 +109,7 @@ trigger-nginx-vhosts-install() { # avoid failing runit init calls on install # the runit binaries are not yet available during dockerfile building # and therefore both these calls will fail - if [[ ! -x /usr/bin/sv ]]; then + if [[ ! -x /usr/bin/sv ]] && [[ ! -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" ]]; then fn-nginx-vhosts-nginx-init-cmd start || fn-nginx-vhosts-nginx-init-cmd reload fi } diff --git a/plugins/nginx-vhosts/subcommands/start b/plugins/nginx-vhosts/subcommands/start new file mode 100755 index 000000000..cb5a854c1 --- /dev/null +++ b/plugins/nginx-vhosts/subcommands/start @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-nginx-start "$@" diff --git a/plugins/nginx-vhosts/subcommands/stop b/plugins/nginx-vhosts/subcommands/stop new file mode 100755 index 000000000..c11428491 --- /dev/null +++ b/plugins/nginx-vhosts/subcommands/stop @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-nginx-stop "$@"