Skip to content

Commit 67a9bb5

Browse files
committed
Update the Papertrail recipe
Remove pidfile from DAEMON_ARGS so that it's not referenced twice in conf.d Remove remote_file remote_syslog_src_filepath - the wget block before it does the job Remove double slash in computed remote_syslog paths Add usage instructions to Papertrail README
1 parent 7e671e7 commit 67a9bb5

File tree

6 files changed

+73
-24
lines changed

6 files changed

+73
-24
lines changed

cookbooks/papertrail/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Papertrail Cookbook for EngineYard EYCloud
2+
=========
3+
4+
Papertrail is a service that provides hosted log management. See http://help.papertrailapp.com/ for details.
5+
6+
The official guide on how to run Papertrail on Engine Yard is [here](http://help.papertrailapp.com/kb/hosting-services/engine-yard/).
7+
8+
This recipe has been updated with changes from https://github.com/leonsodhi/ey-cloud-recipes/tree/master/cookbooks/papertrail. We also incorporate fixes as we encounter them.
9+
10+
## Usage
11+
12+
Add `include_recipe "papertrail"` to `main/recipes/default.rb`
13+
14+
Add the port and host from papertrailapp.com to `papertrail/recipes/default.rb`
15+

cookbooks/papertrail/recipes/default.rb

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
#
55
# thanks @indirect !
66
# Adapted from the original https://github.com/indirect/ey-cloud-recipes/tree/master/cookbooks/papertrail
7+
# and https://github.com/bhoggard/remote_syslog2
78
#
89
# This recipe makes EngineYard Gentoo instances send logs to Papertrail (papertrailapp.com).
910
# * syslog-ng is used to monitor syslog
10-
# * remote_syslog is used for other (application, database, etc.) logs
11+
# * remote_syslog2 is used for other (application, database, etc.) logs
1112
# * TLS is used instead of UDP
1213

1314
app_name = node[:applications].keys.first
1415
env = node[:environment][:framework_env]
1516
PAPERTRAIL_CONFIG = {
16-
:syslog_ng_version => '3.3.5',
17-
:remote_syslog_gem_version => '~>1.6',
18-
:port => 11111111111111, # YOUR PORT HERE
17+
:syslog_ng_version => '3.3.5-r1',
18+
:remote_syslog_version => 'v0.12',
19+
:remote_syslog_filename => 'remote_syslog_linux_amd64.tar.gz',
20+
:remote_syslog_checksum => 'ecb1ed1831ef9645c6379151fae6859bfe7db3ac9c6b096ae4a063dc79930a70',
21+
:port => 111111111111111, # YOUR PORT HERE
22+
:destination_host => 'HOST.papertrailapp.com', # YOUR HOST HERE
1923
:hostname => [app_name, node[:instance_role], `hostname`.chomp].join('_'),
2024
:other_logs => [
2125
'/var/log/engineyard/nginx/*log',
@@ -27,6 +31,9 @@
2731
'400 0 "-" "-" "-', # seen in ssl access logs
2832
],
2933
}
34+
remote_syslog_src_filename = PAPERTRAIL_CONFIG[:remote_syslog_filename]
35+
remote_syslog_src_filepath = "#{Chef::Config['file_cache_path']}#{remote_syslog_src_filename}"
36+
remote_syslog_extract_path = "#{Chef::Config['file_cache_path']}remote_syslog2/#{PAPERTRAIL_CONFIG[:remote_syslog_checksum]}"
3037

3138
# install syslog-ng
3239

@@ -46,19 +53,21 @@
4653
action :install
4754
end
4855

49-
remote_file '/etc/syslog.papertrail.crt' do
50-
source 'https://papertrailapp.com/tools/syslog.papertrail.crt'
51-
checksum '7d6bdd1c00343f6fe3b21db8ccc81e8cd1182c5039438485acac4d98f314fe10'
52-
mode '0644'
53-
end
54-
5556
directory '/etc/syslog-ng/cert.d' do
5657
recursive true
5758
end
5859

59-
link '/etc/syslog-ng/cert.d/2f2c2f7c.0' do
60-
to '/etc/syslog.papertrail.crt'
61-
link_type :symbolic
60+
remote_file '/etc/syslog-ng/cert.d/papertrail-bundle.tar.gz' do
61+
source 'https://papertrailapp.com/tools/papertrail-bundle.tar.gz'
62+
checksum '5590de7f7f957508eff58767212cae8fa2fb8cf503e5b5b801f32087501060f3'
63+
mode '0644'
64+
end
65+
66+
bash 'extract SSL certificates' do
67+
cwd '/etc/syslog-ng/cert.d'
68+
code <<-EOH
69+
tar xzf papertrail-bundle.tar.gz
70+
EOH
6271
end
6372

6473
template '/etc/syslog-ng/syslog-ng.conf' do
@@ -77,11 +86,36 @@
7786
command %{/etc/init.d/syslog-ng restart}
7887
end
7988

80-
# install remote_syslog daemon
89+
# remove remote_syslog gem & install remote_syslog2 daemon
90+
91+
execute 'stop existing instances of remote_syslog' do
92+
command %{/etc/init.d/remote_syslog stop}
93+
only_if { ::File.exists?("/etc/init.d/remote_syslog") }
94+
end
95+
96+
execute 'remove remote_syslog gem' do
97+
command %{gem uninstall remote_syslog -x}
98+
end
99+
100+
execute "Get remote_syslog" do
101+
command "wget -O #{remote_syslog_src_filepath} https://github.com/papertrail/remote_syslog2/releases/download/#{PAPERTRAIL_CONFIG[:remote_syslog_version]}/#{PAPERTRAIL_CONFIG[:remote_syslog_filename]}"
102+
end
103+
104+
bash 'extract and copy executable' do
105+
cwd ::File.dirname(remote_syslog_src_filepath)
106+
code <<-EOH
107+
mkdir -p #{remote_syslog_extract_path}
108+
tar xzf #{remote_syslog_src_filename} -C #{remote_syslog_extract_path}
109+
mv #{remote_syslog_extract_path}/remote_syslog/remote_syslog /usr/local/bin
110+
EOH
111+
not_if { ::File.exists?(remote_syslog_extract_path) }
112+
end
81113

82-
execute 'install remote_syslog gem' do
83-
command %{gem install remote_syslog -v '#{PAPERTRAIL_CONFIG[:remote_syslog_gem_version]}'}
84-
creates '/usr/bin/remote_syslog'
114+
file "/usr/local/bin/remote_syslog" do
115+
owner "root"
116+
group "root"
117+
mode "0755"
118+
action :touch
85119
end
86120

87121
# remote_syslog config file

cookbooks/papertrail/templates/default/log_files.yml.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ files:
44
exclude_patterns:
55
- <%= @exclude_patterns.join("\n - ") %>
66
destination:
7-
host: logs.papertrailapp.com
7+
host: <%= @destination_host %>
88
port: <%= @port %>
9-
ssl_server_cert: /etc/syslog.papertrail.crt
9+
protocol: tls

cookbooks/papertrail/templates/default/remote_syslog.confd.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Distributed under the terms of the Apache License, Version 2.0
33

44
NAME="remote_syslog"
5-
DAEMON="/usr/sbin/${NAME}"
5+
DAEMON="/usr/local/bin/${NAME}"
66
CONFIG="/etc/log_files.yml"
77
PIDFILE="/var/run/${NAME}.pid"
8-
DAEMON_ARGS="-c ${CONFIG} --pid-file ${PIDFILE} --tls"
8+
DAEMON_ARGS="-c ${CONFIG} --tls"

cookbooks/papertrail/templates/default/remote_syslog.initd.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ start() {
99
ebegin "Starting ${NAME}"
1010

1111
start-stop-daemon --start --pidfile $PIDFILE --name $NAME \
12-
--exec /usr/bin/remote_syslog -- $DAEMON_ARGS
12+
--exec /usr/local/bin/remote_syslog -- $DAEMON_ARGS
1313

1414
eend $?
1515
}
@@ -18,7 +18,7 @@ stop() {
1818
ebegin "Stopping ${NAME}"
1919

2020
start-stop-daemon --stop --pidfile $PIDFILE --name $NAME \
21-
--exec /usr/bin/remote_syslog
21+
--exec /usr/local/bin/remote_syslog
2222

2323
eend $?
2424
}

cookbooks/papertrail/templates/default/syslog-ng.conf.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ destination d_papertrail {
4343
# UDP (insecure)
4444
# udp("logs.papertrailapp.com" port(<%= @port %>));
4545
# TLS
46-
tcp("logs.papertrailapp.com" port(<%= @port %>) tls(ca_dir("/etc/syslog-ng/cert.d")) );
46+
tcp("<%= @destination_host %>" port(<%= @port %>) tls(ca_dir("/etc/syslog-ng/cert.d")) );
4747
};
4848
log {
4949
source(src); destination(d_papertrail);

0 commit comments

Comments
 (0)