-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added log prefixes #444
Added log prefixes #444
Conversation
@scriptcoded this is tremendous work. And it will be a problem to change it in the feature. I suggest using bash alias to do this job. It will require 2 lines added. What do you think? smth like this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I like the overall approach and normally I would prefer the clarity of a log
function; however, given that so many lines had to be touched, I like the sound of @wlp7s0 's suggestion number 2 about aliasing echo
. I'm good with including start-utils
in every file, so just declare the alias there and keep those inclusion changes you have made.
@wlp7s0 how strongly do you feel about the escape codes in your suggestion? I'd prefer to keep the log prefix plain text since non-console/tty environments are common, such as kubernetes deployments.
start-minecraftFinalSetup
Outdated
JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}" | ||
if isTrue ${DEBUG_EXEC}; then | ||
set -x | ||
fi | ||
exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $SERVER "$@" $EXTRA_ARGS | ||
exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $SERVER "$@" $EXTRA_ARGS | sed "s/^/[minecraft] /" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's an exec
I'm not sure if piping to sed
actually works...or worse, it might default the point of the exec
and insert a shell process as a parent of mc-server-runner
process. Can you provide a ps -ef
of a container running with these changes so I can confirm the process tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for sure. At least my output looks perfectly fine:
2020-03-03T16:30:15.739032751Z [wrapper] Copying any mods over...
2020-03-03T16:30:15.742490670Z [wrapper] Setting initial memory to 1G and max to 1G
2020-03-03T16:30:15.742728666Z [wrapper] Starting the Minecraft server...
2020-03-03T16:30:18.490584942Z [minecraft] [16:30:18] [main/INFO]: Loading for game Minecraft 1.15.2
2020-03-03T16:30:18.563249509Z [minecraft] [16:30:18] [main/INFO]: [FabricLoader] Loading 2 mods: minecraft@1.15.2, fabricloader@0.7.8+build.184
As for how it actually runs:
$ docker exec 8234897ee6ee ps -ef
PID USER TIME COMMAND
1 minecraf 0:00 {start-minecraft} /bin/bash /start-minecraftFinalSetup
38 minecraf 0:00 mc-server-runner --stop-duration 60s java -XX:+UseG1GC -Xms1G -Xmx1G -jar fabric-server-launch.jar
39 minecraf 0:00 sed s/^/[minecraft] /
46 minecraf 1:24 java -XX:+UseG1GC -Xms1G -Xmx1G -jar fabric-server-launch.jar
106 root 0:00 ps -ef
I'll be perfectly honest and say that I don't quite follow what issues might arise from doing it the way I'm doing it. Are you thinking about performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't realize ps
by default on alpine doesn't show the parent PID of each process. Please re-run with
ps -ef -o pid,ppid,args
The problem I'm worried about is signal propagation, specifically the SIGTERM when the container is stopped. The main reason I created mc-server-runner was to intercept the SIGTERM and send a stop
command to gracefully stop the minecraft server since it itself doesn't properly handle SIGTERM. This article explains it pretty nicely.
For comparison, here's what the process tree looks like on master:
PID PPID COMMAND
1 0 mc-server-runner --stop-duration 60s java -XX:+UseG1GC -Xms1G -Xmx1G -jar minecraft_server.1.15.2.jar
56 1 java -XX:+UseG1GC -Xms1G -Xmx1G -jar minecraft_server.1.15.2.jar
where mc-server-runner must become PID 1 to intercept the signals.
So...long story, short, I think it'll take an enhancement in mc-server-runner to properly prepend those logs. FWIW, I have been wanting to enrich those logs with a date, in addition to time, so that would be a reasonable modification.
start-utils
Outdated
fi | ||
} | ||
|
||
function log { | ||
echo "[wrapper] $*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with hardcoding this; however, "wrapper" still doesn't feel right to me. How about "[startup]" or "[init]"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[init]
sound good in my ears. Even better would be to perhaps have something more descriptive. I can't figure out a good name though, since [minecraft-server]
would indicate the actual Minecraft server.
I personally feel very strongly about modifying native functionality. However, I understand that large changes like my proposal might be unwanted. I guess it boils down to personal preference, and after all this is @itzg's project. @itzg As for escape codes they make parsing the output very cumbersome. Perhaps adding a flag to enable colorized output would be a solution? |
@itzg oh, yeah. You are correct, no need to colourize the output. Didn't think about no-tty deploys. @scriptcoded I would really like to understand what do you mean by
I would like to know it from my personal perspective. I don't see any problem with modifying bashrc inside the container. May be my approach is bad? Can you elaborate please? Because for me it is more like configuring the environment rather than changing functionality. |
@wlp7s0 I like to be careful changing behaviors that are standard. For example, echo "foo" >> bar.txt You would expect |
@scriptcoded I see. This is true, but after modifying global alias, this behaviour is expected. Thank you for the explanation. |
Yeah, all in all I prefer the |
@itzg I'll do that. Did we settle on "init"? |
“init” works for me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing the PR branch I found that the minecraft server failed early with a complaint about the eula.
Build/running with docker build -t mc . && docker run -it --rm -e EULA=TRUE --name mc mc
I got
[init] Starting the Minecraft server...
2020/03/04 15:35:48 Done
[minecraft] [15:35:48] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
With some debugging I discovered the eula file was getting the logging prefixes too:
[init] # Generated via Docker on Wed Mar 4 15:33:38 UTC 2020
[init] eula=true
With that discovery I re-reviewed and noted items that need to remain an echo
. Sorry I missed that in my initial review.
start-minecraftFinalSetup
Outdated
JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}" | ||
if isTrue ${DEBUG_EXEC}; then | ||
set -x | ||
fi | ||
exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $SERVER "$@" $EXTRA_ARGS | ||
exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $SERVER "$@" $EXTRA_ARGS | sed "s/^/[minecraft] /" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't realize ps
by default on alpine doesn't show the parent PID of each process. Please re-run with
ps -ef -o pid,ppid,args
The problem I'm worried about is signal propagation, specifically the SIGTERM when the container is stopped. The main reason I created mc-server-runner was to intercept the SIGTERM and send a stop
command to gracefully stop the minecraft server since it itself doesn't properly handle SIGTERM. This article explains it pretty nicely.
For comparison, here's what the process tree looks like on master:
PID PPID COMMAND
1 0 mc-server-runner --stop-duration 60s java -XX:+UseG1GC -Xms1G -Xmx1G -jar minecraft_server.1.15.2.jar
56 1 java -XX:+UseG1GC -Xms1G -Xmx1G -jar minecraft_server.1.15.2.jar
where mc-server-runner must become PID 1 to intercept the signals.
So...long story, short, I think it'll take an enhancement in mc-server-runner to properly prepend those logs. FWIW, I have been wanting to enrich those logs with a date, in addition to time, so that would be a reasonable modification.
@itzg (couldn't reply to your comment for some reason) Your suspicion was correct, and the process tree becomes odd:
I'm getting the same output as you if I remove the After having looked up a bit more about signal propagation, I agree that the best place to add it would be in When it comes to timestamp, |
Ah, I didn’t know |
@itzg Just having |
I think we're ready for this feature to be merged now. Sorry for making this take so long! |
No problem at all. Thanks for working with me on this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retested the latest code and server startup looks good and process-tree is good. Thanks again!
The updated image is now on Docker Hub. |
In response to #442
Quirks that might be unfavorable:
start-utils
in every filelog
insteadof
echo`[wrapper]
tag is configurable in thestart-utils
file, but[minecraft]
is repeated twice in start-minecraftFinalSetup and has no config.I had some thought about configuration, but my own opinion is that logger names shouldn't have to be configurable from the user side. I can't see a case where the user would benefit from changing the logger names, as long as they are kept unique.
These changes have really just served as a workaround for personal use, so please, rip them all out if need be :)