From 90a9325b33fae983391fa209e7eb952fba55e8cd Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Tue, 19 Apr 2016 16:21:45 -0700 Subject: [PATCH 01/13] JSON format (of a sort) --- ansible/group_vars/all.yml | 2 +- .../rsyslog.conf.j2 => files/rsyslog.conf} | 3 ++ ansible/roles/loggly/tasks/main.yml | 41 +++---------------- .../loggly/templates/21-output-syslog.conf.j2 | 16 +++----- .../roles/loggly/templates/rotate-logs.sh.j2 | 7 ---- 5 files changed, 15 insertions(+), 54 deletions(-) rename ansible/roles/loggly/{templates/rsyslog.conf.j2 => files/rsyslog.conf} (95%) delete mode 100644 ansible/roles/loggly/templates/rotate-logs.sh.j2 diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 287eed7a..8c9757a8 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -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 ## diff --git a/ansible/roles/loggly/templates/rsyslog.conf.j2 b/ansible/roles/loggly/files/rsyslog.conf similarity index 95% rename from ansible/roles/loggly/templates/rsyslog.conf.j2 rename to ansible/roles/loggly/files/rsyslog.conf index 5621cf3b..8eb8c435 100644 --- a/ansible/roles/loggly/templates/rsyslog.conf.j2 +++ b/ansible/roles/loggly/files/rsyslog.conf @@ -35,6 +35,9 @@ $KLogPermitNonKernelFacility on # $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat +# Runnable JSON logging format +$template RunnableJSON,"\n%msg%" + # Filter duplicated messages $RepeatedMsgReduction on diff --git a/ansible/roles/loggly/tasks/main.yml b/ansible/roles/loggly/tasks/main.yml index e427b2aa..a2182002 100644 --- a/ansible/roles/loggly/tasks/main.yml +++ b/ansible/roles/loggly/tasks/main.yml @@ -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 tags: loggly become: true @@ -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 @@ -94,25 +76,12 @@ 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 +- name: ensure log path tags: [loggly, deploy] become: true file: - path="{{ app_log_dir }}/{{ name }}-daemon.log" - state=absent - -- name: touch the log file - tags: [loggly, deploy] - become: true - file: - path="{{ app_log_dir }}/{{ name }}-daemon.log" - state=touch + path="{{ app_log_dir }}" + state=directory owner=syslog group=adm diff --git a/ansible/roles/loggly/templates/21-output-syslog.conf.j2 b/ansible/roles/loggly/templates/21-output-syslog.conf.j2 index 94a449bc..3a0e8697 100644 --- a/ansible/roles/loggly/templates/21-output-syslog.conf.j2 +++ b/ansible/roles/loggly/templates/21-output-syslog.conf.j2 @@ -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 +$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 diff --git a/ansible/roles/loggly/templates/rotate-logs.sh.j2 b/ansible/roles/loggly/templates/rotate-logs.sh.j2 deleted file mode 100644 index 69c3f8b9..00000000 --- a/ansible/roles/loggly/templates/rotate-logs.sh.j2 +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -# literally truncate the file -cat /dev/null > {{ app_log_dir }}/{{ name }}-daemon.log 2>&1 -# exit code? don't care - -exit 0 From a6ce7b7fd1d9d939bd79a964caad40610caf76d0 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Tue, 19 Apr 2016 17:58:25 -0700 Subject: [PATCH 02/13] hacking around weird syslog RFC leading space --- ansible/roles/container_kill_start/tasks/main.yml | 4 ++-- ansible/roles/loggly/files/rsyslog.conf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ansible/roles/container_kill_start/tasks/main.yml b/ansible/roles/container_kill_start/tasks/main.yml index f8ce7e3b..452e1b14 100644 --- a/ansible/roles/container_kill_start/tasks/main.yml +++ b/ansible/roles/container_kill_start/tasks/main.yml @@ -64,8 +64,8 @@ command: > sudo docker run --log-driver={{ log_driver }} - --log-opt syslog-facility={{ log_facility }} - --log-opt tag="{{ log_tag | default ( name ) }}" + #--log-opt syslog-facility={{ log_facility }} + #--log-opt tag="{{ log_tag | default ( name ) }}" -v {{ app_log_dir }}:{{ app_log_dir }}:rw --restart={{ restart_policy | default('always') }} {{ container_run_opts}} diff --git a/ansible/roles/loggly/files/rsyslog.conf b/ansible/roles/loggly/files/rsyslog.conf index 8eb8c435..1dbaa576 100644 --- a/ansible/roles/loggly/files/rsyslog.conf +++ b/ansible/roles/loggly/files/rsyslog.conf @@ -36,7 +36,7 @@ $KLogPermitNonKernelFacility on $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # Runnable JSON logging format -$template RunnableJSON,"\n%msg%" +$template RunnableJSON,"%msg:2:1048576:jsonr%\n" # Filter duplicated messages $RepeatedMsgReduction on From 82bce3d7999eca969be87b3eff04138d76c53da1 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Wed, 20 Apr 2016 05:46:22 -0700 Subject: [PATCH 03/13] read %msg% until end of line --- ansible/roles/loggly/files/rsyslog.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/roles/loggly/files/rsyslog.conf b/ansible/roles/loggly/files/rsyslog.conf index 1dbaa576..b91ea289 100644 --- a/ansible/roles/loggly/files/rsyslog.conf +++ b/ansible/roles/loggly/files/rsyslog.conf @@ -36,7 +36,7 @@ $KLogPermitNonKernelFacility on $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # Runnable JSON logging format -$template RunnableJSON,"%msg:2:1048576:jsonr%\n" +$template RunnableJSON,"%msg:2:$:jsonr%\n" # Filter duplicated messages $RepeatedMsgReduction on From c03d5538250b38db0934dd19926bf0483ef77084 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Thu, 21 Apr 2016 12:10:47 -0700 Subject: [PATCH 04/13] Update main.yml --- ansible/roles/container_kill_start/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/container_kill_start/tasks/main.yml b/ansible/roles/container_kill_start/tasks/main.yml index 9442336e..84f2e2d3 100644 --- a/ansible/roles/container_kill_start/tasks/main.yml +++ b/ansible/roles/container_kill_start/tasks/main.yml @@ -71,8 +71,8 @@ command: > docker run --log-driver={{ log_driver }} - #--log-opt syslog-facility={{ log_facility }} - #--log-opt tag="{{ log_tag | default ( name ) }}" + --log-opt syslog-facility={{ log_facility }} + --log-opt tag="{{ log_tag | default ( name ) }}" -v {{ app_log_dir }}:{{ app_log_dir }}:rw --restart={{ restart_policy | default('always') }} {{ container_run_opts }} From 550ed44fb91d4a9632fdc5f6a9f1370321ee9741 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Fri, 22 Apr 2016 11:45:47 -0700 Subject: [PATCH 05/13] recursively set modes for logdir --- ansible/roles/loggly/tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ansible/roles/loggly/tasks/main.yml b/ansible/roles/loggly/tasks/main.yml index a2182002..a72f3fb8 100644 --- a/ansible/roles/loggly/tasks/main.yml +++ b/ansible/roles/loggly/tasks/main.yml @@ -84,6 +84,8 @@ state=directory owner=syslog group=adm + mode=0755 + recurse=yes - name: restart rsyslog tags: [loggly, deploy] From 7f9d8048f35a0592ddb0855333f8e6eadc7a7fb7 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Fri, 22 Apr 2016 12:04:32 -0700 Subject: [PATCH 06/13] bash aliases (functions, really) --- ansible/roles/bash_aliases/tasks/main.yml | 19 +++++++++++++++++++ .../templates/dot_bash_aliases.sh.j2 | 17 +++++++++++++++++ .../templates/dot_bash_aliases_root.sh.j2 | 17 +++++++++++++++++ ansible/roles/loggly/meta/main.yml | 3 +++ 4 files changed, 56 insertions(+) create mode 100644 ansible/roles/bash_aliases/tasks/main.yml create mode 100644 ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 create mode 100644 ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 create mode 100644 ansible/roles/loggly/meta/main.yml diff --git a/ansible/roles/bash_aliases/tasks/main.yml b/ansible/roles/bash_aliases/tasks/main.yml new file mode 100644 index 00000000..0c5db8d0 --- /dev/null +++ b/ansible/roles/bash_aliases/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: copy bash aliases to ubuntu + tags: 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: bash_aliases + become: true + template: + src=dot_bash_aliases_root.sh.j2 + dest=/root/.bash_aliases + owner=root + group=root + mode=0700 diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 new file mode 100644 index 00000000..9d3094a8 --- /dev/null +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 @@ -0,0 +1,17 @@ +# not really an alias +function logtail() { + MY_APP="$1" + MY_DATE=`date +%Y/%m/%d/%H` + MY_LOGDIR="{{ app_log_dir }}" + MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}-daemon.log" + tail -f ${MY_LOGFILE} | bunyan +} + +function npmlog() { + MY_APP="$1" + MY_DATE=`date +%Y/%m/%d/%H` + MY_LOGDIR="{{ app_log_dir }}" + MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}.log" + less ${MY_LOGFILE} +} + diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 new file mode 100644 index 00000000..9d3094a8 --- /dev/null +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 @@ -0,0 +1,17 @@ +# not really an alias +function logtail() { + MY_APP="$1" + MY_DATE=`date +%Y/%m/%d/%H` + MY_LOGDIR="{{ app_log_dir }}" + MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}-daemon.log" + tail -f ${MY_LOGFILE} | bunyan +} + +function npmlog() { + MY_APP="$1" + MY_DATE=`date +%Y/%m/%d/%H` + MY_LOGDIR="{{ app_log_dir }}" + MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}.log" + less ${MY_LOGFILE} +} + diff --git a/ansible/roles/loggly/meta/main.yml b/ansible/roles/loggly/meta/main.yml new file mode 100644 index 00000000..1d1930df --- /dev/null +++ b/ansible/roles/loggly/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: bash_aliases } From ce654465d9e21bfb3b7a19c8c3dbb7e7f3c176bd Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Fri, 22 Apr 2016 13:32:33 -0700 Subject: [PATCH 07/13] Cuple of changes to fix --- ansible/roles/bash_aliases/tasks/main.yml | 4 ++-- .../roles/bash_aliases/templates/dot_bash_aliases.sh.j2 | 7 +++---- .../bash_aliases/templates/dot_bash_aliases_root.sh.j2 | 7 +++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ansible/roles/bash_aliases/tasks/main.yml b/ansible/roles/bash_aliases/tasks/main.yml index 0c5db8d0..3e69eb04 100644 --- a/ansible/roles/bash_aliases/tasks/main.yml +++ b/ansible/roles/bash_aliases/tasks/main.yml @@ -1,6 +1,6 @@ --- - name: copy bash aliases to ubuntu - tags: bash_aliases + tags: [ loggly, deploy ] template: src=dot_bash_aliases.sh.j2 dest=/home/ubuntu/.bash_aliases @@ -9,7 +9,7 @@ mode=0700 - name: copy bash aliases to root - tags: bash_aliases + tags: [ loggly, deploy ] become: true template: src=dot_bash_aliases_root.sh.j2 diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 index 9d3094a8..43b694f2 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 @@ -3,15 +3,14 @@ function logtail() { MY_APP="$1" MY_DATE=`date +%Y/%m/%d/%H` MY_LOGDIR="{{ app_log_dir }}" - MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}-daemon.log" + MY_LOGFILE="${MY_LOGDIR}/${MY_DATE}/${MY_APP}.log" tail -f ${MY_LOGFILE} | bunyan } function npmlog() { MY_APP="$1" - MY_DATE=`date +%Y/%m/%d/%H` - MY_LOGDIR="{{ app_log_dir }}" - MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}.log" + MY_LOGDIR="/var/log" + MY_LOGFILE="${MY_LOGDIR}/${MY_APP}.log" less ${MY_LOGFILE} } diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 index 9d3094a8..43b694f2 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 @@ -3,15 +3,14 @@ function logtail() { MY_APP="$1" MY_DATE=`date +%Y/%m/%d/%H` MY_LOGDIR="{{ app_log_dir }}" - MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}-daemon.log" + MY_LOGFILE="${MY_LOGDIR}/${MY_DATE}/${MY_APP}.log" tail -f ${MY_LOGFILE} | bunyan } function npmlog() { MY_APP="$1" - MY_DATE=`date +%Y/%m/%d/%H` - MY_LOGDIR="{{ app_log_dir }}" - MY_LOGFILE="${MY_LOG_DIR}/${MY_DATE}/${MY_APP}.log" + MY_LOGDIR="/var/log" + MY_LOGFILE="${MY_LOGDIR}/${MY_APP}.log" less ${MY_LOGFILE} } From c05e0a72a515da66db54332c91d58248d4622c3c Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Fri, 22 Apr 2016 13:54:25 -0700 Subject: [PATCH 08/13] style fixes and comments --- .../templates/dot_bash_aliases.sh.j2 | 28 +++++++++++++------ .../templates/dot_bash_aliases_root.sh.j2 | 28 +++++++++++++------ ansible/roles/loggly/files/rsyslog.conf | 2 ++ 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 index 43b694f2..680dce81 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 @@ -1,16 +1,26 @@ # not really an alias function logtail() { - MY_APP="$1" - MY_DATE=`date +%Y/%m/%d/%H` - MY_LOGDIR="{{ app_log_dir }}" - MY_LOGFILE="${MY_LOGDIR}/${MY_DATE}/${MY_APP}.log" - tail -f ${MY_LOGFILE} | bunyan +# Usage: logtail + # Name of the app log you wish you view, eg: api, navi, docker-listener, swarm-manager + local app_name="$1" + # string of the current year, month, day and hour in YYYY/MM/DD/HH format + local datetime=`date +%Y/%m/%d/%H` + # location of application logs specified in ansible configuration + local app_log_dir="{{ app_log_dir }}" + # concatenate this strings to derive the full log path + local logfile="${app_log_dir}/${datetime}/${app_name}.log" + # follow logfile, format via bunyan + tail -f ${logfile} | bunyan } function npmlog() { - MY_APP="$1" - MY_LOGDIR="/var/log" - MY_LOGFILE="${MY_LOGDIR}/${MY_APP}.log" - less ${MY_LOGFILE} +# Usage: npmlog + # Name of the app npm log you wish to view. + local app_name="$1" + # system log dir + local app_log_dir="/var/log" + # npm log + local logfile="${app_log_dir}/${app_name}.log" + less ${logfile} } diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 index 43b694f2..680dce81 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 @@ -1,16 +1,26 @@ # not really an alias function logtail() { - MY_APP="$1" - MY_DATE=`date +%Y/%m/%d/%H` - MY_LOGDIR="{{ app_log_dir }}" - MY_LOGFILE="${MY_LOGDIR}/${MY_DATE}/${MY_APP}.log" - tail -f ${MY_LOGFILE} | bunyan +# Usage: logtail + # Name of the app log you wish you view, eg: api, navi, docker-listener, swarm-manager + local app_name="$1" + # string of the current year, month, day and hour in YYYY/MM/DD/HH format + local datetime=`date +%Y/%m/%d/%H` + # location of application logs specified in ansible configuration + local app_log_dir="{{ app_log_dir }}" + # concatenate this strings to derive the full log path + local logfile="${app_log_dir}/${datetime}/${app_name}.log" + # follow logfile, format via bunyan + tail -f ${logfile} | bunyan } function npmlog() { - MY_APP="$1" - MY_LOGDIR="/var/log" - MY_LOGFILE="${MY_LOGDIR}/${MY_APP}.log" - less ${MY_LOGFILE} +# Usage: npmlog + # Name of the app npm log you wish to view. + local app_name="$1" + # system log dir + local app_log_dir="/var/log" + # npm log + local logfile="${app_log_dir}/${app_name}.log" + less ${logfile} } diff --git a/ansible/roles/loggly/files/rsyslog.conf b/ansible/roles/loggly/files/rsyslog.conf index b91ea289..eac82082 100644 --- a/ansible/roles/loggly/files/rsyslog.conf +++ b/ansible/roles/loggly/files/rsyslog.conf @@ -36,6 +36,8 @@ $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" # Filter duplicated messages From 56e87a7e3aceb331bed1388de5142a8c938babb6 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Fri, 22 Apr 2016 14:10:06 -0700 Subject: [PATCH 09/13] Fix stupid syslog permissions. --- ansible/roles/loggly/files/rsyslog.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/loggly/files/rsyslog.conf b/ansible/roles/loggly/files/rsyslog.conf index eac82082..9a76afee 100644 --- a/ansible/roles/loggly/files/rsyslog.conf +++ b/ansible/roles/loggly/files/rsyslog.conf @@ -48,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 From d03aadb2033697cc208ffa34d07fb14fe2a909f1 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Fri, 22 Apr 2016 14:32:45 -0700 Subject: [PATCH 10/13] normalize comments per style standards --- .../bash_aliases/templates/dot_bash_aliases.sh.j2 | 15 ++++----------- .../templates/dot_bash_aliases_root.sh.j2 | 15 ++++----------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 index 680dce81..1aac7571 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 @@ -1,25 +1,18 @@ -# not really an alias -function logtail() { +# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/.log # Usage: logtail - # Name of the app log you wish you view, eg: api, navi, docker-listener, swarm-manager +function logtail() { local app_name="$1" - # string of the current year, month, day and hour in YYYY/MM/DD/HH format local datetime=`date +%Y/%m/%d/%H` - # location of application logs specified in ansible configuration local app_log_dir="{{ app_log_dir }}" - # concatenate this strings to derive the full log path local logfile="${app_log_dir}/${datetime}/${app_name}.log" - # follow logfile, format via bunyan tail -f ${logfile} | bunyan } -function npmlog() { +# Outputs contents of an npm start log for , if it exists, into a pager for reading. # Usage: npmlog - # Name of the app npm log you wish to view. +function npmlog() { local app_name="$1" - # system log dir local app_log_dir="/var/log" - # npm log local logfile="${app_log_dir}/${app_name}.log" less ${logfile} } diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 index 680dce81..1aac7571 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 @@ -1,25 +1,18 @@ -# not really an alias -function logtail() { +# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/.log # Usage: logtail - # Name of the app log you wish you view, eg: api, navi, docker-listener, swarm-manager +function logtail() { local app_name="$1" - # string of the current year, month, day and hour in YYYY/MM/DD/HH format local datetime=`date +%Y/%m/%d/%H` - # location of application logs specified in ansible configuration local app_log_dir="{{ app_log_dir }}" - # concatenate this strings to derive the full log path local logfile="${app_log_dir}/${datetime}/${app_name}.log" - # follow logfile, format via bunyan tail -f ${logfile} | bunyan } -function npmlog() { +# Outputs contents of an npm start log for , if it exists, into a pager for reading. # Usage: npmlog - # Name of the app npm log you wish to view. +function npmlog() { local app_name="$1" - # system log dir local app_log_dir="/var/log" - # npm log local logfile="${app_log_dir}/${app_name}.log" less ${logfile} } From 899fed24d3f9c41109239a60dcebc2ef0f125dc7 Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Fri, 22 Apr 2016 14:35:13 -0700 Subject: [PATCH 11/13] close ) in comment for reasons --- ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 | 2 +- .../roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 index 1aac7571..59fb4b81 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases.sh.j2 @@ -1,4 +1,4 @@ -# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/.log +# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/.log) # Usage: logtail function logtail() { local app_name="$1" diff --git a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 index 1aac7571..59fb4b81 100644 --- a/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 +++ b/ansible/roles/bash_aliases/templates/dot_bash_aliases_root.sh.j2 @@ -1,4 +1,4 @@ -# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/.log +# Follows the logfile for a given app_name interpolating the datetime string into the logpath (/var/log/runnable/YYYY/MM/DD/HH/.log) # Usage: logtail function logtail() { local app_name="$1" From 1e448121f63c7dfabed1f196d4d3e6d7c8d66a3b Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Mon, 25 Apr 2016 16:12:22 -0700 Subject: [PATCH 12/13] cleanup tags --- ansible/roles/bash_aliases/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/bash_aliases/tasks/main.yml b/ansible/roles/bash_aliases/tasks/main.yml index 3e69eb04..d0fd92ba 100644 --- a/ansible/roles/bash_aliases/tasks/main.yml +++ b/ansible/roles/bash_aliases/tasks/main.yml @@ -1,6 +1,6 @@ --- - name: copy bash aliases to ubuntu - tags: [ loggly, deploy ] + tags: [ loggly, bash_aliases ] template: src=dot_bash_aliases.sh.j2 dest=/home/ubuntu/.bash_aliases @@ -9,7 +9,7 @@ mode=0700 - name: copy bash aliases to root - tags: [ loggly, deploy ] + tags: [ loggly, bash_aliases ] become: true template: src=dot_bash_aliases_root.sh.j2 From 4b44befac4b3f01bf0061f66d2bf03245d8efb1c Mon Sep 17 00:00:00 2001 From: "Christopher M. Neill" Date: Mon, 25 Apr 2016 16:20:42 -0700 Subject: [PATCH 13/13] also clean this up --- ansible/roles/loggly/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/roles/loggly/tasks/main.yml b/ansible/roles/loggly/tasks/main.yml index a72f3fb8..078a570f 100644 --- a/ansible/roles/loggly/tasks/main.yml +++ b/ansible/roles/loggly/tasks/main.yml @@ -77,7 +77,7 @@ state=absent - name: ensure log path - tags: [loggly, deploy] + tags: loggly become: true file: path="{{ app_log_dir }}"