Files
prosody/entrypoint.sh

70 lines
2.5 KiB
Bash
Raw Normal View History

2026-02-02 20:12:50 +03:00
#!/bin/bash
set -e
# Prosody Docker Entrypoint Script
echo "Initializing Prosody XMPP Server..."
# Wait for MySQL to be ready
if [ -n "$MYSQL_HOST" ]; then
MYSQL_PORT="${MYSQL_PORT:-3306}"
MYSQL_TIMEOUT="${MYSQL_TIMEOUT:-60}"
echo "Waiting for MySQL at $MYSQL_HOST:$MYSQL_PORT (timeout: ${MYSQL_TIMEOUT}s)..."
counter=0
until nc -z "$MYSQL_HOST" "$MYSQL_PORT" 2>/dev/null || [ $counter -eq $MYSQL_TIMEOUT ]; do
counter=$((counter + 1))
if [ $((counter % 10)) -eq 0 ]; then
echo "Still waiting for MySQL... (${counter}s elapsed)"
fi
sleep 1
done
if [ $counter -eq $MYSQL_TIMEOUT ]; then
echo "ERROR: MySQL at $MYSQL_HOST:$MYSQL_PORT did not become ready within ${MYSQL_TIMEOUT} seconds"
echo "Please check that:"
2026-02-03 21:03:20 +03:00
echo " - MySQL server is running on the host"
echo " - MySQL is listening on port $MYSQL_PORT"
2026-02-02 20:12:50 +03:00
echo " - MYSQL_HOST environment variable is correctly set"
2026-02-03 21:03:20 +03:00
echo " - Firewall allows connection to MySQL port"
2026-02-02 20:12:50 +03:00
exit 1
fi
echo "MySQL is ready! (connected after ${counter}s)"
fi
# Ensure necessary directories exist and are writable
# (directories are already created in Dockerfile with proper ownership)
touch /var/log/prosody/prosody.log /var/log/prosody/prosody.err 2>/dev/null || true
2026-02-04 13:25:46 +03:00
# Copy Let's Encrypt certificate to prosody certs directory if available
2026-02-02 20:12:50 +03:00
CERT_PATH="/etc/prosody/certs/xmpp.guschin.info.crt"
KEY_PATH="/etc/prosody/certs/xmpp.guschin.info.key"
2026-02-04 13:14:27 +03:00
LETSENCRYPT_CERT="/etc/prosody/certs/letsencrypt/fullchain.pem"
LETSENCRYPT_KEY="/etc/prosody/certs/letsencrypt/privkey.pem"
2026-02-04 13:19:36 +03:00
if [ -f "$LETSENCRYPT_CERT" ] && [ -f "$LETSENCRYPT_KEY" ]; then
echo "Setting up Let's Encrypt certificate..."
2026-02-04 13:17:59 +03:00
cp "$LETSENCRYPT_CERT" "$CERT_PATH"
cp "$LETSENCRYPT_KEY" "$KEY_PATH"
chmod 644 "$CERT_PATH"
chmod 600 "$KEY_PATH"
2026-02-04 13:19:36 +03:00
chown prosody:prosody "$CERT_PATH" "$KEY_PATH"
2026-02-04 13:25:46 +03:00
echo "Let's Encrypt certificate successfully installed"
elif [ ! -f "$CERT_PATH" ] || [ ! -f "$KEY_PATH" ]; then
echo "Let's Encrypt certificate not found, generating self-signed certificate..."
openssl req -x509 -newkey rsa:4096 -keyout "$KEY_PATH" -out "$CERT_PATH" \
-days 365 -nodes -subj "/CN=xmpp.guschin.info"
chmod 600 "$KEY_PATH"
chmod 644 "$CERT_PATH"
chown prosody:prosody "$CERT_PATH" "$KEY_PATH"
2026-02-04 13:19:36 +03:00
else
2026-02-04 13:25:46 +03:00
echo "Using existing certificates"
2026-02-02 20:12:50 +03:00
fi
echo "Starting Prosody..."
2026-02-04 13:24:19 +03:00
# Switch to prosody user and execute prosody
2026-02-04 13:27:02 +03:00
exec su -l prosody -c "exec $@"