fix(scripts): add fallback logic for OpenSMTPD binary detection

The scripts were hardcoded to look for OpenSMTPD at a custom workspace
path, but the Dockerfile installs it via apt to /usr/sbin/smtpd. This
change adds fallback logic to check multiple locations:

1. Custom workspace path (for backward compatibility)
2. System path /usr/sbin/smtpd
3. Anywhere in PATH

Also adds graceful handling when OpenSMTPD is not installed, logging
an informative message instead of failing with "No such file or directory".
This commit is contained in:
cto-new[bot]
2026-02-09 12:51:31 +00:00
parent 0d17918cad
commit ee4e630b45
2 changed files with 36 additions and 7 deletions

View File

@@ -171,9 +171,26 @@ log "Setting up OpenSMTPD service..."
# Start OpenSMTPD if configuration exists
OPENSMTPD_CONFIG="/workspace/src/backend/app/opensmtpd/install/etc/smtpd.conf"
OPENSMTPD_PID_FILE="/workspace/src/backend/app/opensmtpd/install/var/run/smtpd.pid"
OPENSMTPD_BINARY="/workspace/src/backend/app/opensmtpd/install/sbin/smtpd"
OPENSMTPD_CUSTOM_BINARY="/workspace/src/backend/app/opensmtpd/install/sbin/smtpd"
OPENSMTPD_SYSTEM_BINARY="/usr/sbin/smtpd"
if [ -f "$OPENSMTPD_CONFIG" ] && [ -x "$OPENSMTPD_BINARY" ]; then
# Determine which binary to use (prefer custom, fallback to system)
OPENSMTPD_BINARY=""
if [ -x "$OPENSMTPD_CUSTOM_BINARY" ]; then
OPENSMTPD_BINARY="$OPENSMTPD_CUSTOM_BINARY"
log "Using custom OpenSMTPD binary: $OPENSMTPD_BINARY"
elif [ -x "$OPENSMTPD_SYSTEM_BINARY" ]; then
OPENSMTPD_BINARY="$OPENSMTPD_SYSTEM_BINARY"
log "Using system OpenSMTPD binary: $OPENSMTPD_BINARY"
else
# Try to find in PATH
if command -v smtpd &>/dev/null; then
OPENSMTPD_BINARY="$(command -v smtpd)"
log "Using OpenSMTPD from PATH: $OPENSMTPD_BINARY"
fi
fi
if [ -n "$OPENSMTPD_BINARY" ] && [ -f "$OPENSMTPD_CONFIG" ]; then
log "OpenSMTPD configuration found at $OPENSMTPD_CONFIG"
# Ensure required directories exist with proper permissions
@@ -204,8 +221,8 @@ else
if [ ! -f "$OPENSMTPD_CONFIG" ]; then
log " Config file missing: $OPENSMTPD_CONFIG"
fi
if [ ! -x "$OPENSMTPD_BINARY" ]; then
log " Binary not executable: $OPENSMTPD_BINARY"
if [ -z "$OPENSMTPD_BINARY" ]; then
log " Binary not found at: $OPENSMTPD_CUSTOM_BINARY or $OPENSMTPD_SYSTEM_BINARY"
fi
fi