-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·39 lines (33 loc) · 966 Bytes
/
dev.sh
File metadata and controls
executable file
·39 lines (33 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Auto-reload dev runner for lang2sql-bot.
# Watches src/ for .py changes and restarts the bot automatically.
set -a
source "$(dirname "$0")/.env"
set +a
REF=$(mktemp)
restart_bot() {
if [ -n "$BOT_PID" ] && kill -0 "$BOT_PID" 2>/dev/null; then
echo "[watch] stopping PID $BOT_PID..."
kill "$BOT_PID"
wait "$BOT_PID" 2>/dev/null
fi
echo "[watch] starting bot..."
.venv/bin/lang2sql-bot &
BOT_PID=$!
touch "$REF"
echo "[watch] PID $BOT_PID"
}
trap 'kill $BOT_PID 2>/dev/null; rm -f $REF; exit' INT TERM
restart_bot
while true; do
sleep 2
if find src/ -name "*.py" -newer "$REF" | grep -q .; then
CHANGED=$(find src/ -name "*.py" -newer "$REF" | head -3 | tr '\n' ' ')
echo "[watch] changed: $CHANGED"
restart_bot
elif ! kill -0 "$BOT_PID" 2>/dev/null; then
echo "[watch] bot crashed, restarting in 2s..."
sleep 2
restart_bot
fi
done