Skip to content

Commit 7e84b9c

Browse files
rex0104claude
andcommitted
chore: add restart.sh for production deploy
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f350c43 commit 7e84b9c

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

restart.sh

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,46 @@
22
set -euo pipefail
33

44
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5-
COMPOSE_FILE="$SCRIPT_DIR/docker/docker-compose.yml"
5+
PID_FILE="$SCRIPT_DIR/.server.pid"
6+
LOG_FILE="$SCRIPT_DIR/logs/server.log"
7+
VENV_PYTHON="$SCRIPT_DIR/.venv/bin/python"
68

79
echo "[daily-stock] pulling latest code..."
810
cd "$SCRIPT_DIR"
911
git pull
1012

11-
echo "[daily-stock] rebuilding and restarting server container..."
12-
docker-compose -f "$COMPOSE_FILE" up -d --build server
13+
echo "[daily-stock] updating Python dependencies..."
14+
"$VENV_PYTHON" -m pip install -q -r requirements.txt
1315

14-
echo "[daily-stock] container status:"
15-
docker-compose -f "$COMPOSE_FILE" ps server
16+
echo "[daily-stock] building frontend..."
17+
cd "$SCRIPT_DIR/apps/dsa-web"
18+
npm ci --prefer-offline
19+
VITE_BASE_PATH=/agents/daily-stock/ npm run build
20+
cd "$SCRIPT_DIR"
21+
22+
echo "[daily-stock] stopping existing server..."
23+
if [ -f "$PID_FILE" ]; then
24+
OLD_PID=$(cat "$PID_FILE")
25+
if kill -0 "$OLD_PID" 2>/dev/null; then
26+
kill "$OLD_PID"
27+
sleep 2
28+
fi
29+
rm -f "$PID_FILE"
30+
else
31+
# fallback: find by command
32+
pkill -f "python main.py --serve-only" 2>/dev/null || true
33+
sleep 1
34+
fi
35+
36+
echo "[daily-stock] starting server..."
37+
mkdir -p "$SCRIPT_DIR/logs"
38+
nohup "$VENV_PYTHON" main.py --serve-only >> "$LOG_FILE" 2>&1 &
39+
echo $! > "$PID_FILE"
1640

17-
echo "[daily-stock] done."
41+
sleep 2
42+
if kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
43+
echo "[daily-stock] server started (PID $(cat "$PID_FILE")), logging to $LOG_FILE"
44+
else
45+
echo "[daily-stock] ERROR: server failed to start, check $LOG_FILE"
46+
exit 1
47+
fi

0 commit comments

Comments
 (0)