6
0
Fork 0

Rewrite wordpress / php types to support multiple instances

This commit is contained in:
Timothée Floure 2021-10-26 11:09:15 +02:00
parent 1afe5837de
commit 4dd5960dbc
Signed by: tfloure
GPG key ID: 4502C902C00A1E12
16 changed files with 126 additions and 43 deletions

View file

@ -24,24 +24,12 @@ if [ -f "${__object:?}/parameter/enable-opcache" ]; then
__package "$opcache_package" __package "$opcache_package"
fi fi
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
UPLOAD_MAX_FILESIZE=$(cat "${__object:?}/parameter/upload-max-filesize") UPLOAD_MAX_FILESIZE=$(cat "${__object:?}/parameter/upload-max-filesize")
export UPLOAD_MAX_FILESIZE export UPLOAD_MAX_FILESIZE
mkdir -p "${__object:?}/files" mkdir -p "${__object:?}/files"
"${__type:?}/files/www.conf.sh" > "${__object:?}/files/www.conf"
"${__type:?}/files/php.ini.sh" > "${__object:?}/files/php.ini" "${__type:?}/files/php.ini.sh" > "${__object:?}/files/php.ini"
require="__package/$package" __file /etc/php7/php.ini\ require="__package/$package" __file /etc/php7/php.ini\
--mode 644 --source "${__object:?}/files/php.ini" \ --mode 644 --source "${__object:?}/files/php.ini" \
--onchange "service $service restart" --onchange "service $service restart"
require="__package/$package" __file /etc/php7/php-fpm.d/www.conf \
--mode 644 --source "${__object:?}/files/www.conf" \
--onchange "service $service restart"

View file

@ -1,2 +1 @@
memory-limit
upload-max-filesize upload-max-filesize

View file

@ -4,7 +4,7 @@ cat << EOF
; Start a new pool named 'www'. ; Start a new pool named 'www'.
; the variable \$pool can be used in any directive and will be replaced by the ; the variable \$pool can be used in any directive and will be replaced by the
; pool name ('www' here) ; pool name ('www' here)
[www] [$POOL_NAME]
; Per pool prefix ; Per pool prefix
; It only applies on the following directives: ; It only applies on the following directives:
@ -439,8 +439,13 @@ env[TEMP] = /tmp
;php_admin_value[error_log] = /var/log/php7/\$pool.error.log ;php_admin_value[error_log] = /var/log/php7/\$pool.error.log
;php_admin_flag[log_errors] = on ;php_admin_flag[log_errors] = on
EOF EOF
if [ -f "${__object:?}/parameter/memory-limit" ]; then if [ -f "${__object:?}/parameter/memory-limit" ]; then
echo "php_admin_value[memory_limit] = $(cat "$__object/parameter/memory-limit")" echo "php_admin_value[memory_limit] = $(cat "$__object/parameter/memory-limit")"
else else
echo ";php_admin_value[memory_limit] = 32M" echo ";php_admin_value[memory_limit] = 32M"
fi fi
if [ -f "${__object:?}/parameter/open-basedir" ]; then
echo "php_admin_value[open_basedir] = $(cat "${__object:?}/parameter/open-basedir")"
fi

View file

@ -0,0 +1,35 @@
#!/bin/sh
os=$(cat "${__global:?}/explorer/os")
name=${__object_id:?}
case "$os" in
'alpine')
package="php7-fpm"
service="php-fpm7"
;;
*)
printf "Your operating system (%s) is currently not supported by this type\n" "$os" >&2
printf "Please contribute an implementation for it if you can.\n" >&2
exit 1
;;
esac
__package "$package"
require="__package/$package" __service "$service" --action start
require="__package/$package" __start_on_boot "$service"
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"
require="__package/$package" __file "/etc/php7/php-fpm.d/$name.conf" \
--mode 644 --source "${__object:?}/files/www.conf" \
--onchange "service $service reload"

View file

@ -0,0 +1,2 @@
memory-limit
open-basedir

View file

@ -1,13 +1,44 @@
#!/bin/sh #!/bin/sh
archive=wordpress.tar.gz instance="${__object_id:?}"
user="$instance"
group="$instance"
install_dir="/var/www/$instance"
wp_cli=/usr/local/bin/wp
mysql_database=$instance
if [ -f "${__object:?}/parameter/mysql-database" ]; then
mysql_database=$(cat "${__object:?}/parameter/mysql-database")
fi
mysql_user=$instance
if [ -f "${__object:?}/parameter/mysql-user" ]; then
mysql_user=$(cat "${__object:?}/parameter/mysql-user")
fi
mysql_password="$(cat "${__object:?}/parameter/mysql-password")"
domain="$(cat "${__object:?}/parameter/domain")"
url="https://$domain/"
admin_username="$(cat "${__object:?}/parameter/admin-username")"
admin_password="$(cat "${__object:?}/parameter/admin-password")"
admin_email="$(cat "${__object:?}/parameter/admin-email")"
cat << EOF cat << EOF
if [ ! -f /var/www/wordpress ]; then if [ ! -d "$install_dir" ]; then
cd /var/www mkdir -p "$install_dir"
curl https://wordpress.org/latest.tar.gz -o $archive chown -R $user:$group "$install_dir"
tar xf $archive cd "$install_dir"
rm $archive sudo -u $user $wp_cli core download
chown -R wordpress:wordpress wordpress sudo -u $user $wp_cli config create \
--dbname="$mysql_database" \
--dbuser="$mysql_user" \
--dbpass="$mysql_password"
sudo -u $user $wp_cli core install \
--url="$url" \
--title="$instance" \
--admin_user="$admin_username" \
--admin_password="$admin_password" \
--admin_email="$admin_email"
fi fi
EOF EOF

