From dea7e2640f0800b91eaddda9bd670f725214a235 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 6 Nov 2021 23:36:07 +0100 Subject: [PATCH] install_update_dovecot.sh: systemd service file is now loacted in '/lib/systemd/system/' directory. --- install_update_dovecot.sh | 75 ++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/install_update_dovecot.sh b/install_update_dovecot.sh index ec84d3e..bdcf89b 100755 --- a/install_update_dovecot.sh +++ b/install_update_dovecot.sh @@ -217,6 +217,8 @@ fi [[ -n "$max_userip_connections" ]] || max_userip_connections=24 [[ -n "$auth_mechanisms" ]] || auth_mechanisms="plain login" +[[ -n "$service_limit_nofile" ]] || service_limit_nofile=524280 + declare -i dovecot_major_version=0 declare -i dovecot_minor_version=0 declare -i dovecot_patch_level=0 @@ -866,6 +868,8 @@ else echo -e "$rc_skipped" fi +blank_line + echononl "\tRemove dovecot service file if exists.." if [[ -f "/etc/systemd/system/dovecot.service" ]] ; then rm -f "/etc/systemd/system/dovecot.service" > /dev/null 2>&1 @@ -892,6 +896,21 @@ else echo -e "$rc_skipped" fi +echononl "\tRemove directory '/etc/systemd/system/dovecot.service.d' if exists.." +if [[ -d "/etc/systemd/system/dovecot.service.d" ]] ; then + rm -rf "/etc/systemd/system/dovecot.service.d" > /dev/null 2>&1 + if [[ "$?" -gt 0 ]]; then + echo -e "$rc_failed" + error "Removing directory '/etc/systemd/system/dovecot.service.d' failed." + else + echo -e "$rc_done" + fi +else + echo -e "$rc_skipped" +fi + +blank_line + ## - Install dovecot ## - echononl "\tInstall Dovecot into Folder /usr/local/dovecot-${_version}" @@ -2389,37 +2408,43 @@ if $systemd_support; then ## - here: ## - LimitNOFILE=32768 ## - - echononl "\tAdjust 'LimitNOFILE' at file 'dovecot.service'.." - if [[ -f "/etc/systemd/system/dovecot.service" ]] ; then - if $(grep -q -o -E "LimitNOFILE\s*=\s*[^[:blank:]]+" /etc/systemd/system/dovecot.service 2> /dev/null ) ; then - perl -i -n -p -e "s/(LimitNOFILE\s*=\s*.*)/LimitNOFILE=32768/" /etc/systemd/system/dovecot.service - if [[ $? -eq 0 ]]; then - echo -e "$rc_done" + if [[ -f "/lib/systemd/system/dovecot.service" ]] \ + && $(grep -q -E "^LimitNOFILE=" /lib/systemd/system/dovecot.service) ; then + + _LimitNOFILE="$(grep -E "^LimitNOFILE=[[:digit:]]+" /lib/systemd/system/dovecot.service | cut -d'=' -f2)" + + adjust_limit_nofile=false + + if [[ $service_limit_nofile -gt _LimitNOFILE ]] ; then + + adjust_limit_nofile=true + echononl "\tCreate Directory '/etc/systemd/system/dovecot.service.d'.." + if [[ -d "/etc/systemd/system/dovecot.service.d" ]] ; then + echo -e "$rc_skipped" else + mkdir "/etc/systemd/system/dovecot.service.d" > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + echo -e "$rc_done" + else echo -e "$rc_failed" + adjust_limit_nofile=false + fi fi - else - echo -e "$rc_skipped" + + fi + + echononl "\tAdjust 'LimitNOFILE' for 'dovecot.service'.." + if ! $adjust_limit_nofile ; then + echo -e "$rc_skipped" + else + cat < /etc/systemd/system/dovecot.service.d/set-limit-nofile.conf +[Service] +LimitNOFILE=$service_limit_nofile +EOF + echo -e "$rc_done" fi - else - echo -e "$rc_skipped" fi - echononl "Adjust 'PIDFile' at file 'dovecot.service'.." - if [[ -f "/etc/systemd/system/dovecot.service" ]] ; then - if $(grep -q -o -E "^\s*PIDFile\s*=\s*/run/" /etc/systemd/system/dovecot.service 2> /dev/null ) ; then - perl -i -n -p -e "s/^(PIDFile\s*=\/var(\/run\/.+))/#\1\nPIDFile=\2/" /etc/systemd/system/dovecot.service - if [[ $? -eq 0 ]]; then - echo -e "$rc_done" - else - echo -e "$rc_failed" - fi - else - echo -e "$rc_skipped" - fi - else - echo -e "$rc_skipped" - fi echononl "\tReload systemd .." systemctl daemon-reload > /dev/null 2>&1