IOT-3244 configurable JMX_HOSTNAME 33/27633/1
authorPeter Rafaj <peter.rafaj@kistler.com>
Mon, 3 Dec 2018 08:39:14 +0000 (09:39 +0100)
committerPeter Rafaj <peter.rafaj@kistler.com>
Mon, 3 Dec 2018 08:43:37 +0000 (09:43 +0100)
Change-Id: I707c2db52492f7585aed307f3a47c6e14824c0b3
Signed-off-by: Peter Rafaj <peter.rafaj@kistler.com>
cloud/account/Dockerfile
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServer.java
cloud/account/start.sh [new file with mode: 0755]
cloud/interface/Dockerfile
cloud/interface/start.sh [new file with mode: 0755]
cloud/messagequeue/Dockerfile
cloud/messagequeue/start.sh [new file with mode: 0755]
cloud/resourcedirectory/Dockerfile
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/ResourceDirectoryServer.java
cloud/resourcedirectory/start.sh [new file with mode: 0755]

index e20c9bd..0f10b80 100644 (file)
@@ -2,11 +2,16 @@ FROM openjdk:8-jre-alpine
 
 RUN apk add --update \
     curl \
+    shadow \
     && rm -rf /var/cache/apk/*
 
-ADD ./target/CloudAccount-0.0.1-SNAPSHOT.jar iotivity/AccountServer.jar
-ADD ./target/lib/* iotivity/lib/
-ADD ./properties/* iotivity/properties/
+RUN groupadd -r iotivity && useradd --no-log-init --system  -g iotivity iotivity
+
+COPY --chown=iotivity:iotivity ./target/CloudAccount-0.0.1-SNAPSHOT.jar iotivity/AccountServer.jar
+COPY --chown=iotivity:iotivity ./target/lib/* iotivity/lib/
+COPY --chown=iotivity:iotivity ./properties/* iotivity/properties/
+COPY --chown=iotivity:iotivity  ./start.sh iotivity/
+RUN chmod +x iotivity/start.sh
 
 WORKDIR iotivity/
 
@@ -18,17 +23,11 @@ ENV MONGODB_PORT 27017
 
 
 ENV JMX_PORT 9002
-ENV JAVA_JMX_OPTS "-Dcom.sun.management.jmxremote \
-               -Dcom.sun.management.jmxremote.port=${JMX_PORT} \
-               -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} \
-               -Dcom.sun.management.jmxremote.local.only=false \
-               -Dcom.sun.management.jmxremote.authenticate=false \
-               -Dcom.sun.management.jmxremote.ssl=false \
-               -Djava.rmi.server.hostname= \
-               -XX:MetaspaceSize=30m -XX:MaxMetaspaceSize=40m \
-               -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -server "
+ENV JMX_HOSTNAME ""
+ENV JAVA_MEMORY_OPTS ""
 
 EXPOSE 9002
 
-ENTRYPOINT exec java $JAVA_JMX_OPTS $JAVA_MEMORY_OPTS -jar AccountServer.jar
-HEALTHCHECK --interval=30s --timeout=2s --retries=3    CMD curl -f http://localhost/api/healthcheck || exit 1
+USER iotivity
+ENTRYPOINT [ "./start.sh" ]
+HEALTHCHECK --interval=30s --timeout=2s --retries=3    CMD curl -f http://localhost:8000/api/healthcheck || exit 1
index 6beea9c..934cfc4 100644 (file)
@@ -94,7 +94,7 @@ public class AccountServer {
                 new CoapServer(new InetSocketAddress(coapServerPort)));
 
         if(healthCheckEnabled){
-            serverSystem.addServer(new SimpleHttpServer(new InetSocketAddress(80),healthHolder));
+            serverSystem.addServer(new SimpleHttpServer(new InetSocketAddress(8000),healthHolder));
         }
 
         serverSystem.startSystem(tlsMode);
diff --git a/cloud/account/start.sh b/cloud/account/start.sh
new file mode 100755 (executable)
index 0000000..0ae9417
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+JAVA_OPTS="$JAVA_OPTS "
+if [ ! -z "$JAVA_MEMORY_OPTS" ]; then
+    JAVA_OPTS="$JAVA_OPTS $JAVA_MEMORY_OPTS"
+fi
+
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.local.only=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false "
+
+if [ ! -z "$JMX_HOSTNAME" ]; then
+   JAVA_OPTS="$JAVA_OPTS  -Djava.rmi.server.hostname=${JMX_HOSTNAME} "
+fi
+
+JAVA_OPTS="$JAVA_OPTS -XX:MetaspaceSize=30m "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=40m "
+JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=100 "
+JAVA_OPTS="$JAVA_OPTS -server "
+
+export JAVA_OPTS
+echo "Start Account server service with option: ${JAVA_OPTS}"
+exec java $JAVA_OPTS -jar AccountServer.jar
index 4f012cd..c42b8be 100644 (file)
@@ -1,7 +1,14 @@
 FROM openjdk:8-jre-alpine
 
-ADD ./target/CloudInterface-0.0.1-SNAPSHOT.jar iotivity/CloudInterface.jar
-ADD ./target/lib/* iotivity/lib/
+RUN apk add --update \
+    shadow \
+    && rm -rf /var/cache/apk/*
+
+RUN groupadd -r iotivity && useradd --no-log-init --system  -g iotivity iotivity
+
+COPY --chown=iotivity:iotivity  ./target/CloudInterface-0.0.1-SNAPSHOT.jar iotivity/CloudInterface.jar
+COPY --chown=iotivity:iotivity  ./target/lib/* iotivity/lib/
+COPY --chown=iotivity:iotivity  ./start.sh iotivity/
 
 WORKDIR iotivity/
 
@@ -17,16 +24,10 @@ ENV ACCOUNT_SERVER_ADDRESS iotivity-accountserver
 ENV ACCOUNT_SERVER_PORT 5685
 
 ENV JMX_PORT 9001
-ENV JAVA_JMX_OPTS "-Dcom.sun.management.jmxremote \
-                -Dcom.sun.management.jmxremote.port=${JMX_PORT} \
-                -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} \
-                -Dcom.sun.management.jmxremote.local.only=false \
-                -Dcom.sun.management.jmxremote.authenticate=false \
-                -Dcom.sun.management.jmxremote.ssl=false \
-                -Djava.rmi.server.hostname= \
-                -XX:MetaspaceSize=20m -XX:MaxMetaspaceSize=25m \
-                -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -server "
+ENV JMX_HOSTNAME ""
+ENV JAVA_MEMORY_OPTS ""
 
 EXPOSE 9001
 
-ENTRYPOINT exec java $JAVA_JMX_OPTS $JAVA_MEMORY_OPTS -jar CloudInterface.jar
+USER iotivity
+ENTRYPOINT [ "./start.sh" ]
diff --git a/cloud/interface/start.sh b/cloud/interface/start.sh
new file mode 100755 (executable)
index 0000000..2c0c5a6
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+JAVA_OPTS="$JAVA_OPTS "
+if [ ! -z "$JAVA_MEMORY_OPTS" ]; then
+    JAVA_OPTS="$JAVA_OPTS $JAVA_MEMORY_OPTS"
+fi
+
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.local.only=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false "
+
+if [ ! -z "$JMX_HOSTNAME" ]; then
+   JAVA_OPTS="$JAVA_OPTS  -Djava.rmi.server.hostname=${JMX_HOSTNAME} "
+fi
+
+JAVA_OPTS="$JAVA_OPTS -XX:MetaspaceSize=20m "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=30m "
+JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=100 "
+JAVA_OPTS="$JAVA_OPTS -server "
+
+export JAVA_OPTS
+echo "Start Interface service with option: ${JAVA_OPTS}"
+exec java $JAVA_OPTS -jar CloudInterface.jar
index 25823cd..3719fe2 100644 (file)
@@ -1,7 +1,14 @@
 FROM openjdk:8-jre-alpine
 
-ADD ./target/CloudMessageQueue-0.0.1-SNAPSHOT.jar iotivity/MessageQueue.jar
-ADD ./target/lib/* iotivity/lib/
+RUN apk add --update \
+    shadow \
+    && rm -rf /var/cache/apk/*
+
+RUN groupadd -r iotivity && useradd --no-log-init --system  -g iotivity iotivity
+
+COPY --chown=iotivity:iotivity  ./target/CloudMessageQueue-0.0.1-SNAPSHOT.jar iotivity/MessageQueue.jar
+COPY --chown=iotivity:iotivity  ./target/lib/* iotivity/lib/
+COPY --chown=iotivity:iotivity  ./start.sh iotivity/
 
 WORKDIR iotivity/
 
@@ -13,16 +20,11 @@ ENV KAFKA_ADDRESS kafka-zookeeper
 ENV KAFKA_PORT 9092
 
 ENV JMX_PORT 9003
-ENV JAVA_JMX_OPTS "-Dcom.sun.management.jmxremote \
-               -Dcom.sun.management.jmxremote.port=${JMX_PORT} \
-               -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} \
-               -Dcom.sun.management.jmxremote.local.only=false \
-               -Dcom.sun.management.jmxremote.authenticate=false \
-               -Dcom.sun.management.jmxremote.ssl=false \
-               -Djava.rmi.server.hostname= \
-               -XX:MetaspaceSize=20m -XX:MaxMetaspaceSize=25m \
-               -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -server "
+ENV JMX_HOSTNAME ""
+ENV JAVA_MEMORY_OPTS ""
 
 EXPOSE 9003
 
-ENTRYPOINT exec java $JAVA_JMX_OPTS $JAVA_MEMORY_OPTS -jar MessageQueue.jar
+USER iotivity
+ENTRYPOINT [ "./start.sh" ]
+
diff --git a/cloud/messagequeue/start.sh b/cloud/messagequeue/start.sh
new file mode 100755 (executable)
index 0000000..9120535
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+JAVA_OPTS="$JAVA_OPTS "
+if [ ! -z "$JAVA_MEMORY_OPTS" ]; then
+    JAVA_OPTS="$JAVA_OPTS $JAVA_MEMORY_OPTS"
+fi
+
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.local.only=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false "
+
+if [ ! -z "$JMX_HOSTNAME" ]; then
+   JAVA_OPTS="$JAVA_OPTS  -Djava.rmi.server.hostname=${JMX_HOSTNAME} "
+fi
+
+JAVA_OPTS="$JAVA_OPTS -XX:MetaspaceSize=20m "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=30m "
+JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=100 "
+JAVA_OPTS="$JAVA_OPTS -server "
+
+export JAVA_OPTS
+echo "Start Message queue service with option: ${JAVA_OPTS}"
+exec java $JAVA_OPTS -jar MessageQueue.jar
index 1fddd08..0e3cfb3 100644 (file)
@@ -2,10 +2,14 @@ FROM openjdk:8-jre-alpine
 
 RUN apk add --update \
     curl \
+    shadow \
     && rm -rf /var/cache/apk/*
 
-ADD ./target/CloudResourceDirectory-0.0.1-SNAPSHOT.jar iotivity/ResourceDirectory.jar
-ADD ./target/lib/* iotivity/lib/
+RUN groupadd -r iotivity && useradd --no-log-init --system  -g iotivity iotivity
+
+COPY --chown=iotivity:iotivity ./target/CloudResourceDirectory-0.0.1-SNAPSHOT.jar iotivity/ResourceDirectory.jar
+COPY --chown=iotivity:iotivity ./target/lib/* iotivity/lib/
+COPY --chown=iotivity:iotivity ./start.sh iotivity/
 
 WORKDIR iotivity/
 
@@ -16,17 +20,11 @@ ENV MONGODB_ADDRESS mongodb
 ENV MONGODB_PORT 27017
 
 ENV JMX_PORT 9004
-ENV JAVA_JMX_OPTS "-Dcom.sun.management.jmxremote \
-               -Dcom.sun.management.jmxremote.port=${JMX_PORT} \
-               -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} \
-               -Dcom.sun.management.jmxremote.local.only=false \
-               -Dcom.sun.management.jmxremote.authenticate=false \
-               -Dcom.sun.management.jmxremote.ssl=false \
-               -Djava.rmi.server.hostname= \
-               -XX:MetaspaceSize=20m -XX:MaxMetaspaceSize=25m \
-               -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -server "
+ENV JMX_HOSTNAME ""
+ENV JAVA_MEMORY_OPTS ""
 
 EXPOSE 9004
 
-ENTRYPOINT exec java $JAVA_JMX_OPTS $JAVA_MEMORY_OPTS -jar ResourceDirectory.jar
-HEALTHCHECK --interval=30s --timeout=2s --retries=3    CMD curl -f http://localhost/api/healthcheck || exit 1
+USER iotivity
+ENTRYPOINT [ "./start.sh" ]
+HEALTHCHECK --interval=30s --timeout=2s --retries=3    CMD curl -f http://localhost:8000/api/healthcheck || exit 1
\ No newline at end of file
index 0f99c35..fd927d4 100644 (file)
@@ -74,7 +74,7 @@ public class ResourceDirectoryServer {
                 new CoapServer(new InetSocketAddress(coapServerPort)));
 
         if(healthCheckEnabled){
-            serverSystem.addServer(new SimpleHttpServer(new InetSocketAddress(80),healthHolder));
+            serverSystem.addServer(new SimpleHttpServer(new InetSocketAddress(8000),healthHolder));
         }
 
         serverSystem.startSystem(tlsMode);
diff --git a/cloud/resourcedirectory/start.sh b/cloud/resourcedirectory/start.sh
new file mode 100755 (executable)
index 0000000..df43803
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+JAVA_OPTS="$JAVA_OPTS "
+if [ ! -z "$JAVA_MEMORY_OPTS" ]; then
+    JAVA_OPTS="$JAVA_OPTS $JAVA_MEMORY_OPTS"
+fi
+
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.local.only=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false "
+
+if [ ! -z "$JMX_HOSTNAME" ]; then
+   JAVA_OPTS="$JAVA_OPTS  -Djava.rmi.server.hostname=${JMX_HOSTNAME} "
+fi
+
+JAVA_OPTS="$JAVA_OPTS -XX:MetaspaceSize=20m "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=30m "
+JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC "
+JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=100 "
+JAVA_OPTS="$JAVA_OPTS -server "
+
+export JAVA_OPTS
+echo "Start resource directory service with option: ${JAVA_OPTS}"
+exec java $JAVA_OPTS -jar ResourceDirectory.jar