View file

@ -1,36 +1,46 @@
#!/bin/sh #!/bin/sh
# TODO: set max upload size in PHP configuration (php.ini).
os=$(cat "${__global:?}/explorer/os") os=$(cat "${__global:?}/explorer/os")
instance="${__object_id:?}"
user=$instance
group=$user
if [ "$os" != "alpine" ]; then if [ "$os" != "alpine" ]; then
echo "This type is expected to run on Alpine Linux, not $os. Exiting." >&2 echo "This type is expected to run on Alpine Linux, not $os. Exiting." >&2
exit 1 exit 1
fi fi
# Type parameters. # Type parameters.
mysql_password="$(cat "${__object:?}/parameter/mysql-password")" nginx_domain="$(cat "${__object:?}/parameter/domain")"
nginx_domain="$(cat "${__object:?}/parameter/nginx-domain")"
altdomains= altdomains=
while read -r altdomain; if [ -f "${__object:?}/parameter/altdomains" ]; then
do while read -r altdomain;
do
altdomains="--altdomain $altdomain $altdomains" altdomains="--altdomain $altdomain $altdomains"
done < "${__object:?}/parameter/altdomains" done < "${__object:?}/parameter/altdomains"
fi
max_upload_size=100M max_upload_size=100M
php_fpm_socket=/run/php-fpm7/php-fpm.sock php_fpm_socket="/run/php-fpm7/php-fpm-$instance.sock"
# Wordpress user. # Wordpress CLI management tool.
__user wordpress --home /var/www/wordpress __wp_cli
# Wordpress user & group.
homedir="/var/www/$instance"
__user "$user" --home "$homedir"
# Basic PHP FPM setup + Wordpress dependencies. # Basic PHP FPM setup + Wordpress dependencies.
require="__user/wordpress" __recycledcloud_php \ __recycledcloud_php_fpm \
--pool-user wordpress \ --upload-max-filesize $max_upload_size \
--pool-group wordpress \ --enable-opcache
--pool-listen-addr $php_fpm_socket \ require="__user/$user __recycledcloud_php_fpm" __recycledcloud_php_fpm_pool "$instance" \
--pool-user "$user" \
--pool-group "$group" \
--pool-listen-addr "$php_fpm_socket" \
--pool-listen-owner nginx \ --pool-listen-owner nginx \
--upload-max-filesize $max_upload_size --memory-limit 128M \
--open-basedir "/var/www/$instance:/tmp"
wordpress_dependencies="php7-fpm php7-iconv php7-json php7-gd php7-curl \ wordpress_dependencies="php7-fpm php7-iconv php7-json php7-gd php7-curl \
php7-xml php7-mysqli php7-imap php7-cgi php7-pdo php7-pdo_mysql php7-soap \ php7-xml php7-mysqli php7-imap php7-cgi php7-pdo php7-pdo_mysql php7-soap \
@ -42,17 +52,23 @@ do
__package "$dependency" __package "$dependency"
done done
# MySQL/MariaDB database # Daily database backup/export.
__recycledcloud_mysql require="__user/$user" __cron "$instance-db-export" \
require="__recycledcloud_mysql" __mysql_database wordpress \ --user "$user" \
--user wordpress --password "$mysql_password" --command "/usr/local/bin/wp db export" \
--minute 0 \
--hour 2
require="__user/$user" __cron "$instance-db-export-cleanup" \
--user "$user" \
--command "find *.sql -maxdepth 1 -mtime +5 -delete"
# NGINX vhost for wordpress hosting. # NGINX vhost for wordpress hosting.
# shellcheck disable=SC2086 # shellcheck disable=SC2086
__nginx "$nginx_domain" \ __nginx "$nginx_domain" \
$altdomains \ $altdomains \
--config - <<- EOF --config - <<- EOF
root /var/www/wordpress; root "$homedir";
index index.php; index index.php;
client_max_body_size $max_upload_size; client_max_body_size $max_upload_size;

View file

@ -0,0 +1 @@
admin

View file

@ -1 +1,4 @@
altdomains altdomains
mysql-user
mysql-databse
admin-username

View file

@ -1,2 +1,5 @@
nginx-domain domain
mysql-password mysql-password
admin-password
admin-email