diff --git a/start.sh b/start.sh index d4b4780..568a19d 100755 --- a/start.sh +++ b/start.sh @@ -15,6 +15,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" VENV="$SCRIPT_DIR/.venv" PYTHON="$VENV/bin/python" DATA_DIR="$SCRIPT_DIR/data" +ENV_FILE="$SCRIPT_DIR/.env" # --------------------------------------------------------------- # Colors @@ -61,6 +62,17 @@ for arg in "$@"; do esac done +# --------------------------------------------------------------- +# 3.5 Load environment from .env when present +# --------------------------------------------------------------- +if [ -f "$ENV_FILE" ]; then + info "Loading environment from $ENV_FILE" + set -a + # shellcheck disable=SC1090 + . "$ENV_FILE" + set +a +fi + # --------------------------------------------------------------- # 4. Install cron job # --------------------------------------------------------------- @@ -95,14 +107,16 @@ if [ "$DO_BOT" = true ]; then fi # Kill existing bot process if running - if pgrep -f "telegram_bot.py" > /dev/null 2>&1; then + if pgrep -f "bot/telegram_bot.py|bot\\.telegram_bot" > /dev/null 2>&1; then warn "Killing existing bot process..." - pkill -f "telegram_bot.py" || true + pkill -f "bot/telegram_bot.py|bot\\.telegram_bot" || true sleep 1 fi info "Starting Telegram bot..." - nohup "$PYTHON" "$SCRIPT_DIR/bot/telegram_bot.py" >> "$DATA_DIR/bot.log" 2>&1 & + : > "$DATA_DIR/bot.log" + nohup env PYTHONPATH="$SCRIPT_DIR" "$PYTHON" -m bot.telegram_bot \ + > "$DATA_DIR/bot.log" 2>&1 & BOT_PID=$! info "Bot started (PID: $BOT_PID). Logs: $DATA_DIR/bot.log" fi