<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../../general.ent">
  %general-entities;

  <!ENTITY logrotate-download-http "https://fedorahosted.org/releases/l/o/logrotate/logrotate-&logrotate-version;.tar.gz">
  <!ENTITY logrotate-download-ftp  " ">
  <!ENTITY logrotate-md5sum        "2660f30742da79870d15d042b07829f6">
  <!ENTITY logrotate-size          "76 KB">
  <!ENTITY logrotate-buildsize     "1.9 MB">
  <!ENTITY logrotate-time          "less than 0.1 SBU">
]>

<sect1 id="logrotate" xreflabel="logrotate-&logrotate-version;">
  <?dbhtml filename="logrotate.html"?>

  <sect1info>
    <othername>$LastChangedBy: bdubbs $</othername>
    <date>$Date: 2015-02-21 00:50:01 -0500 (Sat, 21 Feb 2015) $</date>
  </sect1info>

  <title>Logrotate-&logrotate-version;</title>

  <indexterm zone="logrotate">
    <primary sortas="a-logrotate">logrotate</primary>
  </indexterm>

  <sect2 role="package">
    <title>Introduction to Logrotate</title>

    <para>
      The <application>logrotate</application> package allows automatic rotation, 
      compression, removal, and mailing of log files. 
    </para>

    &lfs77_checked;

    <bridgehead renderas="sect3">Package Information</bridgehead>
    <itemizedlist spacing="compact">
      <listitem>
        <para>
          Download (HTTP): <ulink url="&logrotate-download-http;"/>
        </para>
      </listitem>
      <listitem>
        <para>
          Download (FTP): <ulink url="&logrotate-download-ftp;"/>
        </para>
      </listitem>
      <listitem>
        <para>
          Download MD5 sum: &logrotate-md5sum;
        </para>
      </listitem>
      <listitem>
        <para>
          Download size: &logrotate-size;
        </para>
      </listitem>
      <listitem>
        <para>
          Estimated disk space required: &logrotate-buildsize;
        </para>
      </listitem>
      <listitem>
        <para>
          Estimated build time: &logrotate-time;
        </para>
      </listitem>
    </itemizedlist>

    <bridgehead renderas="sect3">Logrotate Dependencies</bridgehead>

    <bridgehead renderas="sect4">Required</bridgehead>
    <para role="required">
      <xref linkend="popt"/>
    </para>

    <bridgehead renderas="sect4">Recommended</bridgehead>
    <para role="recommended">
      <xref linkend="fcron"/> (runtime)
    </para>

    <bridgehead renderas="sect4">Optional</bridgehead>
    <para role="optional">
      An <xref linkend="server-mail"/> (runtime)
    </para>

    <para condition="html" role="usernotes">User Notes:
      <ulink url="&blfs-wiki;/logrotate"/>
    </para>
  </sect2>

  <sect2 role="installation">
    <title>Installation of Logrotate</title>

    <para>
      Install <application>logrotate</application> by running the following
      command:
    </para>

<screen><userinput>./autogen.sh &amp;&amp;
./configure --prefix=/usr &amp;&amp;
make</userinput></screen>

    <para>
      To test the results, issue: <command>make test</command>. 
    </para>

    <para>
      Now, as the <systemitem class="username">root</systemitem> user:
    </para>

<screen role="root"><userinput>make install</userinput></screen>

  </sect2>
<!--
  <sect2 role="commands">
    <title>Command Explanations</title>

    <para>
      <envar>MANDIR=/usr/share/man</envar>: Ensure the man pages are installed
      in the correct location.
    </para>

  </sect2>-->

  <sect2 role="configuration">
     <title>Configuring Logrotate</title>

     <para><application>Logrotate</application> needs a configuration file, 
     which must be passed as an argument to the command when executed.  Create 
     the file as the <systemitem class="username">root</systemitem> user:</para>

<screen role="root"><userinput>cat &gt; /etc/logrotate.conf &lt;&lt; EOF
# Begin of /etc/logrotate.conf

