SlapOS Home SlapOS

    How to Add Logrotate

    How to add logrotate
    • Last Update:2022-04-07
    • Version:002
    • Language:en

    Agenda

    • Prerequisite
    • Add Logrotate entry
    • Verification

    A production server generates a lot of logs, so it is necessary to rotate said logs. Logrotate is the main tool in SlapOS.

    This tutorial explains how to add a logrotate entry inside the instances of your software release for remote monitoring.

    Here are the commits introducing this functionality to html5as Software release: commit diff

    Prerequisite

    Add Logrotate entry

    In instance_html5as.cfg.in, add a logrotate entry for Nginx logs. Note the we use the post command as recommended in Nginx documentation to reopen log after rotation.

    Log rotation can be further customized, you can check the list of parameter in instance-logrotate-base.cfg.in

    # Monitor Stack also provides logrotate stack. We only need to extend
    # the logrotate-entry-base defined in instance-logrotate-base.cfg.in .
    # More parameters can be added following the logrotate-entry-base section
    [logrotate-entry-nginx]
    <= logrotate-entry-base
    name = nginx
    log = ${html5as:path_access_log} ${html5as:path_error_log}
    post = kill -USR1 $(cat ${html5as:path_pid})
    

    Process logrotate entry

    Add the new section to the list of parts to be processed in instance_html5as.cfg.in

    [buildout]
    parts =
        ...
        logrotate-entry-nginx
        ...

    Update md5sums

    Refer How To Move to md5sum automatic update to update md5sum:

    $ cd ~/srv/project/slapos/software/html5as-base
    $ ../../update-hash

    Validation

    1. Inspect the logs
    2. Verify the content in logrotate.d directory

    Compile and Instantiate

    Re-compile the software by

    $ slapos node software --all

    Once it completes, you may re-instantiate it by

    $ slapos node instance --all

    Check the output to make sure it has been deployed and installed.

    Verify the content in logrotate.d/

    Change directory:

    $ cd ~/srv/runner/instance/slappart0/

    List the content in logrotate.d/

    $ ls etc/logrotate.d/

    The content inside will be:

    crond monitor-apache monitor.data monitor.service.status nginx
    

    You may also browse EXPLORER to locate logrotate.d directory.