Skip to content

Commit

Permalink
scripts: remove PostSRSD wrapper (#3128)
Browse files Browse the repository at this point in the history
* remove PostSRSD wrapper

The setup is now completely done during _actual_ setup phase. The
wrapper did not even catch signals (SIGINT, etc.), which I think is
strange.

I also added all the ENVs the wrapper relied on (which previously could
have been unset) to the variables script.

* forgot adjusting the `Dockerfile`
  • Loading branch information
georglauterbach committed Mar 2, 2023
1 parent b451742 commit 9e2f964
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 50 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ COPY \
target/bin/* \
target/scripts/*.sh \
target/scripts/startup/*.sh \
target/scripts/wrapper/*.sh \
/usr/local/bin/

RUN chmod +x /usr/local/bin/*
Expand Down
45 changes: 45 additions & 0 deletions target/scripts/startup/setup.d/postfix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,51 @@ function _setup_SRS
postconf "sender_canonical_classes = ${SRS_SENDER_CLASSES}"
postconf 'recipient_canonical_maps = tcp:localhost:10002'
postconf 'recipient_canonical_classes = envelope_recipient,header_recipient'

function __generate_secret
{
(
umask 0077
dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64 -w0 >"${1}"
)
}

local POSTSRSD_SECRET_FILE POSTSRSD_STATE_DIR POSTSRSD_STATE_SECRET_FILE

sed -i "s/localdomain/${SRS_DOMAINNAME}/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 \
"s/^#\?(SRS_EXCLUDE_DOMAINS=).*$/\1=${SRS_EXCLUDE_DOMAINS}/g" \
/etc/default/postsrsd
fi
}

function _setup_postfix_hostname
Expand Down
8 changes: 7 additions & 1 deletion target/scripts/startup/variables-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ function __environment_variables_general_setup
VARS[POSTFIX_MESSAGE_SIZE_LIMIT]="${POSTFIX_MESSAGE_SIZE_LIMIT:=10240000}" # ~10 MB
VARS[POSTFIX_DAGENT]="${POSTFIX_DAGENT:=}"

_log 'trace' 'Setting SRS specific environment variables'

VARS[SRS_DOMAINNAME]="${SRS_DOMAINNAME:=${DOMAINNAME}}"
VARS[SRS_EXCLUDE_DOMAINS]="${SRS_EXCLUDE_DOMAINS:=}"
VARS[SRS_SECRET]="${SRS_SECRET:=}"
VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}"

_log 'trace' 'Setting miscellaneous environment variables'

VARS[ACCOUNT_PROVISIONER]="${ACCOUNT_PROVISIONER:=FILE}"
Expand All @@ -123,7 +130,6 @@ function __environment_variables_general_setup
VARS[PFLOGSUMM_SENDER]="${PFLOGSUMM_SENDER:=${REPORT_SENDER}}"
VARS[PFLOGSUMM_TRIGGER]="${PFLOGSUMM_TRIGGER:=none}"
VARS[SMTP_ONLY]="${SMTP_ONLY:=0}"
VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}"
VARS[SUPERVISOR_LOGLEVEL]="${SUPERVISOR_LOGLEVEL:=warn}"
VARS[TZ]="${TZ:=}"
VARS[UPDATE_CHECK_INTERVAL]="${UPDATE_CHECK_INTERVAL:=1d}"
Expand Down
47 changes: 0 additions & 47 deletions target/scripts/wrapper/postsrsd-wrapper.sh

This file was deleted.

2 changes: 1 addition & 1 deletion target/supervisor/conf.d/supervisor-app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ autostart=false
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
command=/usr/local/bin/postsrsd-wrapper.sh
command=/etc/init.d/postsrsd start

[program:update-check]
startsecs=0
Expand Down

0 comments on commit 9e2f964

Please sign in to comment.