-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·49 lines (37 loc) · 1.16 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·49 lines (37 loc) · 1.16 KB
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
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Hyperkaehler runner with auto-restart and logging.
# Usage: nohup ./run.sh &
# Or use with screen/tmux for interactive monitoring.
set -eu
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
LOG_DIR="$SCRIPT_DIR/logs"
mkdir -p "$LOG_DIR" "$SCRIPT_DIR/data"
PIDFILE="$SCRIPT_DIR/data/hyperkaehler.pid"
cleanup() {
echo "[$(date -Iseconds)] Stopping hyperkaehler..."
if [ -f "$PIDFILE" ]; then
kill "$(cat "$PIDFILE")" 2>/dev/null || true
rm -f "$PIDFILE"
fi
exit 0
}
trap cleanup SIGINT SIGTERM
echo "[$(date -Iseconds)] Hyperkaehler runner starting"
echo "$$" > "$PIDFILE"
while true; do
LOGFILE="$LOG_DIR/hyperkaehler-$(date +%Y-%m-%d).log"
echo "[$(date -Iseconds)] Starting hyperkaehler (logging to $LOGFILE)"
./hyperkaehler >> "$LOGFILE" 2>&1 &
BOT_PID=$!
echo "$BOT_PID" > "$PIDFILE"
wait "$BOT_PID" || true
EXIT_CODE=$?
echo "[$(date -Iseconds)] Hyperkaehler exited with code $EXIT_CODE"
if [ $EXIT_CODE -eq 0 ]; then
echo "[$(date -Iseconds)] Clean exit, not restarting"
break
fi
echo "[$(date -Iseconds)] Restarting in 30 seconds..."
sleep 30
done