# Rotate log files weekly
weekly

# Don't mail logs to anybody
nomail

# If the log file is empty, it will not be rotated
notifempty

# Number of backups that will be kept
# This will keep the 2 newest backups only
rotate 2

# Create new empty files after rotating old ones
# This will create empty log files, with owner
# set to root, group set to sys, and permissions 644
create 0664 root sys

# Compress the backups with gzip
compress

# No packages own lastlog or wtmp -- rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
    rotate 1
}

/var/log/lastlog {
    monthly
    rotate 1
}

# Some packages drop log rotation info in this directory
# so we include any file in it.
include /etc/logrotate.d

# End of /etc/logrotate.conf
EOF

chmod -v 0644 /etc/logrotate.conf</userinput></screen>

    <para>Now create the <filename class='directory'>/etc/logrotate.d</filename>
    directory as the  <systemitem class="username">root</systemitem> user:</para>

<screen role="root"><userinput> mkdir -p /etc/logrotate.d</userinput></screen>

  <para>At this point additional log rotation commands can be entered, typically 
  in the <filename class='directory'>/etc/logrotate.d</filename> directory.
  For example:</para>

<screen role="root"><userinput>cat &gt; /etc/logrotate.d/sys.log &lt;&lt; EOF
/var/log/sys.log {
   # If the log file is larger than 100kb, rotate it
   size   100k
   rotate 5
   weekly
   postrotate
      /bin/killall -HUP syslogd
   endscript
}
EOF

chmod -v 0644 /etc/logrotate.d/sys.log</userinput></screen>

  <para>You can designate multiple files in one entry:</para>

<screen role="root"><userinput>cat &gt; /etc/logrotate.d/example.log &lt;&lt; EOF
file1
file2
file3 {
   ...
   postrotate
    ...
   endscript
}
EOF

chmod -v 0644 /etc/logrotate.d/example.log</userinput></screen>

  <para>You can use in the same line the list of files: file1 file2 file3.
  See the logrotate man page or 
  <ulink url='http://www.techrepublic.com/article/manage-linux-log-files-with-logrotate/'/>
  for more examples.</para>

  <para>The command <command>logrotate /etc/logrotate.conf</command> can be
  run manually, however, the command should be run daily.
  Other useful commands are <command>logrotate -d /etc/logrotate.conf</command>
  for debugging purposes and <command>logrotate -f /etc/logrotate.conf</command>
  forcing the logrotate commands to be run immediately. Combining the previous
  options <option>-df</option>, you can debug the effect of the force command.
  When debugging, the command is only simulated, not really run, thus, eventual
  non-existing errors appear, when some intermediate files are expected,
  because they are not actually created.</para>

  <para>To set up <xref linkend='fcron'/> to run
  <command>logrotate ...</command> at 3AM daily, root's crontab should be
  edited to add:</para>

<screen><literal>0 3 * * *   /usr/sbin/logrotate /etc/logrotate.conf</literal></screen>


  </sect2>

  <sect2 role="content">
    <title>Contents</title>

    <segmentedlist>
      <segtitle>Installed Programs</segtitle>
      <segtitle>Installed Library</segtitle>
      <segtitle>Installed Directories</segtitle>

      <seglistitem>
        <seg> logrotate </seg>
        <seg> None </seg>
        <seg> None </seg>
      </seglistitem>
    </segmentedlist>

    <variablelist>
      <bridgehead renderas="sect3">Short Descriptions</bridgehead>
      <?dbfo list-presentation="list"?>
      <?dbhtml list-presentation="table"?>

      <varlistentry id="logrotate-prog">
        <term><command>logrotate</command></term>
        <listitem>
          <para>
            performs the log maintenance functions defined in the 
            configuration files.
          </para>
          <indexterm zone="logrotate logrotate-prog">
            <primary sortas="b-logrotate-prog">logrotate</primary>
          </indexterm>
        </listitem>
      </varlistentry>

    </variablelist>

  </sect2>

</sect1>
