On 1/6/09 1:50 PM, John McKown wrote:
I've got a small problem. I have a daemon which I cannot easily restart
because it is production and people are using it. The daemon is started
with something like:

daemon args>>daemon.log

The file "daemon.log" is getting very huge. The correct way to fix this is
to stop the daemon, "mv" or "rm" the "daemon.log", then restart the
daemon. But I have a vague memory that it is sometimes possible to "reset"
a file to "empty" simply by doing a:


daemon.log


You're probably thinking of "> daemon.log" to truncate a file.

and that will, at times, work even if the daemon is not restarted. Is my
memory correct? Or is that some sort of "special case" which does not
apply when bash does a>>  redirect of stdin?


No, append isn't a special case.

We plan to fix this by "not doing that!", but instead piping the stdout
from the daemon to a process called "cronolog" which works by
automatically changing the output file at midnight by changing the "date
portion" of the log name.


I believe some people don't think this is kosher, but I like:

bzip2 -c daemon.log > daemon.log.$(date +%Y%m%d).bz2 && > daemon.log

but if daemon keeps daemon.log open, daemon.log will become a sparse
file the next time daemon writes to it. A sparse file doesn't take up
any disk space, in this case, except what's subsequently written to it
by daemon. You have to remember not to copy the first line of daemon.log
if you do this again (e.g., tail +2 daemon.log | ..., or if you want to
be more efficient:

tail -c $(( $(stat -c %b\*%B daemon.log) )) daemon.log | tr -d '\000'\| ...

(unless you're worried about embedded nulls in the real portion of
daemon.log, in which case replace "tr -d '\000'" with a slightly less
efficient "sed -e '1s/^\000//g'".)

If you do the above on a regular basis, you never have to bounce daemon,
and can still have, e.g. daily, log files. And bonus -- eventually you
can have a file that looks like it's larger than the file system it's on!

A good backup program will back up sparse files sparsely. I don't know
about TSM, but Legato Networker isn't a good backup program :-(

- Larry

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to