Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #32 from docker/180401
add logging functionality, update tomcat
pcaskey committed Apr 3, 2018
2 parents 2e00d54 + ba02962 commit 6218276
Showing 7 changed files with 111 additions and 36 deletions.
27 changes: 22 additions & 5 deletions Dockerfile
@@ -10,11 +10,11 @@ ENV JAVA_VERSION=8u162 \
JAVA_BUNDLE_ID=0da788060d494f5095bf8624735fa2f1 \
##tomcat
TOMCAT_MAJOR=8 \
TOMCAT_VERSION=8.5.27 \
TOMCAT_VERSION=8.5.29 \
##shib-idp
VERSION=3.3.2 \
##TIER
TIERVERSION=18011 \
TIERVERSION=180401 \

##################
### OTHER VARS ###
@@ -34,6 +34,11 @@ ENV TOMCAT_TGZ_URL=https://www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOM
SHIB_RELDIR=http://shibboleth.net/downloads/identity-provider/$VERSION \
SHIB_PREFIX=shibboleth-identity-provider-$VERSION


ENV ENV=dev \
USERTOKEN=nothing


#set labels
LABEL Vendor="Internet2" \
ImageType="Shibboleth IDP Release" \
@@ -133,14 +138,27 @@ RUN mkdir -p "$CATALINA_HOME" && set -x \

ADD container_files/idp/idp.xml /usr/local/tomcat/conf/Catalina/idp.xml
ADD container_files/tomcat/server.xml /usr/local/tomcat/conf/server.xml


#use log4j for tomcat logging
ADD http://central.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.11.0/log4j-core-2.11.0.jar /usr/local/tomcat/bin/
ADD http://central.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.11.0/log4j-api-2.11.0.jar /usr/local/tomcat/bin/
ADD http://central.maven.org/maven2/org/apache/logging/log4j/log4j-jul/2.11.0/log4j-jul-2.11.0.jar /usr/local/tomcat/bin/
RUN cd /usr/local/tomcat/; \
chmod +r bin/log4j-*.jar; \
ADD container_files/tomcat/log4j2.xml /usr/local/tomcat/conf/
ADD container_files/tomcat/setenv.sh /usr/local/tomcat/bin/



# Copy TIER helper scripts
ADD container_files/system/startup.sh /usr/bin/
ADD container_files/bin/setenv.sh /opt/tier/setenv.sh
ADD container_files/bin/setupcron.sh /usr/bin/setupcron.sh
ADD container_files/bin/sendtierbeacon.sh /usr/bin/sendtierbeacon.sh
ADD container_files/system/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chmod +x /opt/tier/setenv.sh \
&& chmod +x /usr/bin/setupcron.sh \
&& chmod +x /usr/bin/startup.sh \
&& chmod +x /usr/bin/sendtierbeacon.sh \
# setup cron
&& /usr/bin/setupcron.sh
@@ -203,5 +221,4 @@ HEALTHCHECK --interval=2m --timeout=30s \
CMD curl -k -f https://127.0.0.1/idp/status || exit 1


# Start tomcat/crond via supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
CMD ["/usr/bin/startup.sh"]
1 change: 1 addition & 0 deletions container_files/bin/setenv.sh
@@ -3,3 +3,4 @@ printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^VERSION" > /opt/tier/env.bash
printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^TIERVERSION" >> /opt/tier/env.bash
printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^IMAGE" >> /opt/tier/env.bash
printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^MAINTAINER" >> /opt/tier/env.bash

25 changes: 0 additions & 25 deletions container_files/bin/startup.sh

This file was deleted.

49 changes: 49 additions & 0 deletions container_files/system/startup.sh
@@ -0,0 +1,49 @@
#!/bin/sh

#for passed-in env vars, remove spaces and replace any ; with : in usertoken env var since we will use ; as a delimiter
export USERTOKEN="${USERTOKEN//;/:}"
export USERTOKEN="${USERTOKEN// /}"
export ENV="${ENV//;/:}"
export ENV="${ENV// /}"

# generic console logging pipe for anyone
mkfifo -m 666 /tmp/logpipe
cat <> /tmp/logpipe 1>&2 &

mkfifo -m 666 /tmp/logcrond
(cat <> /tmp/logcrond | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "crond;console;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) &

mkfifo -m 666 /tmp/logtomcat
(cat <> /tmp/logtomcat | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "tomcat;console;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) &

mkfifo -m 666 /tmp/logsuperd
(cat <> /tmp/logsuperd | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "supervisord;console;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) &

mkfifo -m 666 /tmp/logidp-process
(cat <> /tmp/logidp-process | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "shib-idp;idp-process.log;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) &

mkfifo -m 666 /tmp/logidp-warn
(cat <> /tmp/logidp-warn | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "shib-idp;idp-warn.log;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) &

mkfifo -m 666 /tmp/logidp-audit
(cat <> /tmp/logidp-audit | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "shib-idp;idp-audit.log;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) &

mkfifo -m 666 /tmp/logidp-consent-audit
(cat <> /tmp/logidp-consent-audit | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "shib-idp;idp-consent-audit.log;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) &


# fix IdP's logback.xml to log to use above pipe
IDP_LOG_CFG_FILE=/opt/shibboleth-idp/conf/logback.xml
if test \! -f ${IDP_LOG_CFG_FILE}.dist; then
cp ${IDP_LOG_CFG_FILE} ${IDP_LOG_CFG_FILE}.dist
fi
sed "s#<File>\${idp.logfiles}/idp-process.log</File>#<File>/tmp/logidp-process</File>#" ${IDP_LOG_CFG_FILE}.dist > ${IDP_LOG_CFG_FILE}.tmp
sed "s#<File>\${idp.logfiles}/idp-warn.log</File>#<File>/tmp/logidp-warn</File>#" ${IDP_LOG_CFG_FILE}.tmp > ${IDP_LOG_CFG_FILE}.tmp2
sed "s#<File>\${idp.logfiles}/idp-audit.log</File>#<File>/tmp/logidp-audit</File>#" ${IDP_LOG_CFG_FILE}.tmp2 > ${IDP_LOG_CFG_FILE}.tmp3
sed "s#<File>\${idp.logfiles}/idp-consent-audit.log</File>#<File>/tmp/logidp-consent-audit</File>#" ${IDP_LOG_CFG_FILE}.tmp3 > ${IDP_LOG_CFG_FILE}
rm -f ${IDP_LOG_CFG_FILE}.tmp
rm -f ${IDP_LOG_CFG_FILE}.tmp2
rm -f ${IDP_LOG_CFG_FILE}.tmp

#launch supervisord
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
14 changes: 8 additions & 6 deletions container_files/system/supervisord.conf
@@ -1,23 +1,25 @@
[supervisord]
logfile=/tmp/logsuperd
logfile_maxbytes=0
loglevel=error
nodaemon=true
user=root

[program:cron]
command=/usr/sbin/crond -n
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile=/tmp/logcrond
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile=/tmp/logcrond
stderr_logfile_maxbytes=0
directory=/usr/bin

[program:tomcat]
command=/usr/local/tomcat/bin/catalina.sh run
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile=/tmp/logtomcat
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile=/tmp/logtomcat
stderr_logfile_maxbytes=0
27 changes: 27 additions & 0 deletions container_files/tomcat/log4j2.xml
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration status="info">
<Properties>
<Property name="layout">%d [%t] %-5p %c- %m%n</Property>
</Properties>
<Appenders>
<File name="CATALINA"
fileName="/tmp/logpipe">
<PatternLayout pattern="tomcat;catalina.out;${env:ENV};${env:USERTOKEN} ${layout}"/>
</File>
<File name="LOCALHOST"
fileName="/tmp/logpipe">
<PatternLayout pattern="tomcat;localhost.log;${env:ENV};${env:USERTOKEN} ${layout}"/>
</File>

</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="CATALINA"/>
</Root>
<Logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost]"
level="info" additivity="false">
<AppenderRef ref="LOCALHOST"/>
</Logger>
</Loggers>
</Configuration>

4 changes: 4 additions & 0 deletions container_files/tomcat/setenv.sh
@@ -0,0 +1,4 @@
CLASSPATH=/usr/local/tomcat/bin/*
JAVA_OPTS="-Dlog4j.configurationFile=/usr/local/tomcat/conf/log4j2.xml -DENV=$ENV -DUSERTOKEN=$USERTOKEN"
LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager

0 comments on commit 6218276

Please sign in to comment.