first commit
This commit is contained in:
60
start-instance.sh
Executable file
60
start-instance.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
PORT=$1
|
||||
|
||||
if [ -z "$PORT" ]; then
|
||||
echo "ERROR: Port not specified"
|
||||
echo "Usage: $0 <port>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd /opt/geoip_block_generator
|
||||
|
||||
# Safe .env parser
|
||||
if [ -f /opt/geoip_block_generator/.env ]; then
|
||||
echo "Loading environment from .env..."
|
||||
|
||||
while IFS='=' read -r key value || [ -n "$key" ]; do
|
||||
[[ "$key" =~ ^[[:space:]]*# ]] && continue
|
||||
[[ -z "$key" ]] && continue
|
||||
|
||||
key=$(echo "$key" | xargs)
|
||||
value=$(echo "$value" | xargs)
|
||||
|
||||
if [[ "$value" =~ ^\"(.*)\"$ ]]; then
|
||||
value="${BASH_REMATCH[1]}"
|
||||
elif [[ "$value" =~ ^\'(.*)\'$ ]]; then
|
||||
value="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
|
||||
export "$key=$value"
|
||||
done < /opt/geoip_block_generator/.env
|
||||
fi
|
||||
|
||||
# Override port for this instance
|
||||
export FLASK_PORT=$PORT
|
||||
export FLASK_HOST=127.0.0.1
|
||||
|
||||
# Create log directory if not exists
|
||||
mkdir -p /var/log/geoip-ban
|
||||
|
||||
# Log startup
|
||||
echo "========================================"
|
||||
echo "GeoIP WebApp Instance Starting"
|
||||
echo "Port: $PORT"
|
||||
echo "User: $(whoami)"
|
||||
echo "Time: $(date)"
|
||||
echo "========================================"
|
||||
|
||||
exec /opt/geoip_block_generator/venv/bin/gunicorn \
|
||||
--bind "127.0.0.1:${PORT}" \
|
||||
--workers 1 \
|
||||
--threads 8 \
|
||||
--worker-class sync \
|
||||
--timeout 900 \
|
||||
--access-logfile - \
|
||||
--error-logfile - \
|
||||
--log-level info \
|
||||
--access-logformat '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" [Instance:'"${PORT}"']' \
|
||||
app:app
|
||||
Reference in New Issue
Block a user