#!/bin/bash # shellcheck disable=2034,2059 true # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) # Tech and Me © - 2018, https://www.techandme.se/ # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF DEBUG=0 debug_mode # Must be root root_check # Check Ubuntu version check_distro_version # Check if dir exists if [ ! -d $SCRIPTS ] then mkdir -p $SCRIPTS fi # Install Redis install_if_not php-redis install_if_not redis-server # Set globally doesn't work for some reason # touch /etc/php/7.0/mods-available/redis.ini # echo 'extension=redis.so' > /etc/php/7.0/mods-available/redis.ini # phpenmod redis # Setting direct to apache2 works if 'libapache2-mod-php7.0' is installed echo 'extension=redis.so' >> /etc/php/7.2/apache2/php.ini service apache2 restart # Prepare for adding redis configuration sed -i "s|);||g" $NCPATH/config/config.php # Add the needed config to Nextclouds config.php cat <> $NCPATH/config/config.php 'memcache.local' => '\\OC\\Memcache\\Redis', 'filelocking.enabled' => true, 'memcache.distributed' => '\\OC\\Memcache\\Redis', 'memcache.locking' => '\\OC\\Memcache\\Redis', 'redis' => array ( 'host' => '$REDIS_SOCK', 'port' => 0, 'timeout' => 0.5, 'dbindex' => 0, 'password' => '$REDIS_PASS', ), ); ADD_TO_CONFIG ## Redis performance tweaks ## if ! grep -Fxq "vm.overcommit_memory = 1" /etc/sysctl.conf then echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf fi # Disable THP if ! grep -Fxq "never" /sys/kernel/mm/transparent_hugepage/enabled then echo "never" > /sys/kernel/mm/transparent_hugepage/enabled fi # Raise TCP backlog #if ! grep -Fxq "net.core.somaxconn" /proc/sys/net/core/somaxconn #then # sed -i "s|net.core.somaxconn.*||g" /etc/sysctl.conf # sysctl -w net.core.somaxconn=512 # echo "net.core.somaxconn = 512" >> /etc/sysctl.conf #fi sed -i "s|# unixsocket .*|unixsocket $REDIS_SOCK|g" $REDIS_CONF sed -i "s|# unixsocketperm .*|unixsocketperm 777|g" $REDIS_CONF sed -i "s|^port.*|port 0|" $REDIS_CONF sed -i "s|# requirepass .*|requirepass $REDIS_PASS|g" $REDIS_CONF sed -i 's|# rename-command CONFIG ""|rename-command CONFIG ""|' $REDIS_CONF redis-cli SHUTDOWN # Secure Redis chown redis:root /etc/redis/redis.conf chmod 600 /etc/redis/redis.conf apt update -q4 & spinner_loading apt autoremove -y apt autoclean exit