From rfunk Wed Sep 15 11:09:32 1999 Subject: Re: [COLUG] Apache logs To: email@example.com Date: Wed, 15 Sep 1999 11:09:32 -0400 (EDT) Alex Dukat wrote: >I have created a script that rotates any file you specify and then >truncates the original file by opening in overwrite and then closing it. >I am currently using this for the log files generated by Apache. Looking >at there help though, they mention that the file should be moved and then >Apache restarted so that it will not continue to write where it left off >in the file. When I look at the file sizes I do not see that it continues >where it left off. My main concern is if I really do need to restart >Apache. Also, if the file is just filled with null characters as Apache >states, do they show up in the overall file size? > >This is probably confusing, but I feel I do not have to restart Apache >since the file sizes pan out. (ie it does not show the old file size plus >so many bytes for the information placed in the files.) Don't just look at sizes, look at the contents. And it is quite possible that zeros would not show up in the file size, since they can be "holes" in the file. Anyway, it's best to follow the documented recomendations. Even if not restarting works fine now, they could make a minor change in the future that would break that. It would be no big deal to them, since it would still follow their documentation, but it would be a problem for you. For all log files, you should rename (not copy), create the real name (if the logging program doesn't do it itself), then restart the daemon, then do what you want with the renamed file. When you rename a file that a program has open, the program simply does not notice, and keeps logging to the same file (with a new name). So you restart the program, or send a signal telling the program to reopen its files, and after that it is using the new file (with the same old name). The way you are doing it now, you may lose messages between when you copy and when you truncate the file. And the file could be corrupted if you truncate while Apache is writing to the log. The move-and-restart method prevents you from losing anything. Remember that you can do "apachectl graceful" to gracefully restart Apache without interrupting any current connections. Also remember that Apache has multiple processes with their own open filehandles. One apache process may use the new file while another is using the old file.