mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-07-01 04:54:49 +02:00
refactoring: split helper functions into smaller scripts (#2420)
This commit is contained in:
parent
2927cc47c7
commit
b61dfe1e24
41 changed files with 389 additions and 396 deletions
31
target/scripts/wrapper/fail2ban-wrapper.sh
Executable file
31
target/scripts/wrapper/fail2ban-wrapper.sh
Executable file
|
@ -0,0 +1,31 @@
|
|||
#! /bin/bash
|
||||
|
||||
# You cannot start fail2ban in some foreground mode and
|
||||
# it's more or less important that docker doesn't kill
|
||||
# fail2ban and its chilren if you stop the container.
|
||||
#
|
||||
# Use this script with supervisord and it will take
|
||||
# care about starting and stopping fail2ban correctly.
|
||||
#
|
||||
# supervisord config snippet for fail2ban-wrapper:
|
||||
#
|
||||
# [program:fail2ban]
|
||||
# process_name = fail2ban
|
||||
# command = /path/to/fail2ban-wrapper.sh
|
||||
# startsecs = 0
|
||||
# autorestart = false
|
||||
#
|
||||
|
||||
trap "/usr/bin/fail2ban-client stop" SIGINT
|
||||
trap "/usr/bin/fail2ban-client stop" SIGTERM
|
||||
trap "/usr/bin/fail2ban-client reload" SIGHUP
|
||||
|
||||
/usr/bin/fail2ban-client start
|
||||
sleep 5
|
||||
|
||||
# wait until fail2ban is dead (triggered by trap)
|
||||
while kill -0 "$(< /var/run/fail2ban/fail2ban.pid)"
|
||||
do
|
||||
sleep 5
|
||||
done
|
||||
|
29
target/scripts/wrapper/postfix-wrapper.sh
Executable file
29
target/scripts/wrapper/postfix-wrapper.sh
Executable file
|
@ -0,0 +1,29 @@
|
|||
#! /bin/bash
|
||||
|
||||
# You cannot start postfix in some foreground mode and
|
||||
# it's more or less important that docker doesn't kill
|
||||
# postfix and its chilren if you stop the container.
|
||||
#
|
||||
# Use this script with supervisord and it will take
|
||||
# care about starting and stopping postfix correctly.
|
||||
#
|
||||
# supervisord config snippet for postfix-wrapper:
|
||||
#
|
||||
# [program:postfix]
|
||||
# process_name = postfix
|
||||
# command = /path/to/postfix-wrapper.sh
|
||||
# startsecs = 0
|
||||
# autorestart = false
|
||||
#
|
||||
|
||||
trap "service postfix stop" SIGINT
|
||||
trap "service postfix stop" SIGTERM
|
||||
trap "service postfix reload" SIGHUP
|
||||
|
||||
service postfix start
|
||||
|
||||
# wait until postfix is dead (triggered by trap)
|
||||
while kill -0 "$(< /var/spool/postfix/pid/master.pid)"
|
||||
do
|
||||
sleep 5
|
||||
done
|
47
target/scripts/wrapper/postsrsd-wrapper.sh
Executable file
47
target/scripts/wrapper/postsrsd-wrapper.sh
Executable file
|
@ -0,0 +1,47 @@
|
|||
#! /bin/bash
|
||||
|
||||
# shellcheck source=../helpers/index.sh
|
||||
source /usr/local/bin/helpers/index.sh
|
||||
|
||||
function _generate_secret { ( umask 0077 ; dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64 -w0 > "${1}" ; ) ; }
|
||||
|
||||
_obtain_hostname_and_domainname
|
||||
|
||||
if [[ -n "${SRS_DOMAINNAME}" ]]
|
||||
then
|
||||
NEW_DOMAIN_NAME="${SRS_DOMAINNAME}"
|
||||
else
|
||||
NEW_DOMAIN_NAME="${DOMAINNAME}"
|
||||
fi
|
||||
|
||||
sed -i -e "s/localdomain/${NEW_DOMAIN_NAME}/g" /etc/default/postsrsd
|
||||
|
||||
POSTSRSD_SECRET_FILE='/etc/postsrsd.secret'
|
||||
POSTSRSD_STATE_DIR='/var/mail-state/etc-postsrsd'
|
||||
POSTSRSD_STATE_SECRET_FILE="${POSTSRSD_STATE_DIR}/postsrsd.secret"
|
||||
|
||||
if [[ -n ${SRS_SECRET} ]]
|
||||
then
|
||||
( umask 0077 ; echo "${SRS_SECRET}" | tr ',' '\n' > "${POSTSRSD_SECRET_FILE}" ; )
|
||||
else
|
||||
if [[ ${ONE_DIR} -eq 1 ]]
|
||||
then
|
||||
if [[ ! -f ${POSTSRSD_STATE_SECRET_FILE} ]]
|
||||
then
|
||||
install -d -m 0775 "${POSTSRSD_STATE_DIR}"
|
||||
_generate_secret "${POSTSRSD_STATE_SECRET_FILE}"
|
||||
fi
|
||||
|
||||
install -m 0400 "${POSTSRSD_STATE_SECRET_FILE}" "${POSTSRSD_SECRET_FILE}"
|
||||
elif [[ ! -f ${POSTSRSD_SECRET_FILE} ]]
|
||||
then
|
||||
_generate_secret "${POSTSRSD_SECRET_FILE}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n ${SRS_EXCLUDE_DOMAINS} ]]
|
||||
then
|
||||
sed -i -e "s/^#\?SRS_EXCLUDE_DOMAINS=.*$/SRS_EXCLUDE_DOMAINS=${SRS_EXCLUDE_DOMAINS}/g" /etc/default/postsrsd
|
||||
fi
|
||||
|
||||
/etc/init.d/postsrsd start
|
Loading…
Add table
Add a link
Reference in a new issue