-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart-stop.sh
More file actions
executable file
·62 lines (54 loc) · 1.05 KB
/
start-stop.sh
File metadata and controls
executable file
·62 lines (54 loc) · 1.05 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
#!/bin/bash
ACTION="$1"
INDEX="$2"
PORT_BASE=7999
set -e
function help() {
echo "Usage: $0 start|stop index|all"
exit 1
}
echo "Building..."
cargo build &>/dev/null
if [ "$INDEX" == "all" ]; then
"$0" "$ACTION" 1
"$0" "$ACTION" 2
"$0" "$ACTION" 3
exit 0
fi
PORT="$(("$PORT_BASE" + "$INDEX"))"
PORT_INTERNAL="$(("$PORT" - 5000))"
if [ "$PORT" -eq "$PORT_BASE" ]; then
# Index is NaN or empty
help
fi
set -uo pipefail
PID_FILE="/var/run/user/$(id -u)/timestamping-$INDEX.pid"
cd "$(dirname "$(realpath "$0")")"
case "$ACTION" in
start)
if [ -e "$PID_FILE" ]; then
echo "Already running"
exit 0
fi
echo "Starting server with index $INDEX on http://localhost:$PORT"
cargo run -- "$INDEX" "$PORT" "$PORT_INTERNAL" &
PID="$!"
echo "$PID" > "$PID_FILE"
;;
stop)
if [ ! -e "$PID_FILE" ]; then
echo "Not running"
exit 0
fi
kill "$(cat "$PID_FILE")" || true
rm "$PID_FILE"
;;
restart)
"$0" stop "$INDEX"
sleep 10
"$0" start "$INDEX"
;;
*)
help
;;
esac