BotDeepSeek/restart_bot.sh

29 lines
786 B
Bash
Executable File

#!/bin/bash
set -e
BOT_DIR="$(cd "$(dirname "$0")" && pwd)"
LOG_FILE="$BOT_DIR/trading_bot.log"
echo "=== IB Trading Bot Starter ==="
echo "BOT_DIR: $BOT_DIR"
# Step 1: Kill any existing bot process
pkill -f "main.py" 2>/dev/null || true
echo "[1/2] Stopped old bot process (if any)"
# Step 2: Start the trading bot (setsid so it survives this shell exiting)
echo "[2/2] Starting trading bot..."
setsid nohup "$BOT_DIR/.venv/bin/python" "$BOT_DIR/main.py" >> "$LOG_FILE" 2>&1 < /dev/null &
BOT_PID=$!
echo "Bot PID: $BOT_PID"
# Wait a few seconds and check
sleep 5
if kill -0 "$BOT_PID" 2>/dev/null; then
echo "=== Bot started successfully (PID: $BOT_PID) ==="
echo "Log: tail -f $LOG_FILE"
else
echo "=== Bot failed to start, check log ==="
tail -5 "$LOG_FILE"
fi