forked from darklang/dark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-fsharp-server
executable file
·96 lines (82 loc) · 3.14 KB
/
run-fsharp-server
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
. ./scripts/devcontainer/_assert-in-container "$0" "$@"
set -euo pipefail
PUBLISHED=false
RESTART=true
for i in "$@"
do
case "${i}" in
--published)
PUBLISHED=true
shift
;;
esac
case "${i}" in
--restart=no)
RESTART=false
shift
;;
esac
done
# If servers are running and we don't need to restart, then don't
RUNNING=true
if [[ $(pgrep ApiServer -c) -eq 0 ]]; then RUNNING=false; fi
if [[ $(pgrep BwdServer -c) -eq 0 ]]; then RUNNING=false; fi
if [[ $(pgrep CronChecker -c) -eq 0 ]]; then RUNNING=false; fi
if [[ $(pgrep QueueWorker -c) -eq 0 ]]; then RUNNING=false; fi
if [[ $(pgrep nginx -c) -eq 0 ]]; then RUNNING=false; fi
# TODO pubsub and tunnel
if [[ "${RUNNING}" == "true" && "${RESTART}" == "false" ]]; then
echo "Servers are running and we don't need to restart"
exit 0
fi
if [[ "$PUBLISHED" == "true" ]]; then
APISERVER_BINPATH="fsharp-backend/Build/out/ApiServer/Release/net6.0/linux-x64/publish/"
BWDSERVER_BINPATH="fsharp-backend/Build/out/BwdServer/Release/net6.0/linux-x64/publish/"
CRONCHECKER_BINPATH="fsharp-backend/Build/out/CronChecker/Release/net6.0/linux-x64/publish/"
QUEUEWORKER_BINPATH="fsharp-backend/Build/out/QueueWorker/Release/net6.0/linux-x64/publish/"
EXECHOST_BINPATH="fsharp-backend/Build/out/ExecHost/Release/net6.0/linux-x64/publish/"
else
APISERVER_BINPATH="fsharp-backend/Build/out/ApiServer/Debug/net6.0/linux-x64/"
BWDSERVER_BINPATH="fsharp-backend/Build/out/BwdServer/Debug/net6.0/linux-x64/"
CRONCHECKER_BINPATH="fsharp-backend/Build/out/CronChecker/Debug/net6.0/linux-x64/"
QUEUEWORKER_BINPATH="fsharp-backend/Build/out/QueueWorker/Debug/net6.0/linux-x64/"
EXECHOST_BINPATH="fsharp-backend/Build/out/ExecHost/Debug/net6.0/linux-x64/"
fi
APISERVER_EXE="${APISERVER_BINPATH}/ApiServer"
BWDSERVER_EXE="${BWDSERVER_BINPATH}/BwdServer"
CRONCHECKER_EXE="${CRONCHECKER_BINPATH}/CronChecker"
QUEUEWORKER_EXE="${QUEUEWORKER_BINPATH}/QueueWorker"
EXECHOST_EXE="${EXECHOST_BINPATH}/ExecHost"
# Stop the server processes
echo "Stopping servers"
sudo pkill -f "ApiServer" || true
sudo pkill -f "BwdServer" || true
sudo pkill -f "CronChecker" || true
sudo pkill -f "QueueWorker" || true
./scripts/run-pubsub-emulator
./scripts/run-httptunnel
./scripts/run-nginx-server
echo "Waiting for postgres"
./scripts/devcontainer/_wait-for-background-services postgresql
# if it hasn't been compiled yet, wait for it
echo "Waiting for compiled servers"
for ((i=1;i<=1000;i++));
do
if [[ ! -f "${APISERVER_EXE}" || ! -f "${BWDSERVER_EXE}" || ! -f "${CRONCHECKER_EXE}" || ! -f "${QUEUEWORKER_EXE}" || ! -f "${EXECHOST_EXE}" ]]; then
sleep 0.01
fi
done
echo "Done waiting for compiled servers"
LOGS="${DARK_CONFIG_RUNDIR}/logs"
echo "Running migrations"
"${EXECHOST_EXE}" migrations run > "$LOGS/fsharp-migrations.log" 2>&1
echo "Running apiserver"
"${APISERVER_EXE}" > "$LOGS/fsharp-apiserver.log" 2>&1 &
echo "Running bwdserver"
"${BWDSERVER_EXE}" > "$LOGS/fsharp-bwdserver.log" 2>&1 &
echo "Running cronchecker"
"${CRONCHECKER_EXE}" > "$LOGS/fsharp-cronchecker.log" 2>&1 &
echo "Running queueworker"
"${QUEUEWORKER_EXE}" > "$LOGS/fsharp-queueworker.log" 2>&1 &
echo "Finished loading server"