rewrite
This commit is contained in:
102
entrypoint.sh
102
entrypoint.sh
@@ -1,77 +1,41 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "[$(date)] Starting HAProxy Configurator..."
|
||||
echo "╔════════════════════════════════════════╗"
|
||||
echo "║ HAProxy Manager - Entrypoint ║"
|
||||
echo "║ Starting services... ║"
|
||||
echo "╚════════════════════════════════════════╝"
|
||||
|
||||
# Create directories if they don't exist
|
||||
mkdir -p /app/config/auth
|
||||
mkdir -p /app/config/ssl
|
||||
mkdir -p /etc/haproxy
|
||||
mkdir -p /var/log/supervisor
|
||||
# ===== CHECK ENVIRONMENT =====
|
||||
echo "[STARTUP] Environment: ${FLASK_ENV:-production}"
|
||||
echo "[STARTUP] Python version: $(python --version)"
|
||||
|
||||
# Create default auth.cfg if doesn't exist
|
||||
if [ ! -f /app/config/auth/auth.cfg ]; then
|
||||
cat > /app/config/auth/auth.cfg <<EOF
|
||||
[auth]
|
||||
username = admin
|
||||
password = admin123
|
||||
EOF
|
||||
echo "[$(date)] Created default auth.cfg"
|
||||
fi
|
||||
# ===== INIT DATABASE =====
|
||||
echo "[STARTUP] Initializing database..."
|
||||
python -c "
|
||||
from app import app
|
||||
from database import init_db
|
||||
with app.app_context():
|
||||
init_db(app)
|
||||
print('[STARTUP] Database initialized successfully')
|
||||
" || {
|
||||
echo "[ERROR] Database initialization failed!"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Create default ssl.ini if doesn't exist
|
||||
if [ ! -f /app/config/ssl.ini ]; then
|
||||
cat > /app/config/ssl.ini <<EOF
|
||||
[ssl]
|
||||
certificate_path = /app/config/ssl/haproxy-configurator.pem
|
||||
private_key_path = /app/config/ssl/haproxy-configurator.pem
|
||||
EOF
|
||||
echo "[$(date)] Created default ssl.ini"
|
||||
fi
|
||||
# ===== GENERATE INITIAL HAPROXY CONFIG =====
|
||||
echo "[STARTUP] Generating initial HAProxy config..."
|
||||
python -c "
|
||||
from app import app
|
||||
from utils.config_generator import generate_haproxy_config, save_haproxy_config
|
||||
with app.app_context():
|
||||
config = generate_haproxy_config()
|
||||
save_haproxy_config(config)
|
||||
print('[STARTUP] HAProxy config generated')
|
||||
" || {
|
||||
echo "[WARNING] Could not generate initial config, continuing..."
|
||||
}
|
||||
|
||||
# Generate self-signed certificate if doesn't exist
|
||||
if [ ! -f /app/config/ssl/haproxy-configurator.pem ]; then
|
||||
openssl req -x509 -newkey rsa:2048 -keyout /app/config/ssl/haproxy-configurator.pem \
|
||||
-out /app/config/ssl/haproxy-configurator.pem -days 365 -nodes \
|
||||
-subj "/C=PL/ST=State/L=City/O=Organization/CN=haproxy-configurator.local"
|
||||
chmod 600 /app/config/ssl/haproxy-configurator.pem
|
||||
echo "[$(date)] Generated SSL certificate"
|
||||
fi
|
||||
|
||||
# Create default haproxy.cfg if doesn't exist or is empty
|
||||
if [ ! -s /etc/haproxy/haproxy.cfg ]; then
|
||||
cat > /etc/haproxy/haproxy.cfg <<'HAPROXYCFG'
|
||||
global
|
||||
log stdout local0
|
||||
maxconn 4096
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode http
|
||||
option httplog
|
||||
option dontlognull
|
||||
timeout connect 5000
|
||||
timeout client 50000
|
||||
timeout server 50000
|
||||
|
||||
listen stats
|
||||
bind *:8404
|
||||
stats enable
|
||||
stats uri /stats
|
||||
stats refresh 30s
|
||||
stats show-legends
|
||||
HAPROXYCFG
|
||||
echo "[$(date)] Created default haproxy.cfg"
|
||||
fi
|
||||
|
||||
# Set proper permissions
|
||||
chmod 600 /app/config/ssl/haproxy-configurator.pem 2>/dev/null || true
|
||||
chmod 644 /app/config/auth/auth.cfg
|
||||
chmod 644 /app/config/ssl.ini
|
||||
chmod 644 /etc/haproxy/haproxy.cfg
|
||||
|
||||
echo "[$(date)] Configuration ready"
|
||||
echo "[$(date)] Starting supervisord..."
|
||||
|
||||
# Start supervisord
|
||||
# ===== START SUPERVISOR (runs Flask + HAProxy + other services) =====
|
||||
echo "[STARTUP] Starting supervisord..."
|
||||
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
Reference in New Issue
Block a user