100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Entrypoint changes affecting heap dump storage and `OR_JAVA_OPTS` (#2868)
Rich Turner0bc842f346dc
diff --git a/balena/entrypoint.sh b/balena/entrypoint.shnew file mode 100644index 000000000..4f8903048--- /dev/null+++ b/balena/entrypoint.sh@@ -0,0 +1,13 @@+#!/bin/sh+# Rename any heap dump left from a previous run (in case OnOutOfMemoryError script didn't run)+if [ -f /storage/dump.hprof ]; then+ TIMESTAMP=$(date +%Y%m%d_%H%M%S)+ mv /storage/dump.hprof "/storage/dump_${TIMESTAMP}.hprof"+fi+# Warn if any heap dumps are present+HEAP_DUMPS=$(ls /storage/dump_*.hprof 2>/dev/null)+if [ -n "$HEAP_DUMPS" ]; then+ echo "WARNING: Heap dump(s) found in /storage - remove them to free up disk space:"+ ls -lh /storage/dump_*.hprof+fi+exec java ${JAVA_OPTS} ${JAVA_OPTS_APPEND} -cp "/opt/app/lib/*:/deployment/manager/extensions/*" org.openremote.manager.Maindiff --git a/balena/heapdump-rename.sh b/balena/heapdump-rename.shnew file mode 100644index 000000000..d74e0bc88--- /dev/null+++ b/balena/heapdump-rename.sh@@ -0,0 +1,3 @@+#!/bin/sh+TIMESTAMP=$(date +%Y%m%d_%H%M%S)+mv /storage/dump.hprof "/storage/dump_${TIMESTAMP}.hprof" 2>/dev/null || truediff --git a/balena/manager.Dockerfile b/balena/manager.Dockerfileindex c17ab42bc..c0233e9b2 100644--- a/balena/manager.Dockerfile+++ b/balena/manager.Dockerfile@@ -56,10 +56,16 @@ ENV OR_IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES ${OR_IDENTITY_SESSION_OFFLINE_TIENV OR_ATTRIBUTE_EVENT_THREADS ${OR_ATTRIBUTE_EVENT_THREADS}ENV OR_STORAGE_DIR ${OR_STORAGE_DIR:-/storage}ENV OR_GATEWAY_TUNNEL_LOCALHOST_REWRITE ${OR_GATEWAY_TUNNEL_LOCALHOST_REWRITE:-172.17.0.1}-ENV OR_JAVA_OPTS ${OR_JAVA_OPTS:--Xms500m -Xmx2g \++ARG JAVA_OPTS="-XX:InitialRAMPercentage=75.0 -XX:MaxRAMPercentage=75.0 \-XX:NativeMemoryTracking=summary \-Xlog:all=warning:stdout:uptime,level,tags \- -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof}+ -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/storage/dump.hprof \+ -XX:OnOutOfMemoryError=/heapdump-rename.sh"+ENV JAVA_OPTS=${JAVA_OPTS}++ARG JAVA_OPTS_APPEND+ENV JAVA_OPTS_APPEND=${JAVA_OPTS_APPEND}# OpenMetrics _created series breaks cloudwatch prometheus scraperENV PROMETHEUS_DISABLE_CREATED_SERIES ${PROMETHEUS_DISABLE_CREATED_SERIES:-true}@@ -77,5 +83,10 @@ ADD ./manager-build/map /opt/mapEXPOSE 8080EXPOSE 1883-HEALTHCHECK --interval=3s --timeout=60s --start-period=30s --retries=120 CMD curl --fail --silent http://localhost:8080 || exit 1-ENTRYPOINT java $OR_JAVA_OPTS -cp /opt/app/lib/*:/deployment/manager/extensions/* org.openremote.manager.Main+HEALTHCHECK --interval=5s --timeout=60s --start-period=5s --retries=120 CMD curl --fail --silent http://localhost:8080 || exit 1++COPY entrypoint.sh /entrypoint.sh+RUN chmod +x /entrypoint.sh+COPY heapdump-rename.sh /heapdump-rename.sh+RUN chmod +x /heapdump-rename.sh+ENTRYPOINT ["/entrypoint.sh"]diff --git a/manager/Dockerfile b/manager/Dockerfileindex 889693786..cbea68fe7 100644--- a/manager/Dockerfile+++ b/manager/Dockerfile@@ -145,11 +145,15 @@ ENV OR_STORAGE_DIR=${OR_STORAGE_DIR}ARG OR_GATEWAY_TUNNEL_LOCALHOST_REWRITE=172.17.0.1ENV OR_GATEWAY_TUNNEL_LOCALHOST_REWRITE=${OR_GATEWAY_TUNNEL_LOCALHOST_REWRITE}-ARG OR_JAVA_OPTS="-Xms500m -Xmx2g \+ARG JAVA_OPTS="-XX:InitialRAMPercentage=75.0 -XX:MaxRAMPercentage=75.0 \-XX:NativeMemoryTracking=summary \-Xlog:all=warning:stdout:uptime,level,tags \- -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof"-ENV OR_JAVA_OPTS=${OR_JAVA_OPTS}+ -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/storage/dump.hprof \+ -XX:OnOutOfMemoryError=/heapdump-rename.sh"+ENV JAVA_OPTS=${JAVA_OPTS}++ARG JAVA_OPTS_APPEND+ENV JAVA_OPTS_APPEND=${JAVA_OPTS_APPEND}# OpenMetrics _created series breaks cloudwatch prometheus scraperARG PROMETHEUS_DISABLE_CREATED_SERIES=true@@ -172,4 +176,6 @@ HEALTHCHECK --interval=5s --timeout=60s --start-period=5s --retries=120 CMD curlCOPY entrypoint.sh /entrypoint.shRUN chmod +x /entrypoint.sh+COPY heapdump-rename.sh /heapdump-rename.sh+RUN chmod +x /heapdump-rename.shENTRYPOINT ["/entrypoint.sh"]diff --git a/manager/build.gradle b/manager/build.gradleindex cced2e00a..b97d99f88 100644--- a/manager/build.gradle+++ b/manager/build.gradle@@ -106,7 +106,7 @@ distributions {main {contents {from(project.projectDir) {- include("*Dockerfile", "entrypoint.sh")+ include("*Dockerfile", "entrypoint.sh", "heapdump-rename.sh")}into ("web") {from("${rootDir}/LICENSE.txt")diff --git a/manager/entrypoint.sh b/manager/entrypoint.shindex 364d69ee3..4f8903048 100644--- a/manager/entrypoint.sh+++ b/manager/entrypoint.sh@@ -1,2 +1,13 @@#!/bin/sh-exec java ${OR_JAVA_OPTS} -cp "/opt/app/lib/*:/deployment/manager/extensions/*" org.openremote.manager.Main+# Rename any heap dump left from a previous run (in case OnOutOfMemoryError script didn't run)+if [ -f /storage/dump.hprof ]; then+ TIMESTAMP=$(date +%Y%m%d_%H%M%S)+ mv /storage/dump.hprof "/storage/dump_${TIMESTAMP}.hprof"+fi+# Warn if any heap dumps are present+HEAP_DUMPS=$(ls /storage/dump_*.hprof 2>/dev/null)+if [ -n "$HEAP_DUMPS" ]; then+ echo "WARNING: Heap dump(s) found in /storage - remove them to free up disk space:"+ ls -lh /storage/dump_*.hprof+fi+exec java ${JAVA_OPTS} ${JAVA_OPTS_APPEND} -cp "/opt/app/lib/*:/deployment/manager/extensions/*" org.openremote.manager.Maindiff --git a/manager/heapdump-rename.sh b/manager/heapdump-rename.shnew file mode 100644index 000000000..d74e0bc88--- /dev/null+++ b/manager/heapdump-rename.sh@@ -0,0 +1,3 @@+#!/bin/sh+TIMESTAMP=$(date +%Y%m%d_%H%M%S)+mv /storage/dump.hprof "/storage/dump_${TIMESTAMP}.hprof" 2>/dev/null || truediff --git a/profile/deploy.yml b/profile/deploy.ymlindex 77755c5d0..a32be0380 100644--- a/profile/deploy.yml+++ b/profile/deploy.yml@@ -363,11 +363,9 @@ services:# When using path based proxying this prefix is added to the URLs returned via the REST API.# OR_PATH_PREFIX: /openremote- # Custom JVM options (override default manager options)- #OR_JAVA_OPTS: ${OR_JAVA_OPTS:--Xms500m -Xmx2g- # -XX:NativeMemoryTracking=summary- # -Xlog:all=warning:stdout:uptime,level,tags- # -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof}+ # Custom JVM options (override default manager options or append using JAVA_OPTS_APPEND)+ #JAVA_OPTS:+ #JAVA_OPTS_APPEND:## THE FOLLOWING OPTIONS CAN BE USED TO ENABLE JMX; PORT MUST ALSO BE EXPOSED# ACCESS SHOULD BE RESTRICTED BY FIREWALL TO SPECIFIC IPs FOR DIAGNOSTIC PURPOSESdiff --git a/test/load1-eks/values-manager-eks-load.yaml b/test/load1-eks/values-manager-eks-load.yamlindex 9f4b6696a..29e525106 100644--- a/test/load1-eks/values-manager-eks-load.yaml+++ b/test/load1-eks/values-manager-eks-load.yaml@@ -36,5 +36,5 @@ or:value: "10000"- name: OR_SETUP_DEVICES_SKIP_COUNTvalue: "100"- - name: OR_JAVA_OPTS- value: "-Dhibernate.generate_statistics=true -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof"+ - name: JAVA_OPTS_APPEND+ value: "-Dhibernate.generate_statistics=true"diff --git a/test/load1/deployment1/test-load1.yml b/test/load1/deployment1/test-load1.ymlindex 99b2630ed..15860022f 100644--- a/test/load1/deployment1/test-load1.yml+++ b/test/load1/deployment1/test-load1.yml@@ -94,7 +94,6 @@ services:OR_SETUP_DEVICES_SKIP_COUNT:OR_METRICS_ENABLED: trueOR_EXECUTOR_THREADS_MAX:- OR_JAVA_OPTS: ${OR_JAVA_OPTS:--Xms500m -Xmx4g -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof}volumes:- manager-data:/storage- ./manager:/deployment/managerdiff --git a/test/load2-eks/profiles/2xlarge/values-manager-eks-load.yaml b/test/load2-eks/profiles/2xlarge/values-manager-eks-load.yamlindex 1526e0093..8a59a0773 100644--- a/test/load2-eks/profiles/2xlarge/values-manager-eks-load.yaml+++ b/test/load2-eks/profiles/2xlarge/values-manager-eks-load.yaml@@ -51,7 +51,7 @@ or:value: "500"- name: OR_SETUP_STORE_DATA_POINTSvalue: "false"- - name: OR_JAVA_OPTS- value: "-Dhibernate.generate_statistics=true -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"+ - name: JAVA_OPTS_APPEND+ value: "-Dhibernate.generate_statistics=true -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"- name: JAVA_TOOL_OPTIONSvalue: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8085 -Dcom.sun.management.jmxremote.rmi.port=8085 -Djava.rmi.server.hostname=localhost"diff --git a/test/load2-eks/profiles/4xlarge/values-manager-eks-load.yaml b/test/load2-eks/profiles/4xlarge/values-manager-eks-load.yamlindex 68350776e..c754d353a 100644--- a/test/load2-eks/profiles/4xlarge/values-manager-eks-load.yaml+++ b/test/load2-eks/profiles/4xlarge/values-manager-eks-load.yaml@@ -51,7 +51,7 @@ or:value: "500"- name: OR_SETUP_STORE_DATA_POINTSvalue: "false"- - name: OR_JAVA_OPTS- value: "-Dhibernate.generate_statistics=true -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"+ - name: JAVA_OPTS_APPEND+ value: "-Dhibernate.generate_statistics=true -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"- name: JAVA_TOOL_OPTIONSvalue: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8085 -Dcom.sun.management.jmxremote.rmi.port=8085 -Djava.rmi.server.hostname=localhost"diff --git a/test/load2-eks/profiles/8xlarge/values-manager-eks-load.yaml b/test/load2-eks/profiles/8xlarge/values-manager-eks-load.yamlindex 3e5782d70..427e5557f 100644--- a/test/load2-eks/profiles/8xlarge/values-manager-eks-load.yaml+++ b/test/load2-eks/profiles/8xlarge/values-manager-eks-load.yaml@@ -51,7 +51,7 @@ or:value: "500"- name: OR_SETUP_STORE_DATA_POINTSvalue: "false"- - name: OR_JAVA_OPTS- value: "-Dhibernate.generate_statistics=true -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"+ - name: JAVA_OPTS_APPEND+ value: "-Dhibernate.generate_statistics=true -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"- name: JAVA_TOOL_OPTIONSvalue: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8085 -Dcom.sun.management.jmxremote.rmi.port=8085 -Djava.rmi.server.hostname=localhost"diff --git a/test/load2-eks/profiles/large/values-manager-eks-load.yaml b/test/load2-eks/profiles/large/values-manager-eks-load.yamlindex 3af039041..cc315bf1d 100644--- a/test/load2-eks/profiles/large/values-manager-eks-load.yaml+++ b/test/load2-eks/profiles/large/values-manager-eks-load.yaml@@ -51,7 +51,7 @@ or:value: "500"- name: OR_SETUP_STORE_DATA_POINTSvalue: "false"- - name: OR_JAVA_OPTS- value: "-Dhibernate.generate_statistics=true -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"+ - name: JAVA_OPTS_APPEND+ value: "-Dhibernate.generate_statistics=true -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"- name: JAVA_TOOL_OPTIONSvalue: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8085 -Dcom.sun.management.jmxremote.rmi.port=8085 -Djava.rmi.server.hostname=localhost"diff --git a/test/load2-eks/profiles/xlarge-minimal/values-manager-eks-load.yaml b/test/load2-eks/profiles/xlarge-minimal/values-manager-eks-load.yamlindex 0aad201cb..6cf3aa181 100644--- a/test/load2-eks/profiles/xlarge-minimal/values-manager-eks-load.yaml+++ b/test/load2-eks/profiles/xlarge-minimal/values-manager-eks-load.yaml@@ -51,7 +51,7 @@ or:value: "500"- name: OR_SETUP_STORE_DATA_POINTSvalue: "false"- - name: OR_JAVA_OPTS- value: "-Dhibernate.generate_statistics=true -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"+ - name: JAVA_OPTS_APPEND+ value: "-Dhibernate.generate_statistics=true -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"- name: JAVA_TOOL_OPTIONSvalue: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8085 -Dcom.sun.management.jmxremote.rmi.port=8085 -Djava.rmi.server.hostname=localhost"diff --git a/test/load2-eks/profiles/xlarge/values-manager-eks-load.yaml b/test/load2-eks/profiles/xlarge/values-manager-eks-load.yamlindex 8453d1042..630e99f72 100644--- a/test/load2-eks/profiles/xlarge/values-manager-eks-load.yaml+++ b/test/load2-eks/profiles/xlarge/values-manager-eks-load.yaml@@ -51,7 +51,7 @@ or:value: "500"- name: OR_SETUP_STORE_DATA_POINTSvalue: "false"- - name: OR_JAVA_OPTS- value: "-Dhibernate.generate_statistics=true -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XX:NativeMemoryTracking=summary -Xlog:all=warning:stdout:uptime,level,tags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"+ - name: JAVA_OPTS_APPEND+ value: "-Dhibernate.generate_statistics=true -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=debug,safepoint:file=gc.log"- name: JAVA_TOOL_OPTIONSvalue: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8085 -Dcom.sun.management.jmxremote.rmi.port=8085 -Djava.rmi.server.hostname=localhost"diff --git a/ui/test/manager.cjs b/ui/test/manager.cjsindex e74f9b9b1..36f45254b 100755--- a/ui/test/manager.cjs+++ b/ui/test/manager.cjs@@ -26,16 +26,17 @@ console.log("Starting OpenRemote Manager...");console.log(`Classpath: ${classPath}`);// --- Prepare Java arguments ----// We split OR_JAVA_OPTS by space if it exists, or use the default JVM options defined in our Dockerfile-const javaOpts = process.env.OR_JAVA_OPTS ? process.env.OR_JAVA_OPTS.split(" ") : [- "-Xms500m",- "-Xmx2g",+// We split JAVA_OPTS by space if it exists, or use the default JVM options defined in our Dockerfile+const javaOpts = process.env.JAVA_OPTS ? process.env.JAVA_OPTS.split(" ") : [+ "-XX:InitialRAMPercentage=75.0",+ "-XX:MaxRAMPercentage=75.0","-XX:NativeMemoryTracking=summary","-Xlog:all=warning:stdout:uptime,level,tags","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=./dump.hprof",];-const args = [...javaOpts, "-cp", classPath, "org.openremote.manager.Main"];+const javaOptsAppend = process.env.JAVA_OPTS_APPEND ? process.env.JAVA_OPTS_APPEND.split(" ") : []+const args = [...javaOpts, ...javaOptsAppend, "-cp", classPath, "org.openremote.manager.Main"];// --- Execute Java ---const child = spawn("java", args, {