File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ #
4+ # This is to be run only for legacy logs in /var/log, not application logs in /var/log/runnable
5+ #
6+
7+ # we only want this run as root
8+ if [ " root" != ` whoami` ] ; then
9+ echo " ${0} : ERROR - This script needs to be run as root."
10+ exit 127
11+ fi
12+
13+ # legacy log path
14+ logdir=/var/log
15+ # store log archives here, purge manually
16+ archdir=/docker/archive
17+ datetime=` date +%Y%m%d%H%m`
18+
19+ # these logfiles haven't been modified in > 24 hours, so moving them without cleanup up filehandles first should be OK:
20+ echo " Compressing logs > 24h"
21+ find " ${logdir} " -maxdepth 2 -type f -mmin +1440 -name ' *.log' -exec bzip2 -9 {} \; -print
22+ echo " Restarting rsyslogd"
23+ # but we do need to clean the filehandles after, just in case
24+ service rsyslog restart
25+
26+ # archive anything > 6h
27+ echo " Archiving logs > 6h"
28+ mkdir -p " ${archdir} " 2>&1
29+ find " ${logdir} " -maxdepth 2 -type f -mtime +6 -name ' *z' | xargs tar jcvpf " ${archdir} " /log-archive-" ${datetime} " .tbz
30+ echo " Purging logs > 1wk"
31+ find " ${logdir} " -maxdepth 2 -type f -mtime +6 -exec rm -f {} \; -print
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ #
4+ # This is to be run logs in {{ app_log_dir }}.
5+ # Runs from crontab.
6+ #
7+
8+ logdir=" ${1} "
9+
10+ # We can compress anything older than 6 hours
11+ find " ${logdir} " -mindepth 2 -type f -mmin +360 -name ' *.log' -exec bzip2 -9 {} \;
12+
13+ # We automatically purge anything > 1wk
14+ find " ${logdir} " -maxdepth 2 -type f -mtime +7 -exec rm -f {} \;
Original file line number Diff line number Diff line change 8888 recurse=yes
8989
9090- name : restart rsyslog
91- tags : [loggly, deploy]
91+ tags : [ loggly, deploy ]
9292 become : true
9393 service : name=rsyslog state=restarted
9494
9999 minute="*/2"
100100 job="echo 'loggly monitoring' 2>&1 | /usr/bin/logger -t LogMonitor"
101101 state=present
102+
103+ - name : runnable bin directory
104+ tags : [ loggly, clean ]
105+ become : true
106+ file :
107+ path=/opt/runnable/bin
108+ state=directory
109+ owner=ubuntu
110+ group=ubuntu
111+ mode=0700
112+
113+ - name : copy log purge script
114+ tags : [ loggly, clean ]
115+ copy :
116+ src=purgeLogs.sh
117+ dest=/opt/runnable/bin/purgeLogs.sh
118+ owner=ubuntu
119+ group=ubuntu
120+ mode=0700
121+
122+ - name : purge log files
123+ tags : [ loggly, clean ]
124+ become : true
125+ cron :
126+ name="purge log files"
127+ minute=0
128+ job="/opt/runnable/bin/purgeLogs.sh {{ app_log_dir }}"
129+ state=present
130+
131+ - name : clean legacy log files
132+ tags : [ loggly, clean ]
133+ become : true
134+ script : archiveOldLogs.sh
135+ register : purge_out
You can’t perform that action at this time.
0 commit comments