From b75c0eb4fb44a0da7c9433f3f7b04c88404194bd Mon Sep 17 00:00:00 2001 From: cytopia Date: Sun, 8 Jan 2023 21:23:32 +0100 Subject: [PATCH] Allow to use supervisorctl to be able to reload PHP configuration without restarting --- .ansible/DOCKERFILES/Dockerfile-prod.j2 | 1 - CHANGELOG.md | 6 ++ Dockerfiles/prod/Dockerfile-5.2 | 1 - Dockerfiles/prod/Dockerfile-5.3 | 1 - Dockerfiles/prod/Dockerfile-5.4 | 1 - Dockerfiles/prod/Dockerfile-5.5 | 1 - Dockerfiles/prod/Dockerfile-5.6 | 1 - Dockerfiles/prod/Dockerfile-7.0 | 1 - Dockerfiles/prod/Dockerfile-7.1 | 1 - Dockerfiles/prod/Dockerfile-7.2 | 1 - Dockerfiles/prod/Dockerfile-7.3 | 1 - Dockerfiles/prod/Dockerfile-7.4 | 1 - Dockerfiles/prod/Dockerfile-8.0 | 1 - Dockerfiles/prod/Dockerfile-8.1 | 1 - Dockerfiles/prod/Dockerfile-8.2 | 1 - .../docker-entrypoint.d/304-supervisor.sh | 68 +++++++++++++++++++ Dockerfiles/prod/data/docker-entrypoint.sh | 7 +- Dockerfiles/prod/data/supervisord.conf | 9 --- Dockerfiles/slim/data/docker-entrypoint.sh | 8 ++- 19 files changed, 87 insertions(+), 25 deletions(-) delete mode 100644 Dockerfiles/prod/data/supervisord.conf diff --git a/.ansible/DOCKERFILES/Dockerfile-prod.j2 b/.ansible/DOCKERFILES/Dockerfile-prod.j2 index d3686c7f..f1fff220 100644 --- a/.ansible/DOCKERFILES/Dockerfile-prod.j2 +++ b/.ansible/DOCKERFILES/Dockerfile-prod.j2 @@ -81,7 +81,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/CHANGELOG.md b/CHANGELOG.md index 4840ab85..37814540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ ## Unreleased +## Release 0.151 + +### Added +- Allow to use supervisorctl to be able to reload PHP configuration without restarting + + ## Release 0.150 ### Added diff --git a/Dockerfiles/prod/Dockerfile-5.2 b/Dockerfiles/prod/Dockerfile-5.2 index 80a8d208..15546d97 100644 --- a/Dockerfiles/prod/Dockerfile-5.2 +++ b/Dockerfiles/prod/Dockerfile-5.2 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-5.3 b/Dockerfiles/prod/Dockerfile-5.3 index c3f002d4..40e8637c 100644 --- a/Dockerfiles/prod/Dockerfile-5.3 +++ b/Dockerfiles/prod/Dockerfile-5.3 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-5.4 b/Dockerfiles/prod/Dockerfile-5.4 index 27a8a9b2..6d19831b 100644 --- a/Dockerfiles/prod/Dockerfile-5.4 +++ b/Dockerfiles/prod/Dockerfile-5.4 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-5.5 b/Dockerfiles/prod/Dockerfile-5.5 index 882eef2c..bf69a288 100644 --- a/Dockerfiles/prod/Dockerfile-5.5 +++ b/Dockerfiles/prod/Dockerfile-5.5 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-5.6 b/Dockerfiles/prod/Dockerfile-5.6 index 67a61afe..7026b2ba 100644 --- a/Dockerfiles/prod/Dockerfile-5.6 +++ b/Dockerfiles/prod/Dockerfile-5.6 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-7.0 b/Dockerfiles/prod/Dockerfile-7.0 index 5ca6f8dd..f8cde560 100644 --- a/Dockerfiles/prod/Dockerfile-7.0 +++ b/Dockerfiles/prod/Dockerfile-7.0 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-7.1 b/Dockerfiles/prod/Dockerfile-7.1 index 1f030539..49b6c3ef 100644 --- a/Dockerfiles/prod/Dockerfile-7.1 +++ b/Dockerfiles/prod/Dockerfile-7.1 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-7.2 b/Dockerfiles/prod/Dockerfile-7.2 index 5ad6e11b..6d5f75d9 100644 --- a/Dockerfiles/prod/Dockerfile-7.2 +++ b/Dockerfiles/prod/Dockerfile-7.2 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-7.3 b/Dockerfiles/prod/Dockerfile-7.3 index f5ac19c1..57a71421 100644 --- a/Dockerfiles/prod/Dockerfile-7.3 +++ b/Dockerfiles/prod/Dockerfile-7.3 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-7.4 b/Dockerfiles/prod/Dockerfile-7.4 index a2cf0c0c..62dc6370 100644 --- a/Dockerfiles/prod/Dockerfile-7.4 +++ b/Dockerfiles/prod/Dockerfile-7.4 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-8.0 b/Dockerfiles/prod/Dockerfile-8.0 index b91e5588..08d378d9 100644 --- a/Dockerfiles/prod/Dockerfile-8.0 +++ b/Dockerfiles/prod/Dockerfile-8.0 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-8.1 b/Dockerfiles/prod/Dockerfile-8.1 index 1fb96812..d7c86fca 100644 --- a/Dockerfiles/prod/Dockerfile-8.1 +++ b/Dockerfiles/prod/Dockerfile-8.1 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/Dockerfile-8.2 b/Dockerfiles/prod/Dockerfile-8.2 index 9ecb8838..62e520c1 100644 --- a/Dockerfiles/prod/Dockerfile-8.2 +++ b/Dockerfiles/prod/Dockerfile-8.2 @@ -79,7 +79,6 @@ RUN set -eux \ COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh COPY ./data/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY ./data/postfix.sh /usr/local/sbin/postfix.sh -COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf ### diff --git a/Dockerfiles/prod/data/docker-entrypoint.d/304-supervisor.sh b/Dockerfiles/prod/data/docker-entrypoint.d/304-supervisor.sh index 8a66e32d..d2abf6ae 100755 --- a/Dockerfiles/prod/data/docker-entrypoint.d/304-supervisor.sh +++ b/Dockerfiles/prod/data/docker-entrypoint.d/304-supervisor.sh @@ -9,6 +9,51 @@ set -o pipefail # Functions ############################################################ +### +### Create main supvervisord configuration file +### +supervisor_create_config() { + local path="${1}" + + # Enable supervisorctl (default: disabled) + SVCTL_ENABLE="${SVCTL_ENABLE:-0}" + if [ -z "${SVCTL_USER:-}" ]; then + SVCTL_USER="$( get_random_alphanum "10" )" + fi + if [ -z "${SVCTL_PASS:-}" ]; then + SVCTL_PASS="$( get_random_alphanum "10" )" + fi + + { + # Use 'echo_supervisord_conf' to generate an example config + if [ "${SVCTL_ENABLE}" = "1" ]; then + echo "[rpcinterface:supervisor]" + echo "supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface" + echo + echo "[unix_http_server]" + echo "file = /tmp/supervisor.sock" + echo "chmod = 0700" + echo + echo "[supervisorctl]" + echo "serverurl = unix:///tmp/supervisor.sock" + echo "username = ${SVCTL_USER} ; should be same as in [*_http_server] if set" + echo "password = ${SVCTL_PASS} ; should be same as in [*_http_server] if set" + fi + echo "[supervisord]" + echo "user = root" + echo "nodaemon = true" + echo "loglevel = info" + echo "logfile = /var/log/supervisor/supervisord.log" + echo "pidfile = /var/run/supervisord.pid" + echo "childlogdir = /var/log/supervisor" + echo "strip_ansi = true" # Required to fix tail logs + echo + echo "[include]" + echo "files = /etc/supervisor/conf.d/*.conf /etc/supervisor/custom.d/*.conf" + } > "${path}" +} + + ### ### Add service to supervisord ### @@ -49,3 +94,26 @@ supervisor_add_service() { echo "stderr_events_enabled = true"; } > "${confd}/${name}.conf" } + + +### +### Get Random alphanumeric string +### +get_random_alphanum() { + local len="${1:-15}" # length defaults to 15 + tr -dc A-Za-z0-9 < /dev/urandom | head -c "${len}" | xargs || true +} + + +############################################################ +# Sanity Checks +############################################################ + +if ! command -v tr >/dev/null 2>&1; then + echo "tr not found, but required." + exit 1 +fi +if ! command -v xargs >/dev/null 2>&1; then + echo "xargs not found, but required." + exit 1 +fi diff --git a/Dockerfiles/prod/data/docker-entrypoint.sh b/Dockerfiles/prod/data/docker-entrypoint.sh index 01e10e7a..fcd60c0a 100755 --- a/Dockerfiles/prod/data/docker-entrypoint.sh +++ b/Dockerfiles/prod/data/docker-entrypoint.sh @@ -120,6 +120,12 @@ if ! port_forward_validate "FORWARD_PORTS_TO_LOCALHOST" "${DEBUG_LEVEL}"; then fi +### +### Supvervisor: supervisord.conf +### +supervisor_create_config "/etc/supervisor/supervisord.conf" + + ### ### Supervisor: socat ### @@ -185,7 +191,6 @@ execute_custom_scripts "/startup.1.d" "${DEBUG_LEVEL}" execute_custom_scripts "/startup.2.d" "${DEBUG_LEVEL}" -### ### ### Startup ### diff --git a/Dockerfiles/prod/data/supervisord.conf b/Dockerfiles/prod/data/supervisord.conf deleted file mode 100644 index 1afe1497..00000000 --- a/Dockerfiles/prod/data/supervisord.conf +++ /dev/null @@ -1,9 +0,0 @@ -[supervisord] -user = root -nodaemon = true -logfile = /var/log/supervisor/supervisord.log -pidfile = /var/run/supervisord.pid -childlogdir = /var/log/supervisor - -[include] -files = /etc/supervisor/conf.d/*.conf /etc/supervisor/custom.d/*.conf diff --git a/Dockerfiles/slim/data/docker-entrypoint.sh b/Dockerfiles/slim/data/docker-entrypoint.sh index d1ef1c60..9b78361e 100755 --- a/Dockerfiles/slim/data/docker-entrypoint.sh +++ b/Dockerfiles/slim/data/docker-entrypoint.sh @@ -120,6 +120,12 @@ if ! port_forward_validate "FORWARD_PORTS_TO_LOCALHOST" "${DEBUG_LEVEL}"; then fi +### +### Supvervisor: supervisord.conf +### +supervisor_create_config "/etc/supervisor/supervisord.conf" + + ### ### Supervisor: socat ### @@ -162,7 +168,7 @@ copy_ini_files "${DVL_PHP_CUST_INI_DIR}" "${DVL_PHP_INI_DIR}" "${DEBUG_LEVEL}" if [ "${PHP_VERSION}" = "5.2" ]; then copy_fpm_5_2_conf_file "${DVL_PHP_CUST_FPM_DIR}/php-fpm.xml" "${DEBUG_LEVEL}" else -copy_fpm_files "${DVL_PHP_CUST_FPM_DIR}" "${DVL_PHP_FPM_DIR}" "${DEBUG_LEVEL}" + copy_fpm_files "${DVL_PHP_CUST_FPM_DIR}" "${DVL_PHP_FPM_DIR}" "${DEBUG_LEVEL}" fi