From d2f9e531ab04a2ed6dbbf0ae28e47a7a50b5fa3d Mon Sep 17 00:00:00 2001 From: samuel Date: Thu, 25 Jun 2026 13:01:17 +0200 Subject: [PATCH] feat: add php-fpm config --- Makefile | 5 +- .../nextcloud/{config.php => config.php.tpl} | 7 ++- files/php-fpm/nextcloud.conf | 16 ++++++ netoik-cloud.spec | 54 ++++++++++++------- 4 files changed, 57 insertions(+), 25 deletions(-) rename files/nextcloud/{config.php => config.php.tpl} (88%) create mode 100644 files/php-fpm/nextcloud.conf diff --git a/Makefile b/Makefile index 964cc3b..8c9306a 100644 --- a/Makefile +++ b/Makefile @@ -73,9 +73,10 @@ install: ## Install files into rpm dest (requires env var DESTDIR) printf "[CRITICAL] Missing env var DESTDIR\n[CRITICAL] This command is designed to be called by rpmbuild only!\n" 1>&2; \ exit 1; \ fi - install --mode=755 --directory $(DESTDIR)$(RPM_SYSCONFDIR)/nginx/conf.d $(DESTDIR)$(RPM_SYSCONFDIR)/nextcloud + install --mode=755 --directory $(DESTDIR)$(RPM_SYSCONFDIR)/nginx/conf.d $(DESTDIR)$(RPM_SYSCONFDIR)/nextcloud $(DESTDIR)$(RPM_SYSCONFDIR)/php-fpm.d install --mode=644 --target-directory=$(DESTDIR)$(RPM_SYSCONFDIR)/nginx/conf.d files/nginx/cloud.netoik.io.conf - install --mode=640 --target-directory=$(DESTDIR)$(RPM_SYSCONFDIR)/nextcloud files/nextcloud/config.php + install --mode=640 --target-directory=$(DESTDIR)$(RPM_SYSCONFDIR)/nextcloud files/nextcloud/config.php.tpl + install --mode=644 --target-directory=$(DESTDIR)$(RPM_SYSCONFDIR)/php-fpm.d files/php-fpm/nextcloud.conf .PHONY: upload upload: ## Upload rpm package to Gitea repository (requires env var PKG_TOKEN) diff --git a/files/nextcloud/config.php b/files/nextcloud/config.php.tpl similarity index 88% rename from files/nextcloud/config.php rename to files/nextcloud/config.php.tpl index 501a1d7..4dba9af 100644 --- a/files/nextcloud/config.php +++ b/files/nextcloud/config.php.tpl @@ -1,8 +1,8 @@ '', - 'passwordsalt' => '', - 'secret' => '', + 'instanceid' => '$INSTANCE_ID', + 'passwordsalt' => '$PASSWORD_SALT', + 'secret' => '$SECRET', 'trusted_domains' => array ( 0 => 'cloud.netoik.io', ), @@ -26,7 +26,6 @@ $CONFIG = array ( ), 'default_phone_region' => 'FR', 'maintenance' => false, - 'maintenance_window_start' => 1, 'log_type' => 'systemd', 'loglevel' => 2, 'config_is_read_only' => true, diff --git a/files/php-fpm/nextcloud.conf b/files/php-fpm/nextcloud.conf new file mode 100644 index 0000000..07ce86c --- /dev/null +++ b/files/php-fpm/nextcloud.conf @@ -0,0 +1,16 @@ +; Configure here a php-fpm pool +; See manual at: https://www.php.net/manual/en/install.fpm.configuration.php + +[nextcloud] +user = nextcloud +group = nextcloud + +listen = /run/php-fpm/nextcloud.sock +listen.owner = nextcloud +listen.group = nextcloud +listen.mode = 0777 + +pm = dynamic +pm.max_children = 50 +pm.min_spare_servers = 5 +pm.max_spare_servers = 35 diff --git a/netoik-cloud.spec b/netoik-cloud.spec index d17b1be..4aabb4f 100644 --- a/netoik-cloud.spec +++ b/netoik-cloud.spec @@ -27,30 +27,23 @@ set -xe # Create nextcloud user if ! id nextcloud >/dev/null 2>&1; then - useradd --no-create-home --shell $SHELL --system nextcloud + useradd --base-dir %{_sharedstatedir} --create-home --shell $SHELL --system nextcloud +fi +runuser --user=nextcloud -- mkdir --parents %{_sharedstatedir}/nextcloud/data + +# Create config file +if ! -f %{_sysconfdir}/nextcloud/config.php; then + export INSTANCE_ID=$(openssl rand -hex 16) + export PASSWORD_SALT=$(openssl rand -hex 16) + export SECRET=$(openssl rand -hex 16) + envsubst < %{_sysconfdir}/nextcloud/config.php.tpl > %{_sysconfdir}/nextcloud/config.php + chown root:nextcloud %{_sysconfdir}/nextcloud/config.php + chmod 640 %{_sysconfdir}/nextcloud/config.php fi # Add nextcloud to postgres and valkey groups usermod --groups postgres,valkey --append nextcloud -# Download nextcloud latest release -wget --output-document %{_tmppath}/nextcloud-latest.tar.bz2 https://download.nextcloud.com/server/releases/latest.tar.bz2 -wget --output-document %{_tmppath}/nextcloud-latest.tar.bz2.asc https://download.nextcloud.com/server/releases/latest.tar.bz2.asc -wget --output-document %{_tmppath}/nextcloud.asc https://nextcloud.com/nextcloud.asc -gpg --import %{_tmppath}/nextcloud.asc -gpg --verify %{_tmppath}/nextcloud-latest.tar.bz2.asc %{_tmppath}/nextcloud-latest.tar.bz2 -tar --extract --file=%{_tmppath}/nextcloud-latest.tar.bz2 --directory=%{_sharedstatedir} - -# Change rights an owner -chown --recursive nextcloud:nextcloud %{_sharedstatedir}/nextcloud -chmod 700 %{_sharedstatedir}/nextcloud - -# Create data dir -runuser --user=nextcloud -- mkdir --parents %{_sharedstatedir}/nextcloud/data - -# Add link to config -runuser --user=nextcloud -- ln --symbolic --force %{_sysconfdir}/nextcloud/config.php %{_sharedstatedir}/nextcloud/config/config.php - # Create postgres user and db if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\du' | grep --quiet nextcloud; then runuser --user=postgres -- createuser nextcloud @@ -59,6 +52,24 @@ if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\l' | grep runuser --user=postgres -- createdb --owner=nextcloud nextcloud fi +# Download nextcloud latest release +if ! -d /var/www/nextcloud; then + wget --output-document %{_tmppath}/nextcloud-latest.tar.bz2 https://download.nextcloud.com/server/releases/latest.tar.bz2 + wget --output-document %{_tmppath}/nextcloud-latest.tar.bz2.asc https://download.nextcloud.com/server/releases/latest.tar.bz2.asc + wget --output-document %{_tmppath}/nextcloud.asc https://nextcloud.com/nextcloud.asc + gpg --import %{_tmppath}/nextcloud.asc + gpg --verify %{_tmppath}/nextcloud-latest.tar.bz2.asc %{_tmppath}/nextcloud-latest.tar.bz2 + tar --extract --file=%{_tmppath}/nextcloud-latest.tar.bz2 --directory=/var/www +fi + +# Change rights and owner +chown --recursive nextcloud:nextcloud /var/www/nextcloud +chmod 755 /var/www/nextcloud + +# Create symbolic links to data and config +runuser --user=nextcloud -- ln --symbolic --force %{_sharedstatedir}/nextcloud/data /var/www/nextcloud/data +runuser --user=nextcloud -- ln --symbolic --force %{_sysconfdir}/nextcloud/config.php /var/www/nextcloud/config/config.php + # Restart services systemctl daemon-reload systemctl reenable nginx.service php-fpm.service @@ -86,9 +97,14 @@ fi %files %dir %attr(755, root, root) %{_sysconfdir}/nextcloud +%attr(644, root, root) %{_sysconfdir}/nextcloud/config.php.tpl %attr(640, root, -) %{_sysconfdir}/nextcloud/config.php %attr(644, root, root) %{_sysconfdir}/nginx/conf.d/cloud.netoik.io.conf +%attr(644, root, root) %{_sysconfdir}/php-fpm.d/nextcloud.conf + +%dir %attr(700, -, -) /var/www/nextcloud + %changelog %autochangelog