MinecraftServerControl / mscs

Powerful command-line control for UNIX and Linux powered Minecraft servers
https://minecraftservercontrol.github.io
BSD 2-Clause "Simplified" License
490 stars 61 forks source link

log4j command line file configuration #227

Closed rickyninja closed 4 years ago

rickyninja commented 4 years ago

Hey @sandain this is related to the last PR I sent for log duration. I want to configure the logger to use a timestamp that has enough info to observe things like which players are online the most, how long since they were last online, etc. I've got it working with a modified copy of msctl, but wanted to run this by you before doing a PR to hear your thoughts on it. I tried adding -Dlog4j.configurationFile=... via $SERVER_ARGS but it looks like JVM args need to precede the jarfile in the command line. What do you think of adding $JVMARGS?

related info:

local change I made to msctl to get log4j configurationFile working

minecraft@minecraft> diff -u git/mscs/msctl /usr/local/bin/msctl
--- git/mscs/msctl      2019-11-06 21:39:59.397528513 +0000
+++ /usr/local/bin/msctl        2019-11-06 22:57:08.767932902 +0000
@@ -1340,6 +1340,7 @@
     printf "$SERVER_COMMAND\n"
     exit 1
   fi
+  echo SERVER_COMMAND: $SERVER_COMMAND
   # Start the server.
   nohup sh -c "tail -f --pid=\$$ $WORLD_DIR/console.in | {
     $SERVER_COMMAND mscs-world=$1 > $WORLD_DIR/console.out 2>&1; kill \$$;
@@ -2260,7 +2261,7 @@
 DEFAULT_INITIAL_MEMORY=$(getDefaultsValue 'mscs-default-initial-memory' '128M')
 DEFAULT_MAXIMUM_MEMORY=$(getDefaultsValue 'mscs-default-maximum-memory' '2048M')
 DEFAULT_SERVER_LOCATION=$(getDefaultsValue 'mscs-default-server-location' $LOCATION'/server')
-DEFAULT_SERVER_COMMAND=$(getDefaultsValue 'mscs-default-server-command' '$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGS')
+DEFAULT_SERVER_COMMAND=$(getDefaultsValue 'mscs-default-server-command' '$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -Dlog4j.configurationFile=$HOME/log4j2.xml -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGS')
 # Each world server can override the default values in a similar manner by
 # adding certain key/value pairs to the world's mscs.properties file.
 #

minecraft@minecraft> mscs restart rickyninja
The cached copy of the version manifest is up to date.
Use the force-update option to ensure a new copy is downloaded.
Restarting Minecraft Server: rickyninjaSERVER_COMMAND: /usr/bin/java -Xms128M -Xmx2048M -Dlog4j.configurationFile=$HOME/log4j2.xml -jar /opt/mscs/server/minecraft_server.1.14.4.jar nogui
Erase is control-H (^H).
.

example of altered timestamp:

minecraft@minecraft> mscs console rickyninja
Connecting to server console: rickyninja.
  Hit <Ctrl-D> to detach.
[2019-11-06 16:19:37 MST] [INFO]: Preparing spawn area: 0%
[2019-11-06 16:19:37 MST] [INFO]: Preparing spawn area: 0%
[2019-11-06 16:19:37 MST] [INFO]: Preparing spawn area: 0%
[2019-11-06 16:19:37 MST] [INFO]: Preparing spawn area: 0%
[2019-11-06 16:19:37 MST] [INFO]: Preparing spawn area: 0%
[2019-11-06 16:19:37 MST] [INFO]: Preparing spawn area: 0%
[2019-11-06 16:19:38 MST] [INFO]: Time elapsed: 4450 ms
[2019-11-06 16:19:38 MST] [INFO]: Done (5.348s)! For help, type "help"
[2019-11-06 16:19:38 MST] [INFO]: Starting GS4 status listener
[2019-11-06 16:19:38 MST] [INFO]: Query running on 0.0.0.0:25565
[2019-11-06 16:20:28 MST] [INFO]: UUID of player ricky_ninja is 2ca2332f-429c-46b9-926f-03f9d7dc8049
[2019-11-06 16:20:29 MST] [INFO]: ricky_ninja[/10.157.96.1:48136] logged in with entity id 541 at (-165.87925058759774, 64.0, -376.71651520180245)
[2019-11-06 16:20:29 MST] [INFO]: ricky_ninja joined the game
[2019-11-06 16:20:40 MST] [INFO]: ricky_ninja lost connection: Disconnected
[2019-11-06 16:20:40 MST] [INFO]: ricky_ninja left the game
sandain commented 4 years ago

Hi @rickyninja.

I think adding a $JVMARGS variable makes sense to make this use case easier. This is a little convoluted in the code, so let me know if you have any questions while creating a PR. Look to the other variables, like $JAVA, for inspiration.

rickyninja commented 4 years ago

https://github.com/MinecraftServerControl/mscs/pull/228