1

I need to enable the logrotate service with Jenkins in order to rotate its log files (/var/log/jenkins/jenkins.log). So, I configured a script in /etc/logrotate.d with right permissions:

/var/log/jenkins/jenkins.log {
        hourly
        copytruncate
        missingok
        rotate 8
        compress
        delaycompress
        size 5G
}

The permissions are 644 and the owner is root as for every logrotate script.

The logrotate service works correctly but not for Jenkins. No log files are rotated!

So, I tried to insert the command directly in root's crontab:

0 * * * * logrotate --force /etc/logrotate.d/jenkins

But also this command doesn't work at all even if the cron service works correctly each hour as per cron logs:

cat /var/log/syslog | grep logrotate
[...]
Jun  4 09:00:01 CI-prod CRON[11794]: (root) CMD (logrotate --force /etc/logrotate.d/jenkins)
Jun  4 10:00:01 CI-prod CRON[525]: (root) CMD (logrotate --force /etc/logrotate.d/jenkins)

However, if I manually execute the logrotate command (logrotate --force /etc/logrotate.d/jenkins), it works well and the Jenkins logs are rotated with no problem as per script.

Please, can you help me?

Here are other useful info:

  • OS: Ubuntu 16.04.1 LTS
  • Jenkins version: 2.121.2
  • Java version: 1.8.0_121
4
  • what steps here : stackoverflow.com/questions/31610924/… and here : qamag.net/stop-that-huge-jenkins-log have you followed?
    – tatsu
    Jun 4, 2019 at 9:26
  • Could you use absolute path and redirect logrorate output? 0 * * * * /usr/sbin/logrotate --force /etc/logrotate.d/jenkins > /tmp/outfile.log 2>&1 this could help to find out what goes wrong.
    – Lety
    Jun 4, 2019 at 12:00
  • @Lety: perfect! I found out the problem! I redirected the error output to a temp log and I noticed that the system was unable to locate the logrotate command. I fixed the command in crontab and now it works well!
    – roghan
    Jun 5, 2019 at 16:09
  • @roghan you are welcome :D
    – Lety
    Jun 5, 2019 at 16:16

1 Answer 1

0

crontab has restricted environment, so try with absolute path and redirect command output into a file, this will help you in case of errors.

0 * * * * /usr/sbin/logrotate --force /etc/logrotate.d/jenkins > /tmp/outfile.log 2>&1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .