jusito / ttt_voice_sync

Tool to mute ppl on TS3 as fast as possible.
MIT License
3 stars 0 forks source link

TTT server log is spammed by rcon and lua_run #1

Open ex0nuss opened 4 years ago

ex0nuss commented 4 years ago

Hi,

your plugin works great and makes the game way more fun! Unfortunately the log of my TTT-server gets spammed by your voice-sync-container.

When I don't change anything it looks like this:

rcon from "192.168.240.1:55384": command "lua_run print( GAMEMODE.round_state )"
> for k,v in pairs(player.GetAll()) do print( v:GetName(), v:Alive() ) end...
rcon from "192.168.240.1:55384": command "lua_run for k,v in pairs(player.GetAll()) do print( v:GetName(), v:Alive() ) end"
> print( GAMEMODE.round_state )...
1

When I deactivate RCON-logging (sv_rcon_log 0) in the server.cfg settings of my TTT-server it looks like this:

> for k,v in pairs(player.GetAll()) do print( v:GetName(), v:Alive() ) end...
> print( GAMEMODE.round_state )...
1

One of those log entries is showing up every second and it makes the log of my TTT-container really big. I am running both (ttt-server and voice-sync) in docker-compose.

Thank you in advance for your help :)

jusito commented 4 years ago

Thank you!

The current problem is that polling is used to synchronize the state fast enough, so we have to do a poll every 250 ms. I wasn't able to create a quick and clean workaround for this. A quick and dirty workaround could be, to run with cron (supercron in my docker TTT image) every 5 minutes a sed command to remove only this lines from log (ok maybe this solution is pretty dirty). See at bottom.

possible clean solution

The clean solution would be to use logappend_add (step 1) with async source query reader but without a lua script the server will not print enough informations for this. Something like a verbose state logger is needed (step 2):

I currently can't work on this, maybe version 2.0 would get this.

quick and dirty workaround

Important: replace ip to your ip in the log 192.168.240.1, for me its 172.17.0.1

# looked into my logs (4 month, 4 logs with 500mb) 
# command for cron / supercron (in my TTT image logs are in /home/steam/log/)
find -L /home/steam/log -name '*.log' -exec sed -i -E '/^((([^:]+:){3} )?rcon from "192.168.240.1:|> (for|print)|[0-9]\s+$|\S+\s+(true|false)\s+$)/d' "{}" \;

Tested here:

# show size of every log file
find -L /home/steam/log -name "*.log" -exec ls -lAh "{}" \;
# clean log files
find -L /home/steam/log -name '*.log' -exec sed -i -E '/^((([^:]+:){3} )?rcon from "172.17.0.1:|> (for|print)|[0-9]\s+$|\S+\s+(true|false)\s+$)/d' "{}" \;
# show size of every log file
find -L /home/steam/log -name "*.log" -exec ls -lAh "{}" \;

This would remove every logged rcon connection from given ip, _sv_rconlog 1 is need for this.

What the hell is this?

#find every .log file in logs folder, follow symbolic links and execute sed on them
find -L /home/steam/log -name '*.log' -exec sed ... "{}" \;
# use regular expression to delete lines matching and write back to file
find ... sed -i -E '/.../d' "{}"
# start regex at every line start
find ... sed '/^.../d' "{}"
# find line start which begins with pattern a, or find line start which begins with pattern b, or ...
find ... sed '/^(a|b|c|d)/d' "{}"
# pattern a, find every log line for rcon connection only from given ip (you need to replace the ip maybe)
(([^:]+:){3} )?rcon from "192.168.240.1:
# pattern b, find line which starts with > for or > print
> (for|print)
# pattern c, delete every printed gamemode (just an int) allowed to be exactly one single, line ending after
[0-9]\s+$
# pattern d, delete the printed player alive / dead tables
\S+\s+(true|false)\s+$

add to cron

Create a script named: /home/steam/logs/log.workaround.sh and add chmod +x

#!/bin/bash
#should be /bin/sh compatible

set -o errexit
set -o nounset

find -L /home/steam/log -name "*.log" -exec ls -lAh "{}" \;
find -L /home/steam/log -name '*.log' -exec sed -i -E '/^((([^:]+:){3} )?rcon from "192.168.240.1:|> (for|print)|[0-9]\s+$|\S+\s+(true|false)\s+$)/d' "{}" \;
find -L /home/steam/log -name "*.log" -exec ls -lAh "{}" \;

If your container is name: MyTTT and the file created is in your home dir

docker cp ~/log.workaround.sh MyTTT:/home/steam/logs
docker exec -u root MyTTT chown steam:steam /home/steam/logs/log.workaround.sh
docker exec -u root MyTTT chmod +x /home/steam/logs/log.workaround.sh

cron file is in /home/steam/logs/lgsm.cron,

echo '*/5 * * * * /home/steam/logs/log.workaround.sh > /home/steam/logs/log.workaround.sh.log 2>&1' >> /home/steam/logs/lgsm.cron

restart the container, it will reload the cronjob, if you dont want to restart:

docker exec -it -u root MyTTT pkill supercronic
docker exec -it MyTTT /bin/bash
supercronic "/home/steam/logs/lgsm.cron" 2> "/home/steam/logs/cron.log" &
exit
ex0nuss commented 4 years ago

Hi,

first and foremost, sry for my late answer. I have already found a simpler solution but forgot to post it. Secondly, thank you so much for you help.

As I already sad, my solution is simpler: I decided for myself, to not save the logs from the TTT-Container. This means only the Docker-Log is getting lager and lager. I solve this solution by using log truncation. This means I clear log files depending on certain arguments. This is inside my docker-compose.yml for the ttt-game-server-container:

    logging:
      driver: "json-file"
      options:
        max-size: "10M"
        max-file: "5"

Explanation: