6
0
Fork 0
This repository has been archived on 2022-03-14. You can view files and clone it, but cannot push or open issues or pull requests.
cdist-recycledcloud/type/__recycledcloud_wordpress/manifest

106 lines
2.5 KiB
Bash

#!/bin/sh
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.
nginx_domain="$(cat "${__object:?}/parameter/domain")"
altdomains=
if [ -f "${__object:?}/parameter/altdomains" ]; then
while read -r altdomain;
do
altdomains="--altdomain $altdomain $altdomains"
done < "${__object:?}/parameter/altdomains"
fi
max_upload_size=100M
php_fpm_socket="/run/php-fpm7/php-fpm-$instance.sock"
# Wordpress CLI management tool.
__wp_cli
# Wordpress user & group.
homedir="/var/www/$instance"
__user "$user" --home "$homedir"
# Basic PHP FPM setup + Wordpress dependencies.
__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 \
--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 \
php7-xmlrpc php7-posix php7-mcrypt php7-gettext php7-ldap php7-mbstring \
php7-ctype php7-dom php7-zip php7-fileinfo php7-exif php7-session"
for dependency in $wordpress_dependencies;
do
__package "$dependency"
done
# 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 "$homedir";
index index.php;
client_max_body_size $max_upload_size;
location / {
try_files \$uri \$uri/ /index.php?\$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:$php_fpm_socket;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~* \.(woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}
EOF