Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·66 lines (63 loc) · 1.66 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·66 lines (63 loc) · 1.66 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# One-command lifecycle for the local GitHub status board.
# ./run.sh start|stop|restart|status|logs|once
# Environment (all optional): GSB_PORT, GSB_HOST (preview); GITHUB_TOKEN (generation only)
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RUN_DIR="$HERE/.run"
PID_FILE="$RUN_DIR/server.pid"
LOG_FILE="$RUN_DIR/server.log"
PORT="${GSB_PORT:-8790}"
HOST="${GSB_HOST:-127.0.0.1}"
mkdir -p "$RUN_DIR"
is_running() {
[[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null
}
case "${1:-start}" in
start)
if is_running; then
echo "already running (pid $(cat "$PID_FILE")) at http://$HOST:$PORT/"
exit 0
fi
nohup python3 "$HERE/server.py" --host "$HOST" --port "$PORT" >>"$LOG_FILE" 2>&1 &
echo $! >"$PID_FILE"
sleep 1
if is_running; then
echo "started pid $(cat "$PID_FILE") -> http://$HOST:$PORT/ (log: $LOG_FILE)"
else
echo "failed to start; last log lines:" >&2
tail -n 20 "$LOG_FILE" >&2
exit 1
fi
;;
stop)
if is_running; then
kill "$(cat "$PID_FILE")" && rm -f "$PID_FILE" && echo "stopped"
else
rm -f "$PID_FILE"; echo "not running"
fi
;;
restart)
"$0" stop || true
exec "$0" start
;;
status)
if is_running; then
echo "running pid $(cat "$PID_FILE") at http://$HOST:$PORT/"
curl -fsS "http://$HOST:$PORT/data/snapshot.json" && echo
else
echo "not running"; exit 1
fi
;;
logs)
tail -n "${2:-50}" -f "$LOG_FILE"
;;
once)
shift
exec python3 "$HERE/publish.py" "$@"
;;
*)
echo "usage: $0 {start|stop|restart|status|logs|once}" >&2
exit 2
;;
esac