78 lines
2.0 KiB
Bash
78 lines
2.0 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
echo "[$(date)] Starting HAProxy Configurator..."
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# 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 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
|
|
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|