@@ -135,13 +135,39 @@ retry_dnf() {
135135send_mail () {
136136 local subject=" $1 "
137137 local message=" ${2:- } "
138-
139- local recipients
140- if mail --help | grep s-nail; then
141- recipients=" ${OPERATIONS_EMAIL// , } "
142- else
143- recipients=" ${OPERATIONS_EMAIL} "
144- fi
138+ # debug start
139+ local artifact_dir=" /var/tmp/artifacts"
140+ local log_file=" ${artifact_dir} /post_provision_mail_debug.log"
141+ local ts
142+ ts=" $( date -u +%Y-%m-%dT%H:%M:%SZ) "
143+ mkdir -p " $artifact_dir "
144+ # debug end
145+
146+ # debug start - force single recipient during diagnostics testing
147+ local recipients=" john.malmberg@hpe.com"
148+ # debug end
149+
150+ local mail_cmd
151+ printf -v mail_cmd ' mail -s %q -r %q %q' " $subject " " $DAOS_DEVOPS_EMAIL " " $recipients "
152+
153+ # debug start
154+ {
155+ echo " [$ts ] send_mail invoked"
156+ echo " subject=$subject "
157+ echo " from=$DAOS_DEVOPS_EMAIL "
158+ echo " to=$recipients "
159+ echo " mail_cmd=$mail_cmd "
160+ echo " build=$BUILD_URL "
161+ echo " stage=$STAGE_NAME "
162+ echo " host=$HOSTNAME "
163+ echo " env snapshot (allowlist):"
164+ printenv | grep -E ' ^(BUILD_URL|STAGE_NAME|HOSTNAME|OPERATIONS_EMAIL|DAOS_DEVOPS_EMAIL|JENKINS_URL|EMAIL_DOMAIN|DAOS_FAILURE_STEP|NODESTRING)=' | sort
165+ echo " env snapshot (full - debug only):"
166+ printenv | sort
167+ echo " postfix main.cf (postconf -n):"
168+ postconf -n 2>&1 || true
169+ } >> " $log_file " 2>&1
170+ # debug end
145171
146172 set +x
147173 {
@@ -150,7 +176,32 @@ send_mail() {
150176 echo " Host: $HOSTNAME "
151177 echo " "
152178 echo -e " $message "
153- } 2>&1 | mail -s " $subject " -r " $DAOS_DEVOPS_EMAIL " " $recipients "
179+ # debug start - mail output changed to log to file
180+ # Original (remove >> "$log_file" 2>&1 when reverting):
181+ # } 2>&1 | mail -s "$subject" -r "$DAOS_DEVOPS_EMAIL" "$recipients"
182+ } 2>&1 | mail -s " $subject " -r " $DAOS_DEVOPS_EMAIL " " $recipients " \
183+ >> " $log_file " 2>&1
184+ # debug end
185+
186+ # debug start
187+ {
188+ echo " [$ts ] postqueue -p"
189+ postqueue -p
190+ } >> " $log_file " 2>&1 || true
191+
192+ {
193+ echo " [$ts ] postfix config snapshot"
194+ if command -v postconf > /dev/null 2>&1 ; then
195+ postconf -nh relayhost
196+ postconf -nh smtp_host_lookup
197+ postconf -nh smtp_tls_security_level
198+ postconf -nh myhostname
199+ postconf -nh myorigin
200+ else
201+ echo " postconf not found"
202+ fi
203+ } >> " $log_file " 2>&1 || true
204+ # debug end
154205 set -x
155206}
156207
@@ -160,8 +211,10 @@ monitor_cmd() {
160211
161212 local duration=0
162213 local start=" $SECONDS "
163- if ! time " $@ " ; then
164- return " ${PIPESTATUS[0]} "
214+ if time " $@ " ; then
215+ :
216+ else
217+ return " $? "
165218 fi
166219 (( duration = SECONDS - start))
167220 if [ " $duration " -gt " $threshold " ]; then
@@ -185,17 +238,20 @@ retry_cmd() {
185238 " Command: $* \nAttempts: $attempt \nStatus: $rc "
186239 fi
187240 return 0
241+ else
242+ rc=$?
188243 fi
189244 # Command failed, retry
190- rc=${PIPESTATUS[0]}
191245 (( attempt++ )) || true
192246 if [ " $attempt " -gt 0 ]; then
193247 sleep " ${RETRY_DELAY_SECONDS:- $DAOS_STACK_RETRY_DELAY_SECONDS } "
194248 fi
195249 done
196250 if [ " $rc " -ne 0 ]; then
251+ echo " DEBUG: retry_cmd invoking send_mail (attempts=$attempt rc=$rc stage=$STAGE_NAME )"
197252 send_mail " Command retry failed in $STAGE_NAME after $attempt attempts" \
198253 " Command: $* \nAttempts: $attempt \nStatus: $rc "
254+ echo " DEBUG: retry_cmd returned from send_mail"
199255 echo " Command retry failed in $STAGE_NAME after $attempt attempts"
200256 echo " Command: $* "
201257 echo " Attempts: $attempt "
@@ -218,8 +274,9 @@ timeout_cmd() {
218274 " Command: $* \nAttempts: $attempt \nStatus: $rc "
219275 fi
220276 return 0
277+ else
278+ rc=$?
221279 fi
222- rc=${PIPESTATUS[0]}
223280 if [ " $rc " = " 124" ]; then
224281 # Command timed out, try again
225282 (( attempt++ )) || true
@@ -229,8 +286,10 @@ timeout_cmd() {
229286 break
230287 done
231288 if [ " $rc " -ne 0 ]; then
289+ echo " DEBUG: timeout_cmd invoking send_mail (attempts=$attempt rc=$rc stage=$STAGE_NAME )"
232290 send_mail " Command timeout failed in $STAGE_NAME after $attempt attempts" \
233291 " Command: $* \nAttempts: $attempt \nStatus: $rc "
292+ echo " DEBUG: timeout_cmd returned from send_mail"
234293 echo " Command timeout failed in $STAGE_NAME after $attempt attempts"
235294 echo " Command: $* "
236295 echo " Attempts: $attempt "
0 commit comments