-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathrun-backend-server
executable file
·123 lines (101 loc) · 3.53 KB
/
run-backend-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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/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 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 [[ "${RUNNING}" == "true" && "${RESTART}" == "false" ]]; then
echo "Servers are running and we don't need to restart"
exit 0
fi
if [[ "$PUBLISHED" == "true" ]]; then
BWDSERVER_BINPATH="backend/Build/out/BwdServer/Release/net8.0/linux-x64/publish"
CRONCHECKER_BINPATH="backend/Build/out/CronChecker/Release/net8.0/linux-x64/publish"
QUEUEWORKER_BINPATH="backend/Build/out/QueueWorker/Release/net8.0/linux-x64/publish"
PRODEXEC_BINPATH="backend/Build/out/ProdExec/Release/net8.0/linux-x64/publish"
LOCALEXEC_BINPATH="backend/Build/out/LocalExec/Release/net8.0/linux-x64/publish"
else
BWDSERVER_BINPATH="backend/Build/out/BwdServer/Debug/net8.0"
CRONCHECKER_BINPATH="backend/Build/out/CronChecker/Debug/net8.0"
QUEUEWORKER_BINPATH="backend/Build/out/QueueWorker/Debug/net8.0"
PRODEXEC_BINPATH="backend/Build/out/ProdExec/Debug/net8.0"
LOCALEXEC_BINPATH="backend/Build/out/LocalExec/Debug/net8.0"
fi
LOGS="${DARK_CONFIG_RUNDIR}/logs"
BWDSERVER_EXE="${BWDSERVER_BINPATH}/BwdServer"
CRONCHECKER_EXE="${CRONCHECKER_BINPATH}/CronChecker"
QUEUEWORKER_EXE="${QUEUEWORKER_BINPATH}/QueueWorker"
PRODEXEC_EXE="${PRODEXEC_BINPATH}/ProdExec"
LOCALEXEC_EXE="${LOCALEXEC_BINPATH}/LocalExec"
# Stop the server processes
echo "Stopping servers"
sudo pkill -f "BwdServer" || true
sudo pkill -f "CronChecker" || true
sudo pkill -f "QueueWorker" || true
./scripts/run-pubsub-emulator
./scripts/run-cloud-storage-emulator
echo "Waiting for postgres"
./scripts/devcontainer/_wait-for-postgres
# if it hasn't been compiled yet, wait for it
echo "Waiting for compiled servers"
for ((i=1;i<=1000;i++));
do
if [[
! -f "${BWDSERVER_EXE}" || \
! -f "${CRONCHECKER_EXE}" || \
! -f "${QUEUEWORKER_EXE}" || \
! -f "${PRODEXEC_EXE}" || \
! -f "${LOCALEXEC_EXE}" ]]; then
sleep 0.01
fi
done
echo "Done waiting for compiled servers"
# Wait for cloud-storage-emulator (can be slow on CI)
echo "Waiting for cloud-storage-emulator"
until curl -s -o /dev/null "localhost:4444" ; do
printf '.'
sleep 0.1
done
grey="\033[1;30m"
reset="\033[0m"
function announce() {
msg="$1"
filename="$2"
filename=$(realpath "$filename" --relative-to .)
echo -e "$msg ($grey$filename$reset)"
}
MIGRATIONS_LOG="$LOGS/migrations.log"
announce "Running migrations" "${MIGRATIONS_LOG}"
# This has been made run in the background because it takes a full second to start
# up. If this turns out not to be safe (eg bugs during initialization of dark server
# processes), then make ir run in the foreground again.
"${PRODEXEC_EXE}" migrations run > "${MIGRATIONS_LOG}" 2>&1
BWDSERVER_LOG="$LOGS/bwdserver.log"
announce "Running bwdserver" "${BWDSERVER_LOG}"
"${BWDSERVER_EXE}" > "${BWDSERVER_LOG}" 2>&1 &
CRONCHECKER_LOG="$LOGS/cronchecker.log"
announce "Running cronchecker" "${CRONCHECKER_LOG}"
"${CRONCHECKER_EXE}" > "${CRONCHECKER_LOG}" 2>&1 &
QUEUEWORKER_LOG="$LOGS/queueworker.log"
announce "Running queueworker" "${QUEUEWORKER_LOG}"
"${QUEUEWORKER_EXE}" > "${QUEUEWORKER_LOG}" 2>&1 &
echo "Finished loading servers"