Saturday, April 20, 2019

Wildfly + Graylog + Docker

Dockerfile
FROM jboss/wildfly
MAINTAINER Andrzej Szywala 
ADD gelf-module $JBOSS_HOME/modules/system/layers/base/
ADD execute.sh $JBOSS_HOME/execute.sh
ADD gelf.cli $JBOSS_HOME/gelf.cli

ENV GRAYLOG_URL=""
ENV GRAYLOG_PORT=""
ENV APP="hellojee"
ENV APPVER="1.0"

RUN cp $JBOSS_HOME/standalone/configuration/standalone.xml $JBOSS_HOME/standalone/configuration/standalone-gelf.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-ha.xml $JBOSS_HOME/standalone/configuration/standalone-ha-gelf.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full.xml $JBOSS_HOME/standalone/configuration/standalone-full-gelf.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full-ha.xml $JBOSS_HOME/standalone/configuration/standalone-full-ha-gelf.xml

ENV CONFIG_XML standalone-full-ha-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
ENV CONFIG_XML standalone-full-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
ENV CONFIG_XML standalone-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
ENV CONFIG_XML standalone-ha-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
# WFLYCTL0056: Could not rename /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current to /opt/coig/wildfly/standalone/configuration/standalone_xml_history/20180415-085446266: java.nio.file.DirectoryNotEmptyException: /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current
RUN rm -R $JBOSS_HOME/standalone/configuration/standalone_xml_history
ENTRYPOINT $JBOSS_HOME/execute.sh
gelf.cli
embed-server --server-config=${env.CONFIG_XML}
batch 
/subsystem=logging/custom-handler="GelfLogger":add(class="biz.paluch.logging.gelf.wildfly.WildFlyGelfLogHandler", module="biz.paluch.logging",properties={"host"=>"${env.GRAYLOG_URL}","port"=>"${env.GRAYLOG_PORT}","version"=>"1.1","facility"=>"java-test","extractStackTrace"=>"true","filterStackTrace"=>"true","mdcProfiling"=>"true","timestampPattern"=>"yyyy-MM-dd HH:mm:ss,SSSS","maximumMessageSize"=>"8192", "additionalFields"=>"APP=${env.APP},APPVER=${env.APPVER}"})
/subsystem=logging/root-logger=ROOT:add-handler(name=GelfLogger)
/subsystem=logging/root-logger=ROOT:remove-handler(name=CONSOLE)
/subsystem=logging/root-logger=ROOT:remove-handler(name=FILE)
# Execute the batch
run-batch
stop-embedded-server
quit
execute.sh
#!/bin/bash
JBOSS_CLI=$JBOSS_HOME/bin/jboss-cli.sh
JBOSS_CONFIG=${JBOSS_CONFIG:-"standalone.xml"}

exec $JBOSS_HOME/bin/standalone.sh -b `hostname -i` -c $JBOSS_CONFIG 
exit $?
Build image
docker build -t gelf .
Run image
docker run -it -e "GRAYLOG_URL=udp:graylog.example.com" -e "GRAYLOG_PORT=12203" -e "JBOSS_CONFIG=standalone-gelf.xml" -p 8080:8080 gelf
Sources: https://github.com/andrzejszywala/docker-images/tree/master/gelf

Sunday, April 14, 2019

Access log in Wildfly on Docker

Dockerfile
FROM jboss/wildfly
MAINTAINER Andrzej Szywala 
ADD acl.cli $JBOSS_HOME/acl.cli
ADD execute.sh $JBOSS_HOME/execute.sh

RUN cp $JBOSS_HOME/standalone/configuration/standalone.xml $JBOSS_HOME/standalone/configuration/standalone-acl.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-ha.xml $JBOSS_HOME/standalone/configuration/standalone-ha-acl.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full.xml $JBOSS_HOME/standalone/configuration/standalone-full-acl.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full-ha.xml $JBOSS_HOME/standalone/configuration/standalone-full-ha-acl.xml

ENV CONFIG_XML standalone-full-ha-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
ENV CONFIG_XML standalone-full-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
ENV CONFIG_XML standalone-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
ENV CONFIG_XML standalone-ha-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
# WFLYCTL0056: Could not rename /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current to /opt/coig/wildfly/standalone/configuration/standalone_xml_history/20180415-085446266: java.nio.file.DirectoryNotEmptyException: /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current
RUN rm -R $JBOSS_HOME/standalone/configuration/standalone_xml_history
ENTRYPOINT $JBOSS_HOME/execute.sh
acl.cli
embed-server --server-config=${env.CONFIG_XML}
batch 
/subsystem=undertow/server=default-server/host=default-host/setting=access-log:add(use-server-log=true)
# Execute the batch
run-batch
stop-embedded-server
quit
execute.sh
#!/bin/bash
JBOSS_CLI=$JBOSS_HOME/bin/jboss-cli.sh
JBOSS_CONFIG=${JBOSS_CONFIG:-"standalone.xml"}

exec $JBOSS_HOME/bin/standalone.sh -b `hostname -i` -c $JBOSS_CONFIG 
exit $?
Build image
docker build -t acl .
Run image
docker run -it -e "JBOSS_CONFIG=standalone-acl.xml" -p 8080:8080 acl
https://github.com/andrzejszywala/docker-images/tree/master/gelf