Bug #180
logrotate -> parse wrong file
| Status: | New | Start date: | 08/11/2011 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | - | |||
| Target version: | - |
Description
If something like logrotate moves the games.log file, that file will continue to be used until the end of the current map, then a new games.log will be created. tremadminbot does not detect this, meaning that it will keep trying to parse an old games.log file forever.
The simplest solution is probably to go by file inode: at eof, if there is no current game (i.e., after ShutdownGame, before InitGame), compare the inode of the file named games.log with the (saved) inode of the file being parsed; if they are different, close the current file handle and open the new games.log (re-enabling startupBacklog just in case).
An alternative is to use inotify to find out when the file is moved, then reopen at ShutdownGame.
History
Updated by msk 9 months ago
- File gameslogmove.patch added
- Change main regex so it matches ShutdownGame (which does not include a trailing space)
- Move the code that handles opening the log and finding the last InitGame to a new function
- Keep track of InitGame/ShutdownGame
- At eof, if ShutdownGame has been seen since the last InitGame and the log file does not exist or has a different inode, try reopening the log file (giving up after 3 tries; once per second)
Updated by Lakitu7 9 months ago
Note for me to fix when I get around to merging:
16:21 <Undeference> though actually the logrotate one doesn't close the file handle before
reopening, which might result in a warning (but is completely harmless)
Updated by msk 9 months ago
- File gameslogmove.patch added
Lakitu7 wrote:
Note for me to fix when I get around to merging:
I thought that was going to be on friday
Updated by Lakitu7 9 months ago
I applied this patch and then (partly, initially) tested it by restarting the server while tremAdminBot was running. While it seems to successfully reopen games.log, it crashes immediately upon receiving a command. My immediate guess is that this same close/reopen behavior needs to be applied to com_pipefile.
Updated by msk 9 months ago
The patch does not account for tremded being restarted, only the log file moving
Updated by msk 9 months ago
- File smarterhup.patch added
- Move more initialization code to separate functions
- Use SIGHUP handler for initialization (it should now be safe to change things like $sendMethod while running)
- Before writing to a fifo, attach a (temporary) SIGPIPE handler to try reopening the fifo (in case tremded restarted), with a hack to prevent dropping the message
$dbfile probably should not be changed while tremAdminBot.pl is running since some variables are expected to correspond to values in the db (e.g., userID) and it would require a lot more work to handle properly. But the db will be (safely) reopened when SIGHUP is received anyway.
Updated by Lakitu7 9 months ago
I get an instacrash with this applied in what I think is a pretty normal, vanilla test setup. Loads fine without the patch.
patching file tremAdminBot.pl
Hunk #5 succeeded at 312 (offset 7 lines).
Hunk #6 succeeded at 415 (offset 7 lines).
Hunk #7 succeeded at 1042 (offset 3 lines).
$ ./tremAdminBot.pl
...
For details, see gpl.txt
-------------------------------------------------------------------------------------------
seek() on unopened filehandle FILE at ./tremAdminBot.pl line 411.
Error: seek fail at ./tremAdminBot.pl line 411.
seek fail at ./tremAdminBot.pl line 411.
$
Updated by msk 9 months ago
- File smarterhup-REAL.patch added
smarterhup.patch was missing several hunks, which doesn't make sense since I'm pretty sure I tested it in detached head mode before uploading. Anyway, here is the fixed patch with the missing hunks and updated line numbers. And I tested it and it works (all I did is cherry pick the correct revisions and fix one conflict related to Geo::IP::PurePerl still being used upstream).
Updated by msk 3 months ago
- File smarterhup-REAL_1.patch added
Checking inode alone is not sufficient