Graylog2 / graylog-docker

Official Graylog Docker image
https://hub.docker.com/r/graylog/graylog/
Apache License 2.0
356 stars 133 forks source link

Adjust graylog entrypoint.sh with curl #187

Open samkhamk opened 2 years ago

samkhamk commented 2 years ago

Hello Team,

I was trying to bring curl command to bring some properties enabled once graylog is up but its not working for me

I tried below thing graylog() {

exec "${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" }

curl() { curl something }

run() { setup graylog curl }

run

but its not working , then I tried below thing

graylog() {

exec "${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" && curl something }

it works command gets executed but container keeps on restarting , even I tried below thing s

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" && curl something exec "$@" }

it is also not working, can someone help me here how I can add curl after graylog is up in automated way, I tried to get help from community but no luck,

I dont want to use any operator or sidecar for this. please help I am sorry to for asking help in this manner.

Regards, SAM

malcyon commented 2 years ago

I'm not clear what your curl command is doing. Is it setting an environment variable for a Graylog property?

I think you would want to set the env vars before the java command that starts Graylog. Something like:

run() {
setup
curl
graylog
}

Or even just put your curl command into the setup function.

samkhamk commented 2 years ago

Hello @malcyon

I am trying below

curl -i -X PUT -u $GRAYLOGUSER:$GRAYLOGPASSWORD -H 'Content-Type: application/json' -H 'X-Requested-By: cli' 'http://graylog-core:9000/graylog/api/system/authentication/http-header-auth-config' -d '{"enabled":true,"username_header":"X-Forwarded-User"}'

which needs graylog to be up and functional, can you help me to here, I hope its clear now.

Regards, Sam

malcyon commented 2 years ago

Okay. I see. I think you need to daemonize Graylog itself for what you're doing to work. In the first example, the script will stop executing commands until Graylog exits.

Not sure what's happening in the second example. It may be that Graylog is being backgrounded. And then when curl exits, the script is done, so Docker exits. Docker is really designed to run ONE command. When that command exits, the container is stopped. And then it might restart if your docker-compose is configured to do that.

malcyon commented 2 years ago

The problem is, if you were to daemonize Graylog, then the container would just exit. Docker is supposed to just run one command, and the container stops when that command exits. That's why all the stuff in our script runs before the java process.

If you daemonized Graylog, then ran your curl script, then had an infinite while loop in Bash after that, it might work. But then the container wouldn't stop properly.

You'll probably have to accomplish this in a different way. A sidecar is a good idea, even though you said you didn't want to do that.