Rotate nohup output

8,594

Solution 1

The solution was eventually so simple

nohup ./startWebLogic.sh 2>&1 </dev/null | cat >> AdminServer.out &

and now the AdminServer.out can be rotated with logrotate and the copytruncate option.

Solution 2

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

Share:
8,594

Related videos on Youtube

tweetysat
Author by

tweetysat

Updated on September 18, 2022

Comments

  • tweetysat
    tweetysat over 1 year

    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.

    • kos
      kos about 9 years
    • tweetysat
      tweetysat about 9 years
      I already read that. So if I can't kill the process (and I can't kill weblogic) there is no solution ?
  • tweetysat
    tweetysat about 9 years
    Thanks. I tried with the first multilog. But I don't understand how it's working. I tried for ex. ls -l | multilog t s10485760 n5 '!tai64nlocal' tmp. But nothing appears in the tmp folder.
  • JdeBP
    JdeBP almost 9 years
    With multilog, directory names must start with a dot or a slash.
  • Ishimwe Aubain Consolateur
    Ishimwe Aubain Consolateur over 5 years
    I din't see how it rotate but apparently it is serving my needs. Rotation will come after because I am relying on Log4J2 for logs in my .jar app. If you get any update you can let me know. But I for now I wanted to let you know that your reply helped me