From 3bc9a9ff4a80a91d6ba6ee0eb6d4586ce1568ec9 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Tue, 22 Mar 2022 16:24:00 +0100 Subject: [PATCH] __php_fpm{,_pool}: initial implementation. --- type/__php_fpm/files/php.ini.sh | 45 +++++++++++ type/__php_fpm/man.rst | 75 ++++++++++++++++++ type/__php_fpm/manifest | 47 +++++++++++ type/__php_fpm/parameter/boolean | 2 + type/__php_fpm/parameter/default/memory-limit | 1 + .../parameter/default/upload-max-filesize | 1 + type/__php_fpm/parameter/optional | 2 + type/__php_fpm/parameter/required | 1 + type/__php_fpm/singleton | 0 type/__php_fpm_pool/files/www.conf.sh | 34 ++++++++ type/__php_fpm_pool/man.rst | 79 +++++++++++++++++++ type/__php_fpm_pool/manifest | 37 +++++++++ type/__php_fpm_pool/parameter/optional | 2 + type/__php_fpm_pool/parameter/required | 5 ++ 14 files changed, 331 insertions(+) create mode 100755 type/__php_fpm/files/php.ini.sh create mode 100644 type/__php_fpm/man.rst create mode 100644 type/__php_fpm/manifest create mode 100644 type/__php_fpm/parameter/boolean create mode 100644 type/__php_fpm/parameter/default/memory-limit create mode 100644 type/__php_fpm/parameter/default/upload-max-filesize create mode 100644 type/__php_fpm/parameter/optional create mode 100644 type/__php_fpm/parameter/required create mode 100644 type/__php_fpm/singleton create mode 100755 type/__php_fpm_pool/files/www.conf.sh create mode 100644 type/__php_fpm_pool/man.rst create mode 100644 type/__php_fpm_pool/manifest create mode 100644 type/__php_fpm_pool/parameter/optional create mode 100644 type/__php_fpm_pool/parameter/required diff --git a/type/__php_fpm/files/php.ini.sh b/type/__php_fpm/files/php.ini.sh new file mode 100755 index 0000000..8fbc4ac --- /dev/null +++ b/type/__php_fpm/files/php.ini.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +cat < + + +COPYING +------- +Copyright \(C) 2022 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__php_fpm/manifest b/type/__php_fpm/manifest new file mode 100644 index 0000000..84c4383 --- /dev/null +++ b/type/__php_fpm/manifest @@ -0,0 +1,47 @@ +#!/bin/sh + +os=$(cat "${__global:?}/explorer/os") + +PHPVER=$(cat "${__object:?}/parameter/php-version") +export PHPVER + +case "$os" in +'alpine') + package="php${PHPVER}-fpm" + service="php-fpm${PHPVER}" + opcache_package="php${PHPVER}-opcache" + apcu_package="php${PHPVER}-pecl-apcu" + ;; + +*) + printf "Your operating system is currently not supported by this type\n" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +__package "$package" +require="__package/$package" __start_on_boot "$service" + +if [ -f "${__object:?}/parameter/enable-opcache" ]; then + __package "$opcache_package" +fi + +if [ -f "${__object:?}/parameter/enable-apcu" ]; then + __package "$apcu_package" +fi + +MEMORY_LIMIT=$(cat "${__object:?}/parameter/memory-limit") +export MEMORY_LIMIT + +UPLOAD_MAX_FILESIZE=$(cat "${__object:?}/parameter/upload-max-filesize") +export UPLOAD_MAX_FILESIZE + +mkdir -p "${__object:?}/files" +"${__type:?}/files/php.ini.sh" >"${__object:?}/files/php.ini" + +require="__package/$package" __file "/etc/php${PHPVER}/php.ini" \ + --mode 644 --source "${__object:?}/files/php.ini" \ + --onchange "service $service restart" + +require="__file/etc/php${PHPVER}/php.ini" __service "$service" --action start diff --git a/type/__php_fpm/parameter/boolean b/type/__php_fpm/parameter/boolean new file mode 100644 index 0000000..9964486 --- /dev/null +++ b/type/__php_fpm/parameter/boolean @@ -0,0 +1,2 @@ +enable-opcache +enable-apcu diff --git a/type/__php_fpm/parameter/default/memory-limit b/type/__php_fpm/parameter/default/memory-limit new file mode 100644 index 0000000..d95fe12 --- /dev/null +++ b/type/__php_fpm/parameter/default/memory-limit @@ -0,0 +1 @@ +512M diff --git a/type/__php_fpm/parameter/default/upload-max-filesize b/type/__php_fpm/parameter/default/upload-max-filesize new file mode 100644 index 0000000..5fbcf1c --- /dev/null +++ b/type/__php_fpm/parameter/default/upload-max-filesize @@ -0,0 +1 @@ +2M diff --git a/type/__php_fpm/parameter/optional b/type/__php_fpm/parameter/optional new file mode 100644 index 0000000..a41a87c --- /dev/null +++ b/type/__php_fpm/parameter/optional @@ -0,0 +1,2 @@ +upload-max-filesize +memory-limit diff --git a/type/__php_fpm/parameter/required b/type/__php_fpm/parameter/required new file mode 100644 index 0000000..173609d --- /dev/null +++ b/type/__php_fpm/parameter/required @@ -0,0 +1 @@ +php-version diff --git a/type/__php_fpm/singleton b/type/__php_fpm/singleton new file mode 100644 index 0000000..e69de29 diff --git a/type/__php_fpm_pool/files/www.conf.sh b/type/__php_fpm_pool/files/www.conf.sh new file mode 100755 index 0000000..aa8fa7c --- /dev/null +++ b/type/__php_fpm_pool/files/www.conf.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +cat < + + +COPYING +------- +Copyright \(C) 2022 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__php_fpm_pool/manifest b/type/__php_fpm_pool/manifest new file mode 100644 index 0000000..b090c9d --- /dev/null +++ b/type/__php_fpm_pool/manifest @@ -0,0 +1,37 @@ +#!/bin/sh + +# XXX: this type does not configure or install php-fpm: it expects the +# __recycledcloud_php_fpm type to be used first before pools are configured. + +os=$(cat "${__global:?}/explorer/os") +name=${__object_id:?} + +PHPVER=$(cat "${__object:?}/parameter/php-version") +export PHPVER + +case "$os" in +'alpine') + service="php-fpm${PHPVER}" + : + ;; + +*) + printf "Your operating system is currently not supported by this type\n" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + +POOL_NAME="$name" +POOL_USER=$(cat "${__object:?}/parameter/pool-user") +POOL_GROUP=$(cat "${__object:?}/parameter/pool-group") +POOL_LISTEN_ADDR=$(cat "${__object:?}/parameter/pool-listen-addr") +POOL_LISTEN_OWNER=$(cat "${__object:?}/parameter/pool-listen-owner") +export POOL_USER POOL_GROUP POOL_LISTEN_ADDR POOL_LISTEN_OWNER POOL_NAME + +mkdir -p "${__object:?}/files" +"${__type:?}/files/www.conf.sh" >"${__object:?}/files/www.conf" + +__file "/etc/php${PHPVER:?}/php-fpm.d/${name}.conf" \ + --mode 644 --source "${__object:?}/files/www.conf" \ + --onchange "service $service reload" diff --git a/type/__php_fpm_pool/parameter/optional b/type/__php_fpm_pool/parameter/optional new file mode 100644 index 0000000..7adc0a3 --- /dev/null +++ b/type/__php_fpm_pool/parameter/optional @@ -0,0 +1,2 @@ +memory-limit +open-basedir diff --git a/type/__php_fpm_pool/parameter/required b/type/__php_fpm_pool/parameter/required new file mode 100644 index 0000000..d247290 --- /dev/null +++ b/type/__php_fpm_pool/parameter/required @@ -0,0 +1,5 @@ +php-version +pool-user +pool-group +pool-listen-addr +pool-listen-owner