Limiting log size of jenkins.log or hudson.log

雨燕双飞 提交于 2019-12-04 03:22:02

You can use logrotate. You can find more information about logrotate on this kb article.

Here is how logrotate is configured on my system (/etc/logrotate.d/jenkins):

/var/log/jenkins/jenkins.log /var/log/jenkins/access_log {
    compress
    dateext
    maxage 365
    rotate 99
    size=+4096k
    notifempty
    missingok
    create 644
    postrotate
      if [ -s /var/run/jenkins.pid ]; then
        JPID=`cat /var/run/jenkins.pid`
        test -n "`find /proc/$JPID -maxdepth 0 -user jenkins 2>/dev/null`" && /bin/kill -s ALRM $JPID || :
      fi
    endscript
}

or if you don't really like signals, and it is crashing jenkins for you, you can use the logrotate definition from this debian config.

/var/log/jenkins/jenkins.log {
        weekly
        copytruncate
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
}

Using logrotate with copytruncate does not release the lock for the file descriptor and you end up with issues like the one mentioned by Sebastian Sastre, where rotation happens but you won't get your disk space back until you restart Jenkins.

As an alternative solution this script perhaps could be used in the postrotate block. It relies on gdb to send a close() open() replacing the "broken" file descriptor.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!