Skip to content

Commit

Permalink
include work from 2.5
Browse files Browse the repository at this point in the history
This is the CherryPick commit from the last changes from 2.5 that includes:

- Graylog Master Auto Selection for Kubernetes (Graylog2#60 )
- run Graylog as User (Graylog2#59)
  • Loading branch information
jalogisch committed Feb 5, 2019
1 parent 7b87b77 commit 7b1000b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
58 changes: 41 additions & 17 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,50 @@ fi
# Delete outdated PID file
[[ -e /tmp/graylog.pid ]] && rm --force /tmp/graylog.pid

# Create data directories
if [[ "$1" = 'graylog' ]] && [[ "$(id -u)" = '0' ]]; then
for d in journal log plugin config contentpacks; do
dir=${GRAYLOG_HOME}/data/$d
# check if we are inside kubernetes, Graylog should be run as statefulset and $POD_NAME env var should be defined like this
# env:
# - name: POD_NAME
# valueFrom:
# fieldRef:
# fieldPath: metadata.name
# First stateful member is having pod name ended with -0, so
if [[ ! -z "${POD_NAME}" ]]
then
if echo "${POD_NAME}" | grep "\\-0$" >/dev/null
then
export GRAYLOG_IS_MASTER="true"
else
export GRAYLOG_IS_MASTER="false"
fi
fi

setup() {
# Create data directories
for d in journal log plugin config contentpacks
do
dir=${GRAYLOG_HOME}/data/${d}
[[ -d "${dir}" ]] || mkdir -p "${dir}"
done

chown --recursive "${GRAYLOG_USER}":"${GRAYLOG_GROUP}" "${GRAYLOG_HOME}/data"
}

# Start Graylog server
# shellcheck disable=SC2086
set -- gosu ${GRAYLOG_USER} "${JAVA_HOME}/bin/java" ${GRAYLOG_SERVER_JAVA_OPTS} \
-jar \
-Dlog4j.configurationFile=${GRAYLOG_HOME}/data/config/log4j2.xml \
-Djava.library.path=${GRAYLOG_HOME}/lib/sigar/ \
-Dgraylog2.installation_source=docker \
${GRAYLOG_HOME}/graylog.jar \
server \
-f ${GRAYLOG_HOME}/data/config/graylog.conf ${GRAYLOG_SERVER_OPTS}
fi
graylog() {

"${JAVA_HOME}/bin/java" \
${GRAYLOG_SERVER_JAVA_OPTS} \
-jar \
-Dlog4j.configurationFile="${GRAYLOG_HOME}/data/config/log4j2.xml" \
-Djava.library.path="${GRAYLOG_HOME}/lib/sigar/" \
-Dgraylog2.installation_source=docker \
"${GRAYLOG_HOME}/graylog.jar" \
server \
-f "${GRAYLOG_HOME}/data/config/graylog.conf"
}

run() {
setup
graylog
}

# Allow the user to run arbitrarily commands like bash
exec "$@" 2>&1
run
5 changes: 4 additions & 1 deletion test/integration_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash -ex
#!/bin/bash

set -e

CREDENTIALS="admin:admin"
URL="http://127.0.0.1:9000"

Expand Down
2 changes: 1 addition & 1 deletion test/linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if ! [ -x "$(command -v hadolint)" ]; then
fi

hadolint Dockerfile
shellcheck docker-entrypoint.sh
shellcheck docker-entrypoint.sh --external-sources --exclude=SC2086

0 comments on commit 7b1000b

Please sign in to comment.