-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathkeep-alive.sh
More file actions
37 lines (29 loc) · 1017 Bytes
/
Copy pathkeep-alive.sh
File metadata and controls
37 lines (29 loc) · 1017 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
#!/bin/bash
# keep-alive.sh - Auto restart bot kalau mati
# Cara pakai: bash keep-alive.sh
BOT_DIR="$(cd "$(dirname "$0")" && pwd)" # folder tempat script ini berada
LOG_FILE="$BOT_DIR/logs/bot.log"
PID_FILE="$BOT_DIR/logs/bot.pid"
mkdir -p "$BOT_DIR/logs"
echo "🤖 Keep-alive dimulai..."
echo "📁 Folder bot : $BOT_DIR"
echo "📄 Log file : $LOG_FILE"
while true; do
# Cek apakah bot sedang jalan
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if kill -0 "$PID" 2>/dev/null; then
# Bot masih jalan, tunggu 30 detik
sleep 30
continue
fi
fi
# Bot mati atau belum jalan → restart
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 🔄 Bot mati! Restart..." | tee -a "$LOG_FILE"
cd "$BOT_DIR"
nohup node main.js >> "$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ✅ Bot restart dengan PID $(cat $PID_FILE)" | tee -a "$LOG_FILE"
# Tunggu 10 detik sebelum cek lagi
sleep 10
done