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+ if [ " root" != ` whoami` ] ; then
8+ echo " It don't mean a thing if it ain't got that swing."
9+ exit 127
10+ fi
11+
12+ LOGDIR=/var/log
13+ ARCHDIR=/docker/archive
14+ DATE=` date +%Y%m%d%H%m`
15+
16+ # these haven't been modified in > 24 hours, so "doing it live" should be OK:
17+ echo " Compressing logs > 24h"
18+ find ${LOGDIR} -maxdepth 2 -type f -mmin +1440 -name ' *.log' -exec bzip2 -9 {} \; -print
19+ echo " Restarting rsyslogd"
20+ service rsyslog restart
21+
22+ # archive anything > 1wk
23+ echo " Archiving logs > 1wk"
24+ mkdir -p ${ARCHDIR} 2>&1
25+ find ${LOGDIR} -maxdepth 2 -type f -mtime +6 -name ' *z' | xargs tar jcvpf ${ARCHDIR} /log-archive-${DATE} .tbz
26+ echo " Purging logs > 1wk"
27+ 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+ # purge anything > 1wk
14+ find ${LOGDIR} -maxdepth 2 -type f -mtime +6 -exec rm -f {} \;
Original file line number Diff line number Diff line change 128128 minute="*/2"
129129 job="echo 'loggly monitoring' 2>&1 | /usr/bin/logger -t LogMonitor"
130130 state=present
131+
132+ - name : runnable bin directory
133+ tags : [loggly, deploy]
134+ become : true
135+ file :
136+ path=/opt/runnable/bin
137+ state=directory
138+ owner=ubuntu
139+ group=ubuntu
140+ mode=0700
141+
142+ - name : copy log purge script
143+ tags : [loggly, deploy]
144+ file :
145+ src=purgeLogs.sh
146+ dest=/opt/runnable/bin/purgeLogs.sh
147+ owner=ubuntu
148+ group=ubuntu
149+ mode=0700
150+
151+ - name : purge log files
152+ tags : [loggly, deploy]
153+ become : true
154+ cron :
155+ name="purge log files"
156+ minute=0
157+ job="/opt/runnable/bin/purgeLogs.sh {{ app_log_dir }}"
158+ state=present
159+
160+ - name : clean legacy log files
161+ tags : clean
162+ script : archiveOldLogs.sh
163+ register : purge_out
164+
You can’t perform that action at this time.
0 commit comments