To use logrotate, particularly its option ‘copytruncate’.
cat /etc/logrotate.d/oracleas
/home/oracle/OraAPP/j2ee/oc4j_container/log/oc4j_container_default_island_1/server.log {
daily
missingok
rotate 5
compress
delaycompress
notifempty
copytruncate
}
To quickly test it:
# logrotate -f /etc/logrotate.conf
From /usr/sbin/lsof | grep server.log, we could see the mapping of inode# and java pid is still the same before and after the log rotation.
copytruncate
Truncate the original log file in place after creating a copy,
instead of moving the old log file and optionally creating a new
one, It can be used when some program can not be told to close
its logfile and thus might continue writing (appending) to the
previous log file forever. Note that there is a very small time
slice between copying the file and truncating it, so some log-
ging data might be lost. When this option is used, the create
option will have no effect, as the old log file stays in place.