Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i'd like to do logfile rotation for whenever i start a service, but never "automatically".

i'm running a python-based service that logs to a specific logfile. the service (currently) does not support notification to re-open it's logfiles (e.g. USR1 trap). also, the service must not be restarted for logfile rotation (it's producing a continous audio-stream, which should not be interrupted).

the system i'm running on does not have a hardware clock, so the clock gets reset everytime the system boots, which makes log entries originating from different reboots in the same file tedious (i get the same date multiple times).

i also want to keep history across various boots.

so the idea is to use logrotation on each boot (only).

something like running /usr/sbin/logrotate --force /etc/logrotate.d/myservice before starting the service should do the trick.

now my question is, is it possible to configure log-rotationg in /etc/logrotate.d/myservice in such a way, that it will be never run automatically?

an easy solution would be to not store my logrotate-config file in /etc/logrotate.d/, but "somewhere else".

but then, i'd like to have my user be able to find the logrotate-config in a well-known place (so they can modify the config at their will).

share|improve this question
    
Do you want it to run at system startup, or service startup? Your title and your question body are at variance. –  MadHatter Nov 7 '13 at 13:13
    
@MadHatter oops, i changed my mind while i wrote the question:-) for my system with the unstable clock it would be sufficient to rotate at system boot, but rotating at service startup seems like a good idea as well (so i get a new logfile for each run); i changed the title accordingly –  umläute Nov 7 '13 at 13:18

2 Answers 2

up vote 2 down vote accepted

You can configure logrotate to rotate a file via copy-truncate, which preserves the original file and doesn't require you to re-create the log file.

The syntax is:

/tmp/output.log {
        size 1M
        copytruncate
        rotate 4
        compress
}

This will copy the current file, then cat /dev/null > file

That being said, logrotate only "automatically" rotates files in specific places, unless configured otherwise. I imagine you're logging your script to /var/log/httpd, and that's why it's being automatically rotated.

share|improve this answer
    
i knew i forgot something about logrotate. copytruncate together with a forced rotation at startup is probably the way to go –  umläute Nov 7 '13 at 13:20

Why bother with logrotate at all if you don't want/need to use it?

Simply rotate the log file from your start-up script.

share|improve this answer
    
because it nicely handles renaming of old files, which i don't see a point in re-implementing –  umläute Nov 7 '13 at 13:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.