This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_jar.sh
executable file
·117 lines (96 loc) · 2.51 KB
/
run_jar.sh
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
#!/bin/bash
set -euo pipefail
export PORT=8081
runFrontend=true;
env=default;
echo "about to do args"
while [[ $# -gt 0 ]]
do
echo "in loop $*@"
case $1 in
--env)
env="$2"
shift
shift
;;
--no-frontend) runFrontend=false
shift ;;
*) shift
break
;;
esac
done
echo "done with args"
if [ -z $PORT ] ; then
echo ""
echo "******************************************************"
echo "Port was not set. Setting it to 8080 by default."
echo "******************************************************"
echo ""
export PORT=8080
else
echo "Running on port $PORT."
fi
export BASE_URL=http://localhost:$PORT
# This will always run when THIS script exits
cleanup() {
EXIT_CODE=$?
if [ -f tsr.pid ]; then
! kill -9 "$(cat tsr.pid)"
! rm -f tsr.pid
fi
exit $EXIT_CODE
}
trap cleanup 0
if command -v lsof && lsof -i ":$PORT" ; then
echo ""
echo "******************************************************"
echo "Something is already using port $PORT. Killing it now"
echo "******************************************************"
echo ""
kill "$(lsof -i ":$PORT" | awk '{print $2}' | sed -n '2 p')"
fi
if $runFrontend ; then
echo ""
echo "******************************************************"
echo "starting the front end"
echo "******************************************************"
echo ""
pushd client
BROWSER=none yarn start > /dev/null 2>&1 &
popd
fi
echo ""
echo "******************************************************"
echo "starting the backend"
echo "******************************************************"
echo ""
if [[ -z ${CI+x} ]]; then
# Not in CI
SPRING_PROFILES_ACTIVE="$env" ./gradlew yarn_build assemble bootRun --console=plain --args="--server.port=$PORT" &
else
# In CI
SPRING_PROFILES_ACTIVE="$env" java -jar -Dserver.port=$PORT ./build/libs/tsr-*.jar &
fi
echo $! > tsr.pid
sleep 20;
attempt=0
while [ $attempt -le 299 ];
do
attempt=$(( $attempt + 1 ))
if curl -s -o /dev/null ${BASE_URL}; then
echo ""
echo "******************************************************"
echo "$(date) - connected successfully"
echo "******************************************************"
echo ""
break
fi
echo "$(date) - still trying to connect to ${BASE_URL}"
sleep 1
done
if [ $attempt -eq 300 ]; then
echo "Timed out while trying to connect to ${BASE_URL}"
kill -9 "$(jobs -p)"
exit 1
fi