mirror of
https://github.com/dokku/dokku.git
synced 2026-02-23 19:50:34 +01:00
feat: implement nginx:start and nginx:stop commands
This commit is contained in:
@@ -8,6 +8,8 @@ nginx:error-logs <app> [-t] # Show the nginx error logs for an appl
|
||||
nginx:report [<app>] [<flag>] # Displays a nginx report for one or more apps
|
||||
nginx:set <app> <property> (<value>) # Set or clear an nginx property for an app
|
||||
nginx:show-config <app> # Display app nginx config
|
||||
nginx:start # Starts the nginx server
|
||||
nginx:stop # Stops the nginx server
|
||||
nginx:validate-config [<app>] [--clean] # Validates and optionally cleans up invalid nginx configurations
|
||||
```
|
||||
|
||||
@@ -17,7 +19,23 @@ nginx:validate-config [<app>] [--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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -32,6 +32,8 @@ fn-help-content() {
|
||||
nginx:report [<app>] [<flag>], Displays an nginx report for one or more apps
|
||||
nginx:set <app> <property> (<value>), Set or clear an nginx property for an app
|
||||
nginx:show-config <app>, Display app nginx config
|
||||
nginx:start, Starts the nginx server
|
||||
nginx:stop, Stops the nginx server
|
||||
nginx:validate-config [<app>] [--clean], Validates and optionally cleans up invalid nginx configurations
|
||||
help_content
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
6
plugins/nginx-vhosts/subcommands/start
Executable file
6
plugins/nginx-vhosts/subcommands/start
Executable file
@@ -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 "$@"
|
||||
6
plugins/nginx-vhosts/subcommands/stop
Executable file
6
plugins/nginx-vhosts/subcommands/stop
Executable file
@@ -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 "$@"
|
||||
Reference in New Issue
Block a user