Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
Log everything to stdout as well
Browse files Browse the repository at this point in the history
* rootLogger sends log events to console appender that logs to stdout
* do not redirect the output of `server.sh` to a file
  • Loading branch information
ketan committed Aug 31, 2017
1 parent 047f319 commit 2b7c7c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Docker GoCD agent 17.9.0

* log agent output and logs to `STDOUT` in addition to writing logs to log files, so you can now watch all agent logs using `docker logs`.

# Docker GoCD agent 17.8.0

* [dc49b6d](https://github.com/gocd/docker-gocd-agent/commit/dc49b6df3856ebf91ae59562e42968ecca942b93) Create slimmer agent images by deleting the downloaded zip after extraction.
Expand All @@ -19,4 +23,4 @@ No changes.
## Bug Fixes

* [27b8772](https://github.com/gocd/docker-gocd-agent/commit/27b8772) Remove `/home/go` from the volume instruction. This makes the `/home/go` directory writable by `go` user.
* [44b592f](https://github.com/gocd/docker-gocd-agent/commit/44b592f) Create home directory `/home/go` for docker agent images based on debian.
* [44b592f](https://github.com/gocd/docker-gocd-agent/commit/44b592f) Create home directory `/home/go` for docker agent images based on debian.
14 changes: 13 additions & 1 deletion Dockerfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ RUN \
# unzip the zip file into /go-agent, after stripping the first path prefix
unzip /tmp/go-agent.zip -d / && \
mv go-agent-<%= gocd_version %> /go-agent && \
rm /tmp/go-agent.zip
rm /tmp/go-agent.zip && \
# ensure that logs are printed to console output
<% %w(agent-bootstrapper-log4j.properties agent-launcher-log4j.properties agent-log4j.properties).each do |log_properties_file| -%>
sed -i -e 's/\(log4j.rootLogger.*\)/\1, stdout/g' /go-agent/config/<%= log_properties_file %> && \
sed -i -e 's/\(log4j.rootCategory.*\)/\1, stdout/g' /go-agent/config/<%= log_properties_file %> && \
echo "" >> /go-agent/config/<%= log_properties_file %> && \
echo "" >> /go-agent/config/<%= log_properties_file %> && \
echo "# Log to stdout" >> /go-agent/config/<%= log_properties_file %> && \
echo "log4j.appender.stdout=org.apache.log4j.ConsoleAppender" >> /go-agent/config/<%= log_properties_file %> && \
echo "log4j.appender.stdout.layout=org.apache.log4j.PatternLayout" >> /go-agent/config/<%= log_properties_file %> && \
echo "log4j.appender.stdout.layout.conversionPattern=%d{ISO8601} %5p [%t] %c{1}:%L - %m%n" >> /go-agent/config/<%= log_properties_file %> && \
<% end -%>
true

ADD docker-entrypoint.sh /

Expand Down
30 changes: 23 additions & 7 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ setup_autoregister_properties_file() {

VOLUME_DIR="/godata"

# these 3 vars are used by `/go-agent/agent.sh`, so we export
export AGENT_WORK_DIR="/go"
export STDOUT_LOG_FILE="/go/go-agent-bootstrapper.out.log"
AGENT_WORK_DIR="/go"

# no arguments are passed so assume user wants to run the gocd server
# we prepend "/go-agent/agent.sh" to the argument list
if [[ $# -eq 0 ]] ; then
set -- /go-agent/agent.sh "$@"
set -- /go-agent/agent.sh "$@"
fi

# if running go server as root, then initialize directory structure and call ourselves as `go` user
Expand Down Expand Up @@ -94,11 +92,29 @@ if [ "$1" = '/go-agent/agent.sh' ]; then
fi
done

if [ ! -e "${AGENT_WORK_DIR}/config/agent-bootstrapper-log4j.properties" ]; then
try cp -rfv "/go-agent/config/agent-bootstrapper-log4j.properties" "${AGENT_WORK_DIR}/config/agent-bootstrapper-log4j.properties"
try chown go:go "${VOLUME_DIR}/config/agent-bootstrapper-log4j.properties"
fi

if [ ! -e "${AGENT_WORK_DIR}/config/agent-launcher-log4j.properties" ]; then
try cp -rfv "/go-agent/config/agent-launcher-log4j.properties" "${AGENT_WORK_DIR}/config/agent-launcher-log4j.properties"
try chown go:go "${VOLUME_DIR}/config/agent-launcher-log4j.properties"
fi

if [ ! -e "${AGENT_WORK_DIR}/config/agent-log4j.properties" ]; then
try cp -rfv "/go-agent/config/agent-log4j.properties" "${AGENT_WORK_DIR}/config/agent-log4j.properties"
try chown go:go "${VOLUME_DIR}/config/agent-log4j.properties"
fi

setup_autoregister_properties_file "${AGENT_WORK_DIR}/config/autoregister.properties"
touch "${STDOUT_LOG_FILE}"
chown go:go "${STDOUT_LOG_FILE}"
try exec /usr/local/sbin/tini -- /usr/local/sbin/gosu go "$0" "$@" >> ${STDOUT_LOG_FILE} 2>&1
try exec /usr/local/sbin/tini -- /usr/local/sbin/gosu go "$0" "$@"
fi
fi

# these 3 vars are used by `/go-agent/agent.sh`, so we export
export AGENT_WORK_DIR
export GO_AGENT_SYSTEM_PROPERTIES="${GO_AGENT_SYSTEM_PROPERTIES}${GO_AGENT_SYSTEM_PROPERTIES:+ }-Dgo.console.stdout=true"
export AGENT_BOOTSTRAPPER_JVM_ARGS="${AGENT_BOOTSTRAPPER_JVM_ARGS}${AGENT_BOOTSTRAPPER_JVM_ARGS:+ }-Dgo.console.stdout=true"

try exec "$@"

0 comments on commit 2b7c7c2

Please sign in to comment.