Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Copy Markdown
Member

@casperklein casperklein Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure this doesn't work, as the command exits and doesn't run in foreground. How would supervisor handle restarting that service?

Edit:

Running DMS with

ENABLE_SRS=1
SUPERVISOR_LOGLEVEL=info

we can see an endless loop of supervisor starting postsrsd:

Details
mailserver  | 2023-03-03 01:02:52,127 INFO success: postsrsd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
mailserver  | 2023-03-03 01:02:52,128 INFO exited: postsrsd (exit status 0; expected)
mailserver  | 2023-03-03 01:02:52,129 INFO spawned: 'postsrsd' with pid 972
mailserver  | 2023-03-03 01:02:52,137 INFO success: postsrsd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
mailserver  | 2023-03-03 01:02:52,139 INFO exited: postsrsd (exit status 0; expected)
mailserver  | 2023-03-03 01:02:52,139 INFO spawned: 'postsrsd' with pid 977
mailserver  | 2023-03-03 01:02:52,148 INFO success: postsrsd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
mailserver  | 2023-03-03 01:02:52,149 INFO exited: postsrsd (exit status 0; expected)
mailserver  | 2023-03-03 01:02:52,150 INFO spawned: 'postsrsd' with pid 982
mailserver  | 2023-03-03 01:02:52,158 INFO success: postsrsd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
mailserver  | 2023-03-03 01:02:52,159 INFO exited: postsrsd (exit status 0; expected)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can see an endless loop of supervisor starting postsrsd:

Could we better detect this issue in tests?

I touched on similar concerns observed in the past with supervisor. In addition to the other improvement we have an existing issue for, I'll add mention of this problem too.

Good catch :)


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