Spaces:
Paused
Paused
Update entrypoint.sh
Browse files- entrypoint.sh +54 -55
entrypoint.sh
CHANGED
|
@@ -1,24 +1,24 @@
|
|
| 1 |
-
#!/usr/bin/env bash
|
| 2 |
-
set -euo pipefail
|
| 3 |
-
|
| 4 |
-
if [[ -n "${QBT_PROFILE:-}" ]]; then
|
| 5 |
-
CONFIG_DIR="$QBT_PROFILE"
|
| 6 |
-
elif [[ -d /data ]]; then
|
| 7 |
-
CONFIG_DIR="/data/qbittorrent"
|
| 8 |
-
else
|
| 9 |
-
CONFIG_DIR="/config"
|
| 10 |
-
fi
|
| 11 |
-
|
| 12 |
-
if [[ -n "${QBITTORRENT_SAVE_PATH:-}" ]]; then
|
| 13 |
-
DOWNLOAD_DIR="$QBITTORRENT_SAVE_PATH"
|
| 14 |
-
elif [[ -d /data ]]; then
|
| 15 |
-
DOWNLOAD_DIR="/data/downloads"
|
| 16 |
-
else
|
| 17 |
-
DOWNLOAD_DIR="/downloads"
|
| 18 |
-
fi
|
| 19 |
-
|
| 20 |
-
DEFAULT_CONFIG="/defaults/qBittorrent.conf"
|
| 21 |
-
ACTIVE_CONFIG_DIR="$CONFIG_DIR/qBittorrent/config"
|
| 22 |
ACTIVE_CONFIG="$ACTIVE_CONFIG_DIR/qBittorrent.conf"
|
| 23 |
LEGACY_CONFIG="$CONFIG_DIR/qBittorrent.conf"
|
| 24 |
WEB_PORT="${PORT:-5000}"
|
|
@@ -28,7 +28,7 @@ TORRENT_SSL_PORT="${QBITTORRENT_TORRENT_SSL_PORT:-14906}"
|
|
| 28 |
mkdir -p "$CONFIG_DIR" "$ACTIVE_CONFIG_DIR" "$DOWNLOAD_DIR" "$DOWNLOAD_DIR/incomplete"
|
| 29 |
|
| 30 |
has_webui_config() {
|
| 31 |
-
local config_file="$1"
|
| 32 |
[[ -f "$config_file" ]] \
|
| 33 |
&& grep -q '^WebUI\\Username=' "$config_file" \
|
| 34 |
&& grep -q '^WebUI\\Password_PBKDF2=' "$config_file"
|
|
@@ -45,14 +45,14 @@ ensure_config_value() {
|
|
| 45 |
printf '%s=%s\n' "$key" "$value" >> "$config_file"
|
| 46 |
fi
|
| 47 |
}
|
| 48 |
-
|
| 49 |
-
SOURCE_CONFIG="$DEFAULT_CONFIG"
|
| 50 |
-
if has_webui_config "$LEGACY_CONFIG"; then
|
| 51 |
-
SOURCE_CONFIG="$LEGACY_CONFIG"
|
| 52 |
-
fi
|
| 53 |
-
|
| 54 |
-
# qBittorrent stores its real profile under <profile>/qBittorrent/config.
|
| 55 |
-
# Keep older /config/qBittorrent.conf mounts working by migrating them forward.
|
| 56 |
if ! has_webui_config "$ACTIVE_CONFIG"; then
|
| 57 |
cp "$SOURCE_CONFIG" "$ACTIVE_CONFIG"
|
| 58 |
fi
|
|
@@ -63,7 +63,7 @@ ensure_config_value "$ACTIVE_CONFIG" 'Session\\AddTorrentStopped' "false"
|
|
| 63 |
ensure_config_value "$ACTIVE_CONFIG" 'Session\\ShareLimitAction' "Stop"
|
| 64 |
|
| 65 |
cp "$ACTIVE_CONFIG" "$LEGACY_CONFIG"
|
| 66 |
-
|
| 67 |
shutdown() {
|
| 68 |
if [[ -n "${BOT_PID:-}" ]] && kill -0 "$BOT_PID" 2>/dev/null; then
|
| 69 |
kill "$BOT_PID" 2>/dev/null || true
|
|
@@ -71,34 +71,33 @@ shutdown() {
|
|
| 71 |
if [[ -n "${WEB_PID:-}" ]] && kill -0 "$WEB_PID" 2>/dev/null; then
|
| 72 |
kill "$WEB_PID" 2>/dev/null || true
|
| 73 |
fi
|
| 74 |
-
if [[ -n "${QBT_PID:-}" ]] && kill -0 "$QBT_PID" 2>/dev/null; then
|
| 75 |
-
kill "$QBT_PID" 2>/dev/null || true
|
| 76 |
-
fi
|
| 77 |
-
wait || true
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
trap shutdown SIGINT SIGTERM
|
| 81 |
-
|
| 82 |
-
qbittorrent-nox --profile="$CONFIG_DIR" &
|
| 83 |
-
QBT_PID=$!
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
--
|
| 88 |
-
--
|
| 89 |
-
--
|
|
|
|
| 90 |
app:app &
|
| 91 |
WEB_PID=$!
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
-
WAIT_PIDS=("$QBT_PID" "$WEB_PID")
|
| 99 |
-
if [[ -n "${BOT_PID:-}" ]]; then
|
| 100 |
-
WAIT_PIDS+=("$BOT_PID")
|
| 101 |
-
fi
|
| 102 |
|
| 103 |
wait -n "${WAIT_PIDS[@]}"
|
| 104 |
EXIT_CODE=$?
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
if [[ -n "${QBT_PROFILE:-}" ]]; then
|
| 5 |
+
CONFIG_DIR="$QBT_PROFILE"
|
| 6 |
+
elif [[ -d /data ]]; then
|
| 7 |
+
CONFIG_DIR="/data/qbittorrent"
|
| 8 |
+
else
|
| 9 |
+
CONFIG_DIR="/config"
|
| 10 |
+
fi
|
| 11 |
+
|
| 12 |
+
if [[ -n "${QBITTORRENT_SAVE_PATH:-}" ]]; then
|
| 13 |
+
DOWNLOAD_DIR="$QBITTORRENT_SAVE_PATH"
|
| 14 |
+
elif [[ -d /data ]]; then
|
| 15 |
+
DOWNLOAD_DIR="/data/downloads"
|
| 16 |
+
else
|
| 17 |
+
DOWNLOAD_DIR="/downloads"
|
| 18 |
+
fi
|
| 19 |
+
|
| 20 |
+
DEFAULT_CONFIG="/defaults/qBittorrent.conf"
|
| 21 |
+
ACTIVE_CONFIG_DIR="$CONFIG_DIR/qBittorrent/config"
|
| 22 |
ACTIVE_CONFIG="$ACTIVE_CONFIG_DIR/qBittorrent.conf"
|
| 23 |
LEGACY_CONFIG="$CONFIG_DIR/qBittorrent.conf"
|
| 24 |
WEB_PORT="${PORT:-5000}"
|
|
|
|
| 28 |
mkdir -p "$CONFIG_DIR" "$ACTIVE_CONFIG_DIR" "$DOWNLOAD_DIR" "$DOWNLOAD_DIR/incomplete"
|
| 29 |
|
| 30 |
has_webui_config() {
|
| 31 |
+
local config_file="$1"
|
| 32 |
[[ -f "$config_file" ]] \
|
| 33 |
&& grep -q '^WebUI\\Username=' "$config_file" \
|
| 34 |
&& grep -q '^WebUI\\Password_PBKDF2=' "$config_file"
|
|
|
|
| 45 |
printf '%s=%s\n' "$key" "$value" >> "$config_file"
|
| 46 |
fi
|
| 47 |
}
|
| 48 |
+
|
| 49 |
+
SOURCE_CONFIG="$DEFAULT_CONFIG"
|
| 50 |
+
if has_webui_config "$LEGACY_CONFIG"; then
|
| 51 |
+
SOURCE_CONFIG="$LEGACY_CONFIG"
|
| 52 |
+
fi
|
| 53 |
+
|
| 54 |
+
# qBittorrent stores its real profile under <profile>/qBittorrent/config.
|
| 55 |
+
# Keep older /config/qBittorrent.conf mounts working by migrating them forward.
|
| 56 |
if ! has_webui_config "$ACTIVE_CONFIG"; then
|
| 57 |
cp "$SOURCE_CONFIG" "$ACTIVE_CONFIG"
|
| 58 |
fi
|
|
|
|
| 63 |
ensure_config_value "$ACTIVE_CONFIG" 'Session\\ShareLimitAction' "Stop"
|
| 64 |
|
| 65 |
cp "$ACTIVE_CONFIG" "$LEGACY_CONFIG"
|
| 66 |
+
|
| 67 |
shutdown() {
|
| 68 |
if [[ -n "${BOT_PID:-}" ]] && kill -0 "$BOT_PID" 2>/dev/null; then
|
| 69 |
kill "$BOT_PID" 2>/dev/null || true
|
|
|
|
| 71 |
if [[ -n "${WEB_PID:-}" ]] && kill -0 "$WEB_PID" 2>/dev/null; then
|
| 72 |
kill "$WEB_PID" 2>/dev/null || true
|
| 73 |
fi
|
| 74 |
+
if [[ -n "${QBT_PID:-}" ]] && kill -0 "$QBT_PID" 2>/dev/null; then
|
| 75 |
+
kill "$QBT_PID" 2>/dev/null || true
|
| 76 |
+
fi
|
| 77 |
+
wait || true
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
trap shutdown SIGINT SIGTERM
|
| 81 |
+
|
| 82 |
+
qbittorrent-nox --profile="$CONFIG_DIR" &
|
| 83 |
+
QBT_PID=$!
|
| 84 |
+
echo "[entrypoint] qBittorrent PID: $QBT_PID"
|
| 85 |
+
|
| 86 |
+
gunicorn \
|
| 87 |
+
--bind "0.0.0.0:${WEB_PORT}" \
|
| 88 |
+
--workers "${GUNICORN_WORKERS:-2}" \
|
| 89 |
+
--threads "${GUNICORN_THREADS:-4}" \
|
| 90 |
+
--timeout "${GUNICORN_TIMEOUT:-120}" \
|
| 91 |
app:app &
|
| 92 |
WEB_PID=$!
|
| 93 |
+
echo "[entrypoint] Web PID: $WEB_PID"
|
| 94 |
|
| 95 |
+
echo "[entrypoint] Starting Telegram bot..."
|
| 96 |
+
python -m bot.bot &
|
| 97 |
+
BOT_PID=$!
|
| 98 |
+
echo "[entrypoint] Telegram bot PID: $BOT_PID"
|
| 99 |
|
| 100 |
+
WAIT_PIDS=("$QBT_PID" "$WEB_PID" "$BOT_PID")
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
wait -n "${WAIT_PIDS[@]}"
|
| 103 |
EXIT_CODE=$?
|