[CentOS] Log rolling with a daemon

Larry Martell larry.martell at gmail.com
Sun Dec 22 16:21:30 UTC 2013


On Sat, Dec 21, 2013 at 9:46 PM, Cliff Pratt <enkiduonthenet at gmail.com> wrote:
> John's suggestion is still pertinent. You'll need a SIGHUP handler in your
> script. Logrotate could send the SIGHUP in a postrotate 'script'.

Thanks!


> On Sun, Dec 22, 2013 at 3:15 PM, Larry Martell <larry.martell at gmail.com>wrote:
>
>> On Sat, Dec 21, 2013 at 8:52 PM, John R Pierce <pierce at hogranch.com>
>> wrote:
>> > On 12/21/2013 4:56 PM, Larry Martell wrote:
>> >> I'm looking for advice or suggestions for rolling log files with a
>> >> daemon. I have a python script that I daemonized with
>> >>
>> http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
>> .
>> >> Before I daemonized it it was run from a bash script that invoked the
>> >> underlying python script. It ran the python script, waited for it to
>> >> complete and then it slept for 5 seconds and ran it again. This was in
>> >> a infinite loop. In between each invocation it checked the log file
>> >> and if it was over 10MB it renamed it and then the next invocation
>> >> started with a new empty log. Since each invocation was a separate run
>> >> this worked fine.  But now the daemonized python script doesn't exit -
>> >> the same log file is attached to it forever. So my renaming of the
>> >> file does nothing - the i node doesn't change and it's still logging
>> >> to the same large file. Anyone have any ideas how I can achieve this
>> >> sort of log rolling in this situation?
>> >>
>> >
>> > send a SIGHUP to syslog  and it shoudl re-opent he log files.
>> >
>> > silly question, but whats wrong with the logrotate daemon thats built
>> > into centos?
>>
>> This is not using syslog. If you look at the daemonizing script I gave
>> the link to, you pass in the log files for stdout and stderr, and it
>> does some double fork magic and then associates the given files with
>> them.



More information about the CentOS mailing list