0

I'm learning about logrotate configs. So I've been reading the man page for commands and looking at logrotate configs for specific application logs, I see the snipit below often. (Centos 6.8 and below environments)

postrotate
   /bin/kill -HUP `cat /var/run/XXX.pid 2>/dev/null` 2> /dev/null || true
endscript

or something along these lines. My question is if the process I need to kill -HUP (which by the way I can't find in kill --help or man kill or man signal) is not in /var/run/xx.pid how do I stop the process from still writing to the file ? I know how to kill a process but I just want to stop it from writing the file, or make it re-read the file descriptor, like the example above, or at least I thinks that's what it does.

  • HUP signal is kill -1 – OscarAkaElvis Dec 28 '16 at 8:45
  • Thanks. im still not sure where to find other *.pid items to stop my program from writing to the log for a second or two – ssvegeta96 Dec 28 '16 at 22:33
  • “I came to get help, not to get my question edited.” – ssvegeta96 Aug 8 '18 at 21:01
0

Knowing what PID to kill is the point of having a pidfile in /var/run (or under /run/user/$UID for processes that are managed by your own user account). If your process doesn't write such a file, then you should either configure it to do so (if possible) or run it via a supervisor that creates a pidfile.

As a last resort, you can check which processes have the log file open with fuser, or even kill those processes outright (if you do that, don't forget the -w option, to only kill processes that are writing to the file), e.g.

ps $(fuser /path/to/log/file 2>/dev/null)
fuser -w -k -HUP /path/to/log/file
  • Looks like I got to learn more about my application. Thanks for the help. – ssvegeta96 Dec 30 '16 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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