0

I trust you all doing good.

we planning to implement log rotation for below file. stdout.log

we use below log rotation configuration file.

/usr/local/rms/kafka/kafka-connect-fluentd/stdout.log {
    daily
    rotate 7
    maxsize 100M
    minsize 10M
    copytruncate
    delaycompress
    compress
    notifempty
    missingok
}

we have noticed the file is rotating and file is truncated.But application does not write logs to new file. we tried to send the HUP signal and it did not work.

-rw-r--r-- 1 appuser appuser 8.2M Feb 20 03:11 stdout.log.4.gz
-rw-r--r-- 1 appuser appuser 4.0M Feb 20 23:48 stdout.log.3.gz
-rw-r--r-- 1 appuser appuser 7.6M Feb 20 23:49 stdout.log.2.gz
-rw-r--r-- 1 appuser appuser 2.1G Feb 21 03:39 stdout.log.1
-rw-r--r-- 1 appuser appuser 2.2G Feb 21 14:15 stdout.log

The application itself do not have a reload option, We stop the application and start the application when we need to reload or restart the application.

we use below command to bring up the application

nohup connect-standalone ${BASE}/connect-standalone.properties 
${BASE}/FluentdSourceConnector.properties >& ${BASE}/stdout.log &

we use below command to kill the application

kill -9 <processid>

How do we implement a log rotating mechanism for this situation ?

Selaron
  • 6,105
  • 4
  • 31
  • 39
UtpMahesh
  • 410
  • 10
  • 25
  • 1
    `>& ${BASE}/stdout.log` - you want the log to truncate on each restart? It would be better to use the standard `2>&1 >> ${BASE}/stdout.log` then nonstandard `>&` – KamilCuk Feb 21 '19 at 08:02
  • @KamilCuk this was helped full and resolved my issue. If you do not mind could you please do little bit elaboration – UtpMahesh Feb 21 '19 at 16:06

1 Answers1

1
>& FILE

Is the obsolete syntax for:

> FILE 2>&1

The > FILE redirects standard output of the command to file named FILE. However, before that happens, "if the file does not exist it is created; if it does exist it is truncated to zero size".

So each time you restarted your command, your file was (properly) truncated by the shell. What you want is to append to the file. Do that by using >> redirection. Including that you want to redirect both stdout and stderr, use:

2>&1 >>FILE

The 2>&1 redirects stderr to stdout and the >>FILE appends stdout to FILE.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111