0

Standard Unix daemons support the signal HUP to rotate log files. When ever a daemon receives the signal it closes all log files and reopens them.

I have a daemon process in Java using Apache Commons Daemon. The daemon implementation supports three methods: init, start and stop. But I can not find any support for Unix signals. How to support the HUP signal to rotate log files?

Mandar Pandit
  • 2,171
  • 5
  • 36
  • 58
ceving
  • 21,900
  • 13
  • 104
  • 178

1 Answers1

1

Apache Commons Daemon does this for you using SIGUSR1, which causes the process to close and reopen the stderr and stdout file descriptors.

As long as you're logging to these streams (e.g. using log4j as follows), you don't have to write any java code.

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.err" />
    ...
</appender>
StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
byeo
  • 646
  • 7
  • 17