diff --git a/assets/entrypoint.sh b/assets/entrypoint.sh index ac4f96a..246a19e 100755 --- a/assets/entrypoint.sh +++ b/assets/entrypoint.sh @@ -20,41 +20,6 @@ then echo fi -if [ -z "$PHP_FPM_SERVER" ] -then - PHP_FPM_SERVER=127.0.0.1:9000 -fi - -# Adjust NGINX -if [[ -f /etc/nginx/http.d/default.conf ]] -then - if [ -z "$NGINX_ROOT" ] - then - NGINX_ROOT=/var/www/html - fi - - ${VERBOSE_MODE} && echo "Setting root to '$NGINX_ROOT'" - sed -i "s|^\(\s*root\s*\)@root@;$|\1$NGINX_ROOT;|g" /etc/nginx/http.d/default.conf - ${VERBOSE_MODE} && echo "Setting NGINX fastcgi to '$PHP_FPM_SERVER'" - sed -i "s|@fastcgi@|${PHP_FPM_SERVER}|g" /etc/nginx/http.d/default.conf - - if [[ -n "$PHP_CONTROLLER" ]] - then - ${VERBOSE_MODE} && echo "Setting controller as '$PHP_CONTROLLER'" - sed -i "s|^\(\s*\)#\(try_files.*\)@controller@\(.*\);$|\1\2$PHP_CONTROLLER\3;|g" /etc/nginx/http.d/default.conf - sed -i "s|^\(\s*\)\(index index.php.*\)$|\1#\2|g" /etc/nginx/http.d/default.conf - fi - - if [[ -n "$NGINX_SSL_CERT" ]] - then - ${VERBOSE_MODE} && echo "Setting CERT as '$NGINX_SSL_CERT'" - ${VERBOSE_MODE} && echo "Setting CERT_KEY as '$NGINX_SSL_CERT_KEY'" - sed -i "s|^\(\s*\)#\(listen 443.*\)$|\1\2|g" /etc/nginx/http.d/default.conf - sed -i "s|^\(\s*\)#\(ssl_certificate .*\)@cert@;$|\1\2$NGINX_SSL_CERT;|g" /etc/nginx/http.d/default.conf - sed -i "s|^\(\s*\)#\(ssl_certificate_key .*\)@certkey@;$|\1\2$NGINX_SSL_CERT_KEY;|g" /etc/nginx/http.d/default.conf - fi -fi - # Adjust PHP if [[ -f /usr/bin/php ]] then @@ -62,22 +27,6 @@ then PHPINI=`php -i | grep "Loaded Configuration File" | awk -F" => " '{print $2}'` PHPMODULES=`php -i | grep "Scan this dir" | awk -F" => " '{print $2}'` PHPCUSTOM=/etc/php/conf.d - PHPWWWCONFPATH=$(find /etc -name www.conf 2>/dev/null) - PHPBASECONFPATH=$(find /etc -name base.conf 2>/dev/null) - - # Setting PHP FPM Server - if [ -n "$PHP_FPM_SERVER" ] - then - ${VERBOSE_MODE} && echo "Setting FPM fastcgi to '$PHP_FPM_SERVER'" - if [ -f "$PHPWWWCONFPATH" ] - then - sed -i "s|@fastcgi@|${PHP_FPM_SERVER}|g" $PHPWWWCONFPATH - fi - if [ -f "$PHPBASECONFPATH" ] - then - sed -i "s|@fastcgi@|${PHP_FPM_SERVER}|g" $PHPBASECONFPATH - fi - fi # Disable modules for VAR in `printenv | grep DISABLEMODULE | cut -d= -f1 | cut -d_ -f2- | awk '{print tolower($0)}'` diff --git a/assets/fpm-nginx/conf/nginx.conf b/assets/fpm-nginx/conf/nginx.conf index 42ab7ea..2359b70 100644 --- a/assets/fpm-nginx/conf/nginx.conf +++ b/assets/fpm-nginx/conf/nginx.conf @@ -1,8 +1,5 @@ user nginx; -# Run in foreground -daemon off; - # Set number of worker processes automatically based on number of CPU cores. worker_processes auto; diff --git a/assets/fpm-nginx/conf/supervisord.conf b/assets/fpm-nginx/conf/supervisord.conf index 86a3f92..51059d9 100644 --- a/assets/fpm-nginx/conf/supervisord.conf +++ b/assets/fpm-nginx/conf/supervisord.conf @@ -34,7 +34,7 @@ stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:nginx] -command=/usr/sbin/nginx -g "daemon off;" +command=/start-nginx.sh autostart=true autorestart=false priority=10 diff --git a/assets/script/start-fpm.sh b/assets/script/start-fpm.sh index 31d3baa..d112233 100755 --- a/assets/script/start-fpm.sh +++ b/assets/script/start-fpm.sh @@ -1,21 +1,32 @@ #!/usr/bin/env bash FPMBASE="/etc/$PHP_VARIANT/php-fpm.d/base.conf" +FPMWWW="/etc/$PHP_VARIANT/php-fpm.d/www.conf" FPMENV="/etc/$PHP_VARIANT/php-fpm.d/env.conf" FPMMAIN="/etc/$PHP_VARIANT/php-fpm.conf" -if [ -z "$PHP_FPM_SERVER"]; then - sed -i 's/^\(listen *=\).*/\1 0.0.0.0:9000/g' $FPMBASE +if [ "$VERBOSE" == "true" ] +then + VERBOSE_MODE=true +fi + +if [ -z "$PHP_FPM_SERVER" ] +then + PHP_FPM_SERVER=0.0.0.0:9000 fi +${VERBOSE_MODE} && echo "Setting FPM fastcgi to '$PHP_FPM_SERVER'" +sed -i "s|@fastcgi@|${PHP_FPM_SERVER}|g" $FPMBASE +sed -i "s|@fastcgi@|${PHP_FPM_SERVER}|g" $FPMWWW # Function to update the fpm configuration to make the service environment variables available function setEnvironmentVariable() { if [ -z "$2" ]; then - echo "Environment variable '$1' not set." + ${VERBOSE_MODE} && echo "Environment variable '$1' is empty." return fi + ${VERBOSE_MODE} && echo "$1 = '$2'" # Check whether variable already exists if grep -q $1 "$FPMENV"; then # Reset variable @@ -29,7 +40,7 @@ function setEnvironmentVariable() { # Grep for variables that look like docker set them (_PORT_) if [ -z "$PHP_FPM_IGNORE_ENV"] then - echo "clear_env = no" >> $FPMENV + echo "clear_env = no" > $FPMENV for _curVar in `env | awk -F = '{print $1}'`;do # awk has split them by the equals sign # Pass the name and value to our function @@ -38,7 +49,7 @@ then fi # Log something to the supervisord log so we know this script as run -echo "DONE" +${VERBOSE_MODE} && echo "DONE" # Now start php-fpm $(command -v php-fpm) --nodaemonize --fpm-config "$FPMMAIN" \ No newline at end of file diff --git a/assets/script/start-nginx.sh b/assets/script/start-nginx.sh new file mode 100755 index 0000000..f83cc29 --- /dev/null +++ b/assets/script/start-nginx.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +if [ "$VERBOSE" == "true" ] +then + VERBOSE_MODE=true +fi + +if [ -z "$NGINX_ROOT" ] +then + NGINX_ROOT=/var/www/html +fi + +${VERBOSE_MODE} && echo "Setting root to '$NGINX_ROOT'" +sed -i "s|^\(\s*root\s*\)@root@;$|\1$NGINX_ROOT;|g" /etc/nginx/http.d/default.conf +${VERBOSE_MODE} && echo "Setting NGINX fastcgi to '$PHP_FPM_SERVER'" +sed -i "s|@fastcgi@|${PHP_FPM_SERVER}|g" /etc/nginx/http.d/default.conf + +if [[ -n "$PHP_CONTROLLER" ]] +then + ${VERBOSE_MODE} && echo "Setting controller as '$PHP_CONTROLLER'" + sed -i "s|^\(\s*\)#\(try_files.*\)@controller@\(.*\);$|\1\2$PHP_CONTROLLER\3;|g" /etc/nginx/http.d/default.conf + sed -i "s|^\(\s*\)\(index index.php.*\)$|\1#\2|g" /etc/nginx/http.d/default.conf +fi + +if [[ -n "$NGINX_SSL_CERT" ]] +then + ${VERBOSE_MODE} && echo "Setting CERT as '$NGINX_SSL_CERT'" + ${VERBOSE_MODE} && echo "Setting CERT_KEY as '$NGINX_SSL_CERT_KEY'" + sed -i "s|^\(\s*\)#\(listen 443.*\)$|\1\2|g" /etc/nginx/http.d/default.conf + sed -i "s|^\(\s*\)#\(ssl_certificate .*\)@cert@;$|\1\2$NGINX_SSL_CERT;|g" /etc/nginx/http.d/default.conf + sed -i "s|^\(\s*\)#\(ssl_certificate_key .*\)@certkey@;$|\1\2$NGINX_SSL_CERT_KEY;|g" /etc/nginx/http.d/default.conf +fi + +$(command -v nginx) -g "daemon off;" diff --git a/generator/__init__.py b/generator/__init__.py index 23150cf..632c703 100644 --- a/generator/__init__.py +++ b/generator/__init__.py @@ -148,6 +148,7 @@ def build_fpm_nginx(self, arch): self._run_cli(["buildah", "copy", container, "assets/fpm-nginx/conf/nginx.vh.default.conf", "/etc/nginx/http.d/default.conf"]) self._run_cli(["buildah", "copy", container, "assets/fpm-nginx/conf/supervisord.conf", "/etc/supervisord.conf"]) self._run_cli(["buildah", "copy", container, "assets/script/exit-event-listener.py", "/exit-event-listener.py"]) + self._run_cli(["buildah", "copy", container, "assets/script/start-nginx.sh", "/start-nginx.sh"]) script = self.parse_config("php-fpm-nginx.j2", False) with open(".tmp.sh", "w") as file: file.write(script) @@ -158,10 +159,11 @@ def build_nginx(self, arch): self._banner("nginx") base_image = self.content["image"][arch] if arch in self.content["image"] else self.content["image"]["default"] container = self._from("docker://" + base_image, arch) - self._run_cli(["buildah", "config", "--cmd", "nginx", container]) + self._run_cli(["buildah", "config", "--cmd", "/start-nginx.sh", container]) self._run_cli(["buildah", "config", "--entrypoint", '["/entrypoint.sh"]', container]) self._run_cli(["buildah", "config", "--workingdir", "/srv", container]) self._run_cli(["buildah", "copy", container, "assets/fpm-nginx/conf/nginx.conf", "/etc/nginx/nginx.conf"]) self._run_cli(["buildah", "copy", container, "assets/fpm-nginx/conf/nginx.vh.default.conf", "/etc/nginx/http.d/default.conf"]) + self._run_cli(["buildah", "copy", container, "assets/script/start-nginx.sh", "/start-nginx.sh"]) self._run_cli(["buildah", "copy", container, "assets/entrypoint.sh", "/"]) return self._build(container, "nginx", arch)