-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathflushall_build_and_run.sh
More file actions
executable file
·160 lines (142 loc) · 5.38 KB
/
flushall_build_and_run.sh
File metadata and controls
executable file
·160 lines (142 loc) · 5.38 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
################################################################################
# OBP-API Build and Run Script (HTTP4S Server)
#
# This script builds the OBP-API project and runs the HTTP4S server.
# It replaces the obsolete flushall_build_and_run.sh which referenced
# the removed obp-http4s-runner module and Jetty server.
#
# Usage:
# ./build_and_run.sh - Build and run with Redis flush
# ./build_and_run.sh --no-flush - Build and run without Redis flush
# ./build_and_run.sh --background - Run server in background
#
# The HTTP4S server runs on the port configured in your props file
# (default: 8080 for dev.port, or 8086 for hostname port)
################################################################################
set -e # Exit on error
# Parse arguments
FLUSH_REDIS=true
RUN_BACKGROUND=false
for arg in "$@"; do
case $arg in
--no-flush)
FLUSH_REDIS=false
echo ">>> Skipping Redis flush"
;;
--background)
RUN_BACKGROUND=true
echo ">>> Server will run in background"
;;
esac
done
################################################################################
# FLUSH REDIS CACHE (OPTIONAL)
################################################################################
if [ "$FLUSH_REDIS" = true ]; then
echo "=========================================="
echo "Flushing Redis cache..."
echo "=========================================="
if command -v redis-cli &> /dev/null; then
redis-cli <<EOF
flushall
exit
EOF
if [ $? -eq 0 ]; then
echo "✓ Redis cache flushed successfully"
else
echo "⚠ Warning: Failed to flush Redis cache. Continuing anyway..."
fi
else
echo "⚠ Warning: redis-cli not found. Skipping Redis flush..."
fi
echo ""
fi
################################################################################
# BUILD PROJECT
################################################################################
echo "=========================================="
echo "Building OBP-API with Maven..."
echo "=========================================="
# Maven options for build performance
# Memory:
# - 3-6GB heap (balanced for both Maven and Scala compiler)
# - 2GB metaspace for class metadata
# - 4m stack for Scala compiler (matches POM config)
#
# JVM Optimizations:
# - G1GC: Better garbage collection for large heaps
# - ReservedCodeCacheSize: More space for JIT compiled code
# - TieredCompilation: Faster JIT compilation
# - TieredStopAtLevel=1: Skip C2 compiler for faster startup (build-time only)
#
# Java Module Opens:
# - Required for Java 11+ compatibility
export MAVEN_OPTS="-Xms3G -Xmx6G -XX:MaxMetaspaceSize=2G -Xss4m \
-XX:+UseG1GC \
-XX:ReservedCodeCacheSize=512m \
-XX:+TieredCompilation \
-XX:TieredStopAtLevel=1 \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang.invoke=ALL-UNNAMED \
--add-opens java.base/java.util.jar=ALL-UNNAMED \
--add-opens java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED"
echo "Maven Options: ${MAVEN_OPTS}"
echo ""
# Build obp-api module (includes obp-commons as dependency)
# - clean: Remove old build artifacts
# - package: Compile and create JAR with maven-shade-plugin
# - -pl obp-api -am: Build obp-api and all required modules
# - -DskipTests: Skip test execution for faster builds
# - -T 4: Use 4 threads for parallel compilation
echo "Building obp-api module..."
echo "Build output will be saved to: build.log"
mvn -pl obp-api -am clean package -DskipTests=true -Dmaven.test.skip=true -T 4 > build.log 2>&1
if [ $? -ne 0 ]; then
echo ""
echo "❌ Build failed! Please check build.log for details."
echo "Last 30 lines of build log:"
tail -30 build.log
exit 1
fi
echo ""
echo "✓ Build completed successfully"
echo "✓ JAR created: obp-api/target/obp-api.jar"
echo "✓ Build log saved to: build.log"
echo ""
################################################################################
# RUN HTTP4S SERVER
################################################################################
echo "=========================================="
if [ "$RUN_BACKGROUND" = true ]; then
echo "Starting HTTP4S server (background)..."
else
echo "Starting HTTP4S server (foreground)..."
fi
echo "=========================================="
# Java options for runtime
# - Module opens for Kryo serialization and reflection
JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang.invoke=ALL-UNNAMED \
--add-opens java.base/java.util.jar=ALL-UNNAMED \
--add-opens java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED"
if [ "$RUN_BACKGROUND" = true ]; then
# Run in background with output to log file
nohup java $JAVA_OPTS -jar obp-api/target/obp-api.jar > http4s-server.log 2>&1 &
SERVER_PID=$!
echo "✓ HTTP4S server started in background"
echo " PID: $SERVER_PID"
echo " Log: http4s-server.log"
echo ""
echo "To stop the server: kill $SERVER_PID"
echo "To view logs: tail -f http4s-server.log"
else
# Run in foreground (Ctrl+C to stop)
echo "Press Ctrl+C to stop the server"
echo ""
java $JAVA_OPTS -jar obp-api/target/obp-api.jar
fi