logrotate

The purpose of this document is to describe some good ways to use logrotate.

    • mkdir -p /opt/jgs/scripts-jgs/common/logrotate.d/ && mkdir -p /var/log/jgs/old

    • vim /opt/jgs/scripts-jgs/common/logrotate.d/jgs.logrotate

    • Paste the script in

    • cd /etc/logrotate.d/ && ln -s /opt/jgs/scripts-jgs/common/logrotate.d/jgs.logrotate jgs.logrotate

    • chmod 644 /opt/jgs/scripts-jgs/common/logrotate.d/jgs.logrotate

/etc/logrotate.d/jgs.logrotate -> /opt/jgs/scripts-jgs/common/logrotate.d/jgs.logrotate

/var/log/jgs/*.log { size 10M rotate 5 olddir /var/log/jgs/old compress copytruncate }

Generic logrotate script

  • logname="jgs-distributed-cache"

  • srcdir="/var/log/jgs"

  • destdir="/var/log/jgs/old"

  • scriptdir="/opt/jgs/scripts-jgs/${logname}/logrotate.d"

  • scriptfile="${scriptdir}/${logname}.logrotate"

  • mkdir -p "${destdir}"

  • mkdir -p "${scriptdir}"

  • vim "${scriptfile}"

/var/log/jgs/jgs-distributed-cache { size 10M rotate 5 olddir /var/log/jgs/old compress copytruncate }

  • cd /etc/logrotate.d/ && ln -s "${scriptfile}" "${logname}.logrotate"

  • chmod 644 "${scriptfile}"

    • Test it with: logrotate --verbose --force "${scriptfile}"

[Edit]