nextcloudpi/bin/ncp/CONFIG/nc-limits.sh
Tobias Knöppler b675d61e61
Upgrade to PHP 8.1 when installing NC >= 24 (#1554)
* Update nextcloud to 24.0.4
* ncp-update-nc: Upgrade php to version 8.1 when installing NC >= 24
* ncp-update-nc: Use /etc/shadow workaround for installing systemd
* ncp-update-nc: Run nc-limits after php upgrade
* ncp-update-nc: Rollback after failed php upgrade
* ncp-update-nc: Add success message
* ncp-update-nc: Prevent installation of NC >= 24 on debian 10/PHP <= 7.3
* lamp.sh: Install php8.1 from sury.org
* lamp.sh: Use /etc/shadow workaround for installing systemd
* Dockerfile: Install wget, ca-certificates, lsb-release and procps before installing lamp.sh
* Dockerfile: Make sure, ncp-templates are available when installing lamp.sh
* Migrate all scripts to use template for writing opcache.ini and get_nc_config_value for retrieving datadir
* nc-nextcloud.sh Fix crash if nc-datadir has not been installed yet
* opcache.ini.sh: Don't try to get tmpl values from nc-datadir in containers
2022-09-15 17:31:15 +02:00

101 lines
3.6 KiB
Bash

#!/bin/bash
# System limits configuration for NextCloudPi
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# More at https://ownyourbits.com/2017/03/13/nextcloudpi-gets-nextcloudpi-config/
#
get_total_mem() {
free -b | sed -n 2p | awk '{ print $2 }'
}
tmpl_innodb_buffer_pool_size() {
local TOTAL_MEM="$(get_total_mem)"
# DATABASE MEMORY (25%)
local AUTOMEM=$(( TOTAL_MEM * 25 / 100 ))
# Maximum MySQL Memory Usage = innodb_buffer_pool_size + key_buffer_size + (read_buffer_size + sort_buffer_size) X max_connections
# leave 16MiB for key_buffer_size and a bit more
AUTOMEM=$(( AUTOMEM - (16 + 32) * 1024 * 1024 ))
echo -n "$AUTOMEM"
}
tmpl_php_max_memory() {
local TOTAL_MEM="$( get_total_mem )"
local MEMORYLIMIT="$(find_app_param nc-limits MEMORYLIMIT)"
[[ "$MEMORYLIMIT" == "0" ]] && echo -n "$(( TOTAL_MEM * 75 / 100 ))" || echo -n "$MEMORYLIMIT"
}
tmpl_php_max_filesize() {
local FILESIZE="$(find_app_param nc-limits MAXFILESIZE)"
[[ "$FILESIZE" == "0" ]] && echo -n "10G" || echo -n "$FILESIZE"
}
configure()
{
# Set auto memory limit to 75% of the total memory
local TOTAL_MEM="$( get_total_mem )"
# special case of 32bit emulation (e.g. 32bit-docker on 64bit hardware)
file /bin/bash | grep 64-bit > /dev/null || TOTAL_MEM="$(( 1024 * 1024 * 1024 * 4 ))"
local AUTOMEM=$(( TOTAL_MEM * 75 / 100 ))
# MAX FILESIZE
# MAX PHP MEMORY
local require_fpm_restart=false
local CONF=/etc/php/${PHPVER}/fpm/conf.d/90-ncp.ini
local CONF_VALUE="$(cat "$CONF" || true)"
echo "Using $(tmpl_php_max_memory) for PHP max memory"
install_template "php/90-ncp.ini.sh" "$CONF"
[[ "$CONF_VALUE" == "$(cat "$CONF")" ]] || require_fpm_restart=true
# MAX PHP THREADS
local CONF=/etc/php/${PHPVER}/fpm/pool.d/www.conf
local CURRENT_THREADS=$( grep "^pm.max_children" "$CONF" | awk '{ print $3 }' )
[[ $PHPTHREADS -eq 0 ]] && PHPTHREADS=$(nproc)
[[ $PHPTHREADS -lt 6 ]] && PHPTHREADS=6
echo "Using $PHPTHREADS PHP threads"
sed -i "s|^pm =.*|pm = static|" "$CONF"
sed -i "s|^pm.max_children =.*|pm.max_children = $PHPTHREADS|" "$CONF"
[[ "$PHPTHREADS" == "$CURRENT_THREADS" ]] || require_fpm_restart=true
local CONF=/etc/mysql/mariadb.conf.d/91-ncp.cnf
CONF_VALUE="$(cat "$CONF" || true)"
install_template "mysql/91-ncp.cnf.sh" "$CONF"
[[ "$CONF_VALUE" == "$(cat "$CONF")" ]] || service mariadb restart
# RESTART PHP
[[ "$require_fpm_restart" == "true" ]] && bash -c "sleep 3; service php${PHPVER}-fpm restart" &>/dev/null &
# redis max memory
local CONF=/etc/redis/redis.conf
local CURRENT_REDIS_MEM=$( grep "^maxmemory" "$CONF" | awk '{ print $2 }' )
[[ "$REDISMEM" != "$CURRENT_REDIS_MEM" ]] && {
sed -i "s|^maxmemory .*|maxmemory $REDISMEM|" "$CONF"
chown redis:redis "$CONF"
service redis-server restart
}
}
install() { :; }
# License
#
# This script is free software; 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 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA