63 lines
1.8 KiB
Bash
63 lines
1.8 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
# Entrypoint script to run both Caddy and CPM+ in a single container
|
|
# This simplifies deployment for home users
|
|
|
|
echo "Starting CaddyProxyManager+ with integrated Caddy..."
|
|
|
|
# Start Caddy in the background with initial empty config
|
|
echo '{"apps":{}}' > /config/caddy.json
|
|
# Use JSON config directly; no adapter needed
|
|
caddy run --config /config/caddy.json &
|
|
CADDY_PID=$!
|
|
echo "Caddy started (PID: $CADDY_PID)"
|
|
|
|
# Wait for Caddy to be ready
|
|
echo "Waiting for Caddy admin API..."
|
|
i=1
|
|
while [ "$i" -le 30 ]; do
|
|
if wget -q -O- http://127.0.0.1:2019/config/ > /dev/null 2>&1; then
|
|
echo "Caddy is ready!"
|
|
break
|
|
fi
|
|
i=$((i+1))
|
|
sleep 1
|
|
done
|
|
|
|
# Start CPM+ management application
|
|
echo "Starting CPM+ management application..."
|
|
if [ "$CPMP_DEBUG" = "1" ]; then
|
|
DEBUG_PORT=${CPMP_DEBUG_PORT:-2345}
|
|
echo "Running CPM+ under Delve (port $DEBUG_PORT)"
|
|
/usr/local/bin/dlv exec /app/cpmp --headless --listen=":$DEBUG_PORT" --api-version=2 --accept-multiclient --log -- &
|
|
else
|
|
/app/cpmp &
|
|
fi
|
|
APP_PID=$!
|
|
echo "CPM+ started (PID: $APP_PID)"
|
|
shutdown() {
|
|
echo "Shutting down..."
|
|
kill -TERM "$APP_PID" 2>/dev/null || true
|
|
kill -TERM "$CADDY_PID" 2>/dev/null || true
|
|
wait "$APP_PID" 2>/dev/null || true
|
|
wait "$CADDY_PID" 2>/dev/null || true
|
|
exit 0
|
|
}
|
|
|
|
# Trap signals for graceful shutdown
|
|
trap 'shutdown' TERM INT
|
|
|
|
echo "CaddyProxyManager+ is running!"
|
|
echo " - Management UI: http://localhost:8080"
|
|
echo " - Caddy Proxy: http://localhost:80, https://localhost:443"
|
|
echo " - Caddy Admin API: http://localhost:2019"
|
|
|
|
# Wait loop: exit when either process dies, then shutdown the other
|
|
while kill -0 "$APP_PID" 2>/dev/null && kill -0 "$CADDY_PID" 2>/dev/null; do
|
|
sleep 1
|
|
done
|
|
|
|
echo "A process exited, initiating shutdown..."
|
|
shutdown
|