Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fbdb11

Browse files
committed
NEW: cflogsink / syslog logging support
1 parent ab08573 commit 9fbdb11

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
=== (next) ===
3+
NEW: cflogsink / syslog logging support
4+
25
=== 0.12.0 (2017-02-09) ===
36
NEW: version bump of cf* series
47

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ Main setup and configuration of nginx web server.
175175
* `$cpu_weight = 100`
176176
* `$io_weight = 100`
177177
* `$settings_tune = {}` - tree for fine tune of nginx.conf
178+
* `cfweb = {}` - tune of `cfweb` itself
179+
- 'extra_files = 20000' - extra file descriptors, affects open file cache
180+
- 'mem_per_conn = 128' - expected memory requirement per connection in KiB
181+
- 'ssl_sess_factor = 3' - multiplier of max conn for ssl cache size
182+
- 'use_syslog' - auto-detected based on cflogsink::client
178183
* `$trusted_proxy = []` - list of trusted reverse-proxies
179184
* `$default_certs = {}` - cert names to use for the default catch all vhosts
180185
* `$backlog = 4096` - tune backlog

lib/puppet/provider/cfweb_nginx/cfweb.rb

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,36 @@ def self.on_config_change(newconf)
6767
worker_connections = (mem_limit * 1024 / mem_per_conn / worker_processes).to_i
6868
ssl_sess_factor = cfweb_tune.fetch('ssl_sess_factor', 3).to_i
6969
ssl_sess_per_mb = 4000
70-
71-
70+
71+
#---
72+
if cfweb_tune.fetch('use_syslog', false)
73+
access_log = "syslog:server=unix:/dev/hdlog,facility=local2,tag=access_#{service_name},nohostname vhosts"
74+
error_log = "syslog:server=unix:/dev/hdlog,facility=local1,tag=#{service_name},nohostname error"
75+
log_conf = {
76+
'error_log' => error_log,
77+
'access_log' => access_log,
78+
}
79+
else
80+
access_log = '/var/log/nginx/access.log vhosts'
81+
error_log = '/var/log/nginx/error.log error'
82+
log_conf = {}
83+
end
84+
85+
config_changed = cf_system.atomicWrite(
86+
"#{conf_dir}/log.conf",
87+
nginxConf( log_conf, 0),
88+
{
89+
:user => user,
90+
:mode => 0640,
91+
}
92+
)
93+
94+
#---
7295
global_conf = {
7396
'worker_processes' => worker_processes,
7497
'worker_cpu_affinity' => 'auto',
7598
'pcre_jit' => 'on',
76-
'error_log' => '/var/log/nginx/error.log error',
99+
'error_log' => error_log,
77100
}.merge(settings_tune.fetch('global', {}))
78101
worker_processes = global_conf['worker_processes'].to_i
79102

@@ -86,21 +109,21 @@ def self.on_config_change(newconf)
86109
max_conn = global_conf['worker_processes'].to_i *
87110
events_conf['worker_connections'].to_i
88111
ssl_sess_cache = (max_conn * ssl_sess_factor / ssl_sess_per_mb + 1).to_i
89-
112+
90113
http_conf = {
91114
'default_type' => 'application/octet-stream',
92115
#
93116
'log_format main' => [
94117
'\'$remote_addr - $remote_user [$time_local]',
95118
'"$request" $status $body_bytes_sent "$http_referer"',
96-
'"$http_user_agent" "$http_x_forwarded_for"\''
119+
'"$http_user_agent"\''
97120
].join(' '),
98121
'log_format vhosts' => [
99-
'\'$host $remote_addr - $remote_user [$time_local]',
122+
'\'$host:$server_port $remote_addr - $remote_user [$time_local]',
100123
'"$request" $status $body_bytes_sent "$http_referer"',
101-
'"$http_user_agent" "$http_x_forwarded_for"\''
124+
'"$http_user_agent" $request_time\''
102125
].join(' '),
103-
'access_log' => '/var/log/nginx/access.log vhosts',
126+
'access_log' => access_log,
104127
#
105128
'keepalive_timeout' => '65 60',
106129
'keepalive_requests' => 100,

manifests/nginx.pp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@
6161
$acme_challenge_group = $cfweb::acme_challenge_group
6262
$acme_challenge_root = $cfweb::acme_challenge_root
6363

64+
#---
65+
$act_settings_tune = merge(
66+
{
67+
cfweb => merge(
68+
{
69+
use_syslog => defined(Class['cflogsink::client']) or lookup('cflogsink::target')
70+
},
71+
pick($settings_tune['cfweb'], {})
72+
)
73+
},
74+
$settings_tune
75+
)
76+
77+
if $act_settings_tune['cfweb']['use_syslog'] {
78+
include cfsystem::hdsyslog
79+
}
80+
#---
81+
82+
6483
group { $group:
6584
ensure => present,
6685
}
@@ -85,7 +104,7 @@
85104
recurse => true,
86105
force => true,
87106
}
88-
-> file { "${conf_dir}/nginx.conf":
107+
-> file { [ "${conf_dir}/nginx.conf", "${conf_dir}/log.conf" ]:
89108
group => $group,
90109
mode => '0640',
91110
replace => false,
@@ -159,7 +178,7 @@
159178
memory_weight => $memory_weight,
160179
cpu_weight => $cpu_weight,
161180
io_weight => $io_weight,
162-
settings_tune => $settings_tune,
181+
settings_tune => $act_settings_tune,
163182
service_name => $service_name,
164183
limits => $limits,
165184
stress_hosts => $stress_hosts,

templates/app_vhost.epp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ server {
106106
listen <%= $l %>;
107107
<% } -%>
108108

109+
# NOTE: it's not redundant, there are some fine moments in log handling in server block
110+
include /etc/nginx/log.conf;
111+
109112
<%= $tls_snippet -%>
110113
<%= $trust_proxy_snippet -%>
111114

@@ -159,6 +162,8 @@ server {
159162
listen <%= $l %>;
160163
<% } -%>
161164

165+
# NOTE: it's not redundant, there are some fine moments in log handling in server block
166+
include /etc/nginx/log.conf;
162167

163168
<%= $trust_proxy_snippet -%>
164169
<%= $acme_challenge_snippet %>
@@ -176,6 +181,9 @@ server {
176181
server {
177182
server_name <%= $alt_names.join(' ') %>;
178183

184+
# NOTE: it's not redundant, there are some fine moments in log handling in server block
185+
include /etc/nginx/log.conf;
186+
179187
<% $listen_plain.each |$l| { -%>
180188
listen <%= $l %>;
181189
<% } -%>

templates/default_vhost.epp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ server {
2525
<% } -%>
2626
;
2727

28+
# NOTE: it's not redundant, there are some fine moments in log handling in server block
29+
include /etc/nginx/log.conf;
2830

2931
<% if $proxy_protocol { -%>
3032
<% $trusted_proxy.each |$p| { -%>

0 commit comments

Comments
 (0)