Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ loggly_username: ops
## cores and logs
##

app_log_dir: /var/log
app_log_dir: /var/log/runnable
core_file_dir: /var/log/core

##
Expand Down
19 changes: 19 additions & 0 deletions ansible/roles/bash_aliases/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: copy bash aliases to ubuntu
tags: [ loggly, bash_aliases ]
template:
src=dot_bash_aliases.sh.j2
dest=/home/ubuntu/.bash_aliases
owner=ubuntu
group=ubuntu
mode=0700

- name: copy bash aliases to root
tags: [ loggly, bash_aliases ]
become: true
template:
src=dot_bash_aliases_root.sh.j2
dest=/root/.bash_aliases
owner=root
group=root
mode=0700
19 changes: 19 additions & 0 deletions ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/<app_name>.log)
# Usage: logtail <app_name>
function logtail() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's comment these functions similar to the way we comment them in dock-init, please and ty 👯

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the methods look like they do in dock-init:
https://github.com/CodeNow/dock-init/blob/master/lib/consul.sh#L28

local app_name="$1"
local datetime=`date +%Y/%m/%d/%H`
local app_log_dir="{{ app_log_dir }}"
local logfile="${app_log_dir}/${datetime}/${app_name}.log"
tail -f ${logfile} | bunyan
}

# Outputs contents of an npm start log for <app_name>, if it exists, into a pager for reading.
# Usage: npmlog <app_name>
function npmlog() {
local app_name="$1"
local app_log_dir="/var/log"
local logfile="${app_log_dir}/${app_name}.log"
less ${logfile}
}

19 changes: 19 additions & 0 deletions ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/<app_name>.log)
# Usage: logtail <app_name>
function logtail() {
local app_name="$1"
local datetime=`date +%Y/%m/%d/%H`
local app_log_dir="{{ app_log_dir }}"
local logfile="${app_log_dir}/${datetime}/${app_name}.log"
tail -f ${logfile} | bunyan
}

# Outputs contents of an npm start log for <app_name>, if it exists, into a pager for reading.
# Usage: npmlog <app_name>
function npmlog() {
local app_name="$1"
local app_log_dir="/var/log"
local logfile="${app_log_dir}/${app_name}.log"
less ${logfile}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ $KLogPermitNonKernelFacility on
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Runnable JSON logging format
# Creates an "output formatter" template that accepts as input JSON and prints it out without any further processing ("raw JSON").
# The formatting around the %msg% string is as such: start printing at the second character "2" until the end of the line "$" using the raw JSON format type.
$template RunnableJSON,"%msg:2:$:jsonr%\n"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead an add a comment that explains this line.


# Filter duplicated messages
$RepeatedMsgReduction on

Expand All @@ -43,11 +48,11 @@ $RepeatedMsgReduction on
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$FileCreateMode 0644
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog
$PrivDropToGroup adm

#
# Where to place spool and state files
Expand Down
3 changes: 3 additions & 0 deletions ansible/roles/loggly/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- { role: bash_aliases }
45 changes: 8 additions & 37 deletions ansible/roles/loggly/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@
owner=syslog
group=syslog

- name: create runnable bin directory
tags: loggly
become: true
file:
path=/opt/runnable/bin
state=directory
mode=0755
owner=ubuntu
group=ubuntu

- name: copy rotate util script
tags: loggly
become: true
template:
src=rotate-logs.sh.j2
dest=/opt/runnable/bin/rotate-{{ name }}-logs.sh
mode=0755

- name: copy app config
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we no longer need the rotate script at all? Is this somehow handled by rsyslog itself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Syslog will simply open a new log file every hour.

Actually, let me add one more thing...

tags: loggly
become: true
Expand All @@ -76,8 +58,8 @@
- name: copy rsyslog config
tags: loggly
become: true
template:
src=rsyslog.conf.j2
copy:
src=rsyslog.conf
dest=/etc/rsyslog.conf
owner=syslog
group=syslog
Expand All @@ -94,27 +76,16 @@
path=/var/spool/rsyslog/stat-{{ name }}
state=absent

- name: check for current log file
tags: [loggly, deploy]
stat: path="{{ app_log_dir }}/{{ name }}-daemon.log"
register: log_file

- name: remove old log file
when: log_file.stat.exists
tags: [loggly, deploy]
become: true
file:
path="{{ app_log_dir }}/{{ name }}-daemon.log"
state=absent

- name: touch the log file
tags: [loggly, deploy]
- name: ensure log path
tags: loggly
become: true
file:
path="{{ app_log_dir }}/{{ name }}-daemon.log"
state=touch
path="{{ app_log_dir }}"
state=directory
owner=syslog
group=adm
mode=0755
recurse=yes

- name: restart rsyslog
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need to restart every deploy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope ;)

tags: [loggly, deploy]
Expand Down
16 changes: 6 additions & 10 deletions ansible/roles/loggly/templates/21-output-syslog.conf.j2
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
$WorkDirectory /var/spool/rsyslog

# start log rotation via outchannel
# outchannel definition
$outchannel log_rotation_{{ name }},{{ app_log_dir }}/{{ name }}-daemon.log,524288000,/opt/runnable/bin/rotate-{{ name }}-logs.sh
# activate the channel and log everything to it
if $msg contains '{{ name }}' and $syslogfacility-text == 'local7' then :omfile:$log_rotation_{{ name }}
# end log rotation via outchannel
# Rotate per hour
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, are the log files actually removed from the system? How does this all work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean up handled in another PR

$template RotateHourly_{{ name }},"{{ app_log_dir }}/%$YEAR%/%$MONTH%/%$DAY%/%$HOUR%/{{ name }}.log"
if $msg contains '{{ name }}' and $syslogfacility-text == 'local7' then { action (type="omfile" DynaFile="RotateHourly_{{ name }}" template="RunnableJSON") }

# {{ name }} access file:
#Add a tag for {{ name }} events
# Loggly: Add a tag for {{ name }} events
$template LogglyFormat_{{ name }},"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [{{ loggly_token }}@41058 tag=\"runnable\" tag=\"{{ node_env }}\"] %msg%\n"
if $msg contains '{{ name }}' then @@logs-01.loggly.com:6514;LogglyFormat_{{ name }}
if $msg contains '{{ name }}' then stop
if $msg contains '{{ name }}' and $syslogfacility-text == 'local7' then @@logs-01.loggly.com:6514;LogglyFormat_{{ name }}
if $msg contains '{{ name }}' and $syslogfacility-text == 'local7' then stop
7 changes: 0 additions & 7 deletions ansible/roles/loggly/templates/rotate-logs.sh.j2

This file was deleted.