fititnt / ap-application-load-balancer

AP Application Load Balancer (AP-ALB). Sophisticated monolithic Ansible role to manage standalone and clusters of cross-platform and multicloud load balancers. Abstract HAProxy + OpenResty + On-the-fly auto HTTPS. Dedicated to Public Domain.
https://ap-application-load-balancer.etica.ai/
The Unlicense
1 stars 0 forks source link

Implement logrotate #9

Closed fititnt closed 5 years ago

fititnt commented 5 years ago

The current version of ALB does not rotate logs both for ALB itself and the apps. This issue if for implement at least one MVP of this for apps, and make good defaults for the logs of ALBs.

fititnt commented 5 years ago
root@a1:/etc/logrotate.d# cat alb
# Ansible managed
#
# FILE:             /etc/logrotate.d/alb
#
# TODO: implement logrotate for ALB (fititnt, 2019-11-07 21:49 BRT)
# @see https://linux.die.net/man/8/logrotate
# @see https://manpages.debian.org/jessie/logrotate/logrotate.8.en.html

# IMPORTANT NOTE: this logrotate file still need testing (fititnt, 2019-11-07 22:04 BRT) 

/var/log/alb/access.log /var/log/alb/error.log {
    daily
    minsize 1M
    rotate 365
    dateext
    missingok
    compress
    delaycompress
    missingok
    sharedscripts
    postrotate
        [ ! -f /usr/local/openresty/nginx/logs/nginx.pid ] || kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`
    endscript
}

/var/log/alb/letsencrypt.log {
    monthly
    rotate 48
    maxsize 10M
    dateext
    missingok
    compress
    delaycompress
    missingok
    sharedscripts
    postrotate
        [ ! -f /usr/local/openresty/nginx/logs/nginx.pid ] || kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`
    endscript
}root@a1:/etc/logrotate.d# logrotate -d alb
reading config file alb
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 2 logs

rotating pattern: /var/log/alb/access.log /var/log/alb/error.log  after 1 days (365 rotations)
empty log files are rotated, only log files >= 1048576 bytes are rotated, old logs are removed
considering log /var/log/alb/access.log
Creating new state
  Now: 2019-11-08 02:18
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
considering log /var/log/alb/error.log
Creating new state
  Now: 2019-11-08 02:18
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
not running postrotate script, since no logs were rotated

rotating pattern: /var/log/alb/letsencrypt.log  monthly (48 rotations)
empty log files are rotated, log files >= 10485760 are rotated earlier, old logs are removed
considering log /var/log/alb/letsencrypt.log
Creating new state
  Now: 2019-11-08 02:18
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
not running postrotate script, since no logs were rotated
root@a1:/etc/logrotate.d# cat alb_apps 
# Ansible managed
#
# FILE:             /etc/logrotate.d/alb_apps
#
# TODO: implement logrotate for ALB Apps (fititnt, 2019-11-07 21:49 BRT)
# @see https://linux.die.net/man/8/logrotate
# @see https://manpages.debian.org/jessie/logrotate/logrotate.8.en.html

# IMPORTANT NOTE: this logrotate file still need testing (fititnt, 2019-11-07 22:04 BRT) 

/var/log/app/*/access.log /var/log/app/*/error.log {
    monthly
    rotate 36
    maxsize 10M
    dateext
    missingok
    compress
    delaycompress
    missingok
    sharedscripts
    postrotate
        [ ! -f /usr/local/openresty/nginx/logs/nginx.pid ] || kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`
    endscript
}root@a1:/etc/logrotate.d# logrotate -d alb_apps 
reading config file alb_apps
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 1 logs

rotating pattern: /var/log/app/*/access.log /var/log/app/*/error.log  monthly (36 rotations)
empty log files are rotated, log files >= 10485760 are rotated earlier, old logs are removed
considering log /var/log/app/AAAAAAAAAAAA/access.log
Creating new state
  Now: 2019-11-08 02:20
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
considering log /var/log/app/BBBBBBBBBBBB/access.log
Creating new state
  Now: 2019-11-08 02:20
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
considering log /var/log/app/CCCCCCCCCCCC/access.log
Creating new state
  Now: 2019-11-08 02:20
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
considering log /var/log/app/DDDDDDDD/error.log
Creating new state
  Now: 2019-11-08 02:20
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
considering log /var/log/app/EEEEEEEE/error.log
Creating new state
  Now: 2019-11-08 02:20
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
considering log /var/log/app/haproxy-a1-vps/error.log
Creating new state
  Now: 2019-11-08 02:20
  Last rotated at 2019-11-08 02:00
  log does not need rotating (log has been already rotated)
not running postrotate script, since no logs were rotated