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"
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")
export UPLOAD_MAX_FILESIZE
mkdir -p "${__object:?}/files"
"${__type:?}/files/www.conf.sh" > "${__object:?}/files/www.conf"
"${__type:?}/files/php.ini.sh" > "${__object:?}/files/php.ini"
require="__package/$package" __file /etc/php7/php.ini\
--mode 644 --source "${__object:?}/files/php.ini" \
--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

@ -4,7 +4,7 @@ cat << EOF
; Start a new pool named 'www'.
; the variable \$pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]
[$POOL_NAME]
; Per pool prefix
; 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_flag[log_errors] = on
EOF
if [ -f "${__object:?}/parameter/memory-limit" ]; then
echo "php_admin_value[memory_limit] = $(cat "$__object/parameter/memory-limit")"
else
echo ";php_admin_value[memory_limit] = 32M"
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
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
if [ ! -f /var/www/wordpress ]; then
cd /var/www
curl https://wordpress.org/latest.tar.gz -o $archive
tar xf $archive
rm $archive
chown -R wordpress:wordpress wordpress
if [ ! -d "$install_dir" ]; then
mkdir -p "$install_dir"
chown -R $user:$group "$install_dir"
cd "$install_dir"
sudo -u $user $wp_cli core download
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
EOF

View file

@ -1,36 +1,46 @@
#!/bin/sh
# TODO: set max upload size in PHP configuration (php.ini).
os=$(cat "${__global:?}/explorer/os")
instance="${__object_id:?}"
user=$instance
group=$user
if [ "$os" != "alpine" ]; then
echo "This type is expected to run on Alpine Linux, not $os. Exiting." >&2
exit 1
fi
# Type parameters.
mysql_password="$(cat "${__object:?}/parameter/mysql-password")"
nginx_domain="$(cat "${__object:?}/parameter/nginx-domain")"
nginx_domain="$(cat "${__object:?}/parameter/domain")"
altdomains=
while read -r altdomain;
do
if [ -f "${__object:?}/parameter/altdomains" ]; then
while read -r altdomain;
do
altdomains="--altdomain $altdomain $altdomains"
done < "${__object:?}/parameter/altdomains"
done < "${__object:?}/parameter/altdomains"
fi
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.
__user wordpress --home /var/www/wordpress
# Wordpress CLI management tool.
__wp_cli
# Wordpress user & group.
homedir="/var/www/$instance"
__user "$user" --home "$homedir"
# Basic PHP FPM setup + Wordpress dependencies.
require="__user/wordpress" __recycledcloud_php \
--pool-user wordpress \
--pool-group wordpress \
--pool-listen-addr $php_fpm_socket \
__recycledcloud_php_fpm \
--upload-max-filesize $max_upload_size \
--enable-opcache
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 \
--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 \
php7-xml php7-mysqli php7-imap php7-cgi php7-pdo php7-pdo_mysql php7-soap \
@ -42,17 +52,23 @@ do
__package "$dependency"
done
# MySQL/MariaDB database
__recycledcloud_mysql
require="__recycledcloud_mysql" __mysql_database wordpress \
--user wordpress --password "$mysql_password"
# Daily database backup/export.
require="__user/$user" __cron "$instance-db-export" \
--user "$user" \
--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.
# shellcheck disable=SC2086
__nginx "$nginx_domain" \
$altdomains \
--config - <<- EOF
root /var/www/wordpress;
root "$homedir";
index index.php;
client_max_body_size $max_upload_size;

View file

@ -0,0 +1 @@
admin

View file

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

View file

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