Init.
This commit is contained in:
53
entrypoint.sh
Executable file
53
entrypoint.sh
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/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:"
|
||||
echo " - MySQL container is running"
|
||||
echo " - Both containers are on the same Docker network"
|
||||
echo " - MYSQL_HOST environment variable is correctly set"
|
||||
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
|
||||
|
||||
# Generate self-signed certificate if needed
|
||||
CERT_PATH="/etc/prosody/certs/xmpp.guschin.info.crt"
|
||||
KEY_PATH="/etc/prosody/certs/xmpp.guschin.info.key"
|
||||
|
||||
if [ ! -f "$CERT_PATH" ] || [ ! -f "$KEY_PATH" ]; then
|
||||
echo "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"
|
||||
fi
|
||||
|
||||
echo "Starting Prosody..."
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user