Ubuntu – Rotate nohup output

12.04lognohup

I'm working with weblogic 10.3.5 under ubuntu 12.04.

Weblogic is started using

nohup ./startWebLogic.sh >Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/logs/AdminServer.out 2>&1 </dev/null &

It's working fine and now I would like to rotate AdminServer.out using logrotate but it seems it's not so easy to do. Searching on internet it is not very clear to understand if it is possible or not.

I tried using the copytruncate options. When the logrotate is executing the size of the file becomes 0 but returns to original size after the first 'write' of the server.

Also tried renaming the file. The server still writes to the renamed file.

It seems the server only have a pointer to a file independently of it's name or size.

So … is there a solution ? Using logrotate or not.

–EDIT–

I also tried with

#!/bin/bash
mkdir -p tmp
if [ ! -p tmp/weblogic.fifo ]; then
    mkfifo tmp/weblogic.fifo
fi
tail -f tmp/weblogic.fifo >> Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/logs/AdminServer.out &
nohup ./startWebLogic.sh > /home/me/tmp/weblogic.fifo 2>&1 </dev/null &

I don't know if it is proper but … there is at least one problem : sometimes, it hangs up writing to the file. Sometimes a few seconds but after a while (even before the server has started) … indefinitely !

So I cannot test the logrotate.

Best Answer

Unlearn the need for logrotate. You don't need logrotate in the first place. This is a problem that has been solved since the middle 1990s.

Get yourself one or more of:

and send script standard output and standard error through a pipe to their standard input, in the normal way:

./startWebLogic.sh 2>&1 | cyclog logs/

They will write a set of automatically cycled, rotateable-on-demand, strictly size-capped logs in a directory that you specify, with no need for any additional log rotation programs at all. None of them need any superuser privileges. (In fact, far from needing or expecting superuser privileges it is best practice in their most widely known use case, logging dæmon output, to run them under unprivileged accounts.)

Further reading

Related Question