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:
@@ -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
|
||||
|
||||
|
||||
@@ -174,8 +174,20 @@ main() {
|
||||
|
||||
# Check OpenSMTPD service (ports 25, 587, 465)
|
||||
health_log "INFO" "=== OpenSMTPD Service ==="
|
||||
OPENSMTPD_BINARY="/workspace/src/backend/app/opensmtpd/install/sbin/smtpd"
|
||||
if [ -x "$OPENSMTPD_BINARY" ]; then
|
||||
OPENSMTPD_CUSTOM_BINARY="/workspace/src/backend/app/opensmtpd/install/sbin/smtpd"
|
||||
OPENSMTPD_SYSTEM_BINARY="/usr/sbin/smtpd"
|
||||
|
||||
# Determine which binary to use (prefer custom, fallback to system)
|
||||
OPENSMTPD_BINARY=""
|
||||
if [ -x "$OPENSMTPD_CUSTOM_BINARY" ]; then
|
||||
OPENSMTPD_BINARY="$OPENSMTPD_CUSTOM_BINARY"
|
||||
elif [ -x "$OPENSMTPD_SYSTEM_BINARY" ]; then
|
||||
OPENSMTPD_BINARY="$OPENSMTPD_SYSTEM_BINARY"
|
||||
elif command -v smtpd &>/dev/null; then
|
||||
OPENSMTPD_BINARY="$(command -v smtpd)"
|
||||
fi
|
||||
|
||||
if [ -n "$OPENSMTPD_BINARY" ]; then
|
||||
# Check SMTP port 25
|
||||
if check_port 25 "SMTP"; then
|
||||
health_log "INFO" "✓ SMTP port 25 is listening"
|
||||
@@ -205,7 +217,7 @@ main() {
|
||||
health_log "WARN" "⚠ OpenSMTPD process not found (may be disabled)"
|
||||
fi
|
||||
else
|
||||
health_log "INFO" "OpenSMTPD not installed at expected location, skipping SMTP checks"
|
||||
health_log "INFO" "OpenSMTPD not installed (checked: $OPENSMTPD_CUSTOM_BINARY, $OPENSMTPD_SYSTEM_BINARY, PATH), skipping SMTP checks"
|
||||
fi
|
||||
|
||||
# ttyd service has been removed, no longer checking port 4501
|
||||
|
||||
Reference in New Issue
Block a user