From e35d314e378e3304933c5457e8ba498f114402d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guzm=C3=A1n=20Bras=C3=B3?= Date: Thu, 27 Sep 2012 18:55:33 -0300 Subject: [PATCH 1/5] Summary: Fixed error from cat when trying nginx.d/* on nodes without vhosts defined Description: When running first time from scratch, if class was included without any setup at all and with sane defaults, in debian squeeze generates an error when trying to collect non existant vhosts, because cat complains that can not expand * because there are no files. Changed: Added unless to check that at least there is a file in nginx.d by testing it can expand. --- manifests/service.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/service.pp b/manifests/service.pp index 6d78a00..66dfe02 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -17,6 +17,7 @@ class nginx::service { exec { 'rebuild-nginx-vhosts': command => "/bin/cat ${nginx::params::nx_temp_dir}/nginx.d/* > ${nginx::params::nx_conf_dir}/conf.d/vhost_autogen.conf", refreshonly => true, + unless => "/usr/bin/test ! -f ${nginx::params::nx_temp_dir}/nginx.d/*", subscribe => File["${nginx::params::nx_temp_dir}/nginx.d"], } service { "nginx": From 1ccca88dc2db85bda0ec8ad927b38e6b097a852a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guzm=C3=A1n=20Bras=C3=B3?= Date: Fri, 28 Sep 2012 13:59:32 -0300 Subject: [PATCH 2/5] Moved worker_connections, worker_process and proxy_set_header to the new structure, backwards compatible Defaults are set inside params, nginx class will set default and send it from local var to nginx::config, so even when there is no need for set default values on nginx::config, in case someone already using this module it's for some reason calling directly nginx::config, to avoid breaking anything defaults are set inside nginx::config too. --- manifests/config.pp | 6 +++++- manifests/init.pp | 13 ++++++++++--- templates/conf.d/nginx.conf.erb | 4 ++-- templates/conf.d/proxy.conf.erb | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index c6135fd..25c96f9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -13,7 +13,11 @@ # Sample Usage: # # This class file is not called directly -class nginx::config inherits nginx::params { +class nginx::config( + $worker_processes = $nginx::params::nx_worker_processes, + $worker_connections = $nginx::params::nx_worker_connections, + $proxy_set_header = $nginx::params::nx_proxy_set_header +) inherits nginx::params { File { owner => 'root', group => 'root', diff --git a/manifests/init.pp b/manifests/init.pp index ad3afbb..d117f51 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -28,7 +28,11 @@ # node default { # include nginx # } -class nginx { +class nginx ( + $worker_processes = $nginx::params::nx_worker_processes, + $worker_connections = $nginx::params::nx_worker_connections, + $proxy_set_header = $nginx::params::nx_proxy_set_header +) inherits nginx::params { include stdlib @@ -37,8 +41,11 @@ class nginx { } class { 'nginx::config': - require => Class['nginx::package'], - notify => Class['nginx::service'], + worker_processes => $worker_processes, + worker_connections => $worker_connections, + proxy_set_header => $proxy_set_header, + require => Class['nginx::package'], + notify => Class['nginx::service'], } class { 'nginx::service': } diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 71a5aaf..20e0967 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -1,11 +1,11 @@ user <%= scope.lookupvar('nginx::config::nx_daemon_user') %>; -worker_processes <%= scope.lookupvar('nginx::params::nx_worker_processes')%>; +worker_processes <%= worker_processes %>; error_log <%= scope.lookupvar('nginx::params::nx_logdir')%>/error.log; pid <%= scope.lookupvar('nginx::params::nx_pid')%>; events { - worker_connections <%= scope.lookupvar('nginx::params::nx_worker_connections') %>; + worker_connections <%= worker_connections %>; <% if scope.lookupvar('nginx::params::nx_multi_accept' == 'on') %>multi_accept on;<% end %> } diff --git a/templates/conf.d/proxy.conf.erb b/templates/conf.d/proxy.conf.erb index 677e2d3..b05d71d 100644 --- a/templates/conf.d/proxy.conf.erb +++ b/templates/conf.d/proxy.conf.erb @@ -5,6 +5,6 @@ proxy_connect_timeout <%= scope.lookupvar('nginx::params::nx_proxy_connect_tim proxy_send_timeout <%= scope.lookupvar('nginx::params::nx_proxy_send_timeout') %>; proxy_read_timeout <%= scope.lookupvar('nginx::params::nx_proxy_read_timeout') %>; proxy_buffers <%= scope.lookupvar('nginx::params::nx_proxy_buffers') %>; -<% scope.lookupvar('nginx::params::nx_proxy_set_header').each do |header| %> +<% proxy_set_header.each do |header| %> proxy_set_header <%= header %>; <% end %> From 7f7c7ac37da7e49446ee1f145bbac44a867ce9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guzm=C3=A1n=20Bras=C3=B3?= Date: Sun, 30 Sep 2012 05:30:04 -0300 Subject: [PATCH 3/5] Added purge support in confd. Added confd_purge option to tell it to purge files non managed by pupet in conf.d, default is false. --- manifests/config.pp | 10 +++++++++- manifests/init.pp | 4 +++- manifests/params.pp | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 25c96f9..9f00a3e 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -16,7 +16,8 @@ class nginx::config( $worker_processes = $nginx::params::nx_worker_processes, $worker_connections = $nginx::params::nx_worker_connections, - $proxy_set_header = $nginx::params::nx_proxy_set_header + $proxy_set_header = $nginx::params::nx_proxy_set_header, + $confd_purge = $nginx::params::nx_confd_purge, ) inherits nginx::params { File { owner => 'root', @@ -31,6 +32,13 @@ class nginx::config( file { "${nginx::params::nx_conf_dir}/conf.d": ensure => directory, } + if $confd_purge == true { + File["${nginx::params::nx_conf_dir}/conf.d"] { + purge => true, + recurse => true, + } + } + file { "${nginx::config::nx_run_dir}": ensure => directory, diff --git a/manifests/init.pp b/manifests/init.pp index d117f51..99def01 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -31,7 +31,8 @@ class nginx ( $worker_processes = $nginx::params::nx_worker_processes, $worker_connections = $nginx::params::nx_worker_connections, - $proxy_set_header = $nginx::params::nx_proxy_set_header + $proxy_set_header = $nginx::params::nx_proxy_set_header, + $confd_purge = $nginx::params::nx_confd_purge, ) inherits nginx::params { include stdlib @@ -44,6 +45,7 @@ class nginx ( worker_processes => $worker_processes, worker_connections => $worker_connections, proxy_set_header => $proxy_set_header, + confd_purge => $confd_purge, require => Class['nginx::package'], notify => Class['nginx::service'], } diff --git a/manifests/params.pp b/manifests/params.pp index b5c3a6a..00a7f81 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -18,6 +18,7 @@ class nginx::params { $nx_run_dir = '/var/nginx' $nx_conf_dir = '/etc/nginx' + $nx_confd_purge = false $nx_worker_processes = 1 $nx_worker_connections = 1024 $nx_multi_accept = off From c16934b4724185275d86e846f6531d515e5c34a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guzm=C3=A1n=20Bras=C3=B3?= Date: Sun, 30 Sep 2012 17:29:55 -0300 Subject: [PATCH 4/5] Implementation of option configtest_enable which will call configtest on each service restart, therefore if user submit an invalid configuration nginx won't stop and realize too late that it can start again. By default it's false, if true it assumes you will have a working /etc/init.d/nginx which accepts configtest and restart. --- manifests/init.pp | 5 ++++- manifests/params.pp | 1 + manifests/service.pp | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 99def01..9a53ffb 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -33,6 +33,7 @@ class nginx ( $worker_connections = $nginx::params::nx_worker_connections, $proxy_set_header = $nginx::params::nx_proxy_set_header, $confd_purge = $nginx::params::nx_confd_purge, + $configtest_enable = $nginx::params::nx_configtest_enable, ) inherits nginx::params { include stdlib @@ -50,7 +51,9 @@ class nginx ( notify => Class['nginx::service'], } - class { 'nginx::service': } + class { 'nginx::service': + configtest_enable => $configtest_enable, + } # Allow the end user to establish relationships to the "main" class # and preserve the relationship to the implementation classes through diff --git a/manifests/params.pp b/manifests/params.pp index 00a7f81..39a249f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -19,6 +19,7 @@ class nginx::params { $nx_conf_dir = '/etc/nginx' $nx_confd_purge = false + $nx_configtest_enable = false $nx_worker_processes = 1 $nx_worker_connections = 1024 $nx_multi_accept = off diff --git a/manifests/service.pp b/manifests/service.pp index 66dfe02..eeb65c5 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -13,7 +13,9 @@ # Sample Usage: # # This class file is not called directly -class nginx::service { +class nginx::service( + $configtest_enable = $nginx::params::nx_configtest_enable, +) { exec { 'rebuild-nginx-vhosts': command => "/bin/cat ${nginx::params::nx_temp_dir}/nginx.d/* > ${nginx::params::nx_conf_dir}/conf.d/vhost_autogen.conf", refreshonly => true, @@ -27,4 +29,9 @@ class nginx::service { hasrestart => true, subscribe => Exec['rebuild-nginx-vhosts'], } + if $configtest_enable == true { + Service["nginx"] { + restart => "/etc/init.d/nginx configtest && /etc/init.d/nginx restart", + } + } } From a9273d7fb8b1e71c20090c0ec34edaa76dbf2897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guzm=C3=A1n=20Bras=C3=B3?= Date: Tue, 2 Oct 2012 19:44:47 -0300 Subject: [PATCH 5/5] Added support for stub_status location If stub_status is provided as true a location will be created to provide nginx status information from stub_status module. --- manifests/resource/location.pp | 8 ++++++-- templates/vhost/vhost_location_stub_status.erb | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 templates/vhost/vhost_location_stub_status.erb diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index f52ee9c..7f5a01a 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -13,6 +13,7 @@ # [*proxy_read_timeout*] - Override the default the proxy read timeout value of 90 seconds # [*ssl*] - Indicates whether to setup SSL bindings for this location. # [*location_alias*] - Path to be used as basis for serving requests for this location +# [*stub_status*] - If true it will point configure module stub_status to provide nginx stats on location # [*option*] - Reserved for future use # # Actions: @@ -37,6 +38,7 @@ define nginx::resource::location( $ssl = false, $location_alias = undef, $option = undef, + $stub_status = undef, $location ) { File { @@ -57,6 +59,8 @@ define nginx::resource::location( $content_real = template('nginx/vhost/vhost_location_proxy.erb') } elsif ($location_alias != undef) { $content_real = template('nginx/vhost/vhost_location_alias.erb') + } elsif ($stub_status != undef) { + $content_real = template('nginx/vhost/vhost_location_stub_status.erb') } else { $content_real = template('nginx/vhost/vhost_location_directory.erb') } @@ -65,8 +69,8 @@ define nginx::resource::location( if ($vhost == undef) { fail('Cannot create a location reference without attaching to a virtual host') } - if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef)) { - fail('Cannot create a location reference without a www_root, proxy or location_alias defined') + if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef) and ($stub_status == undef) ) { + fail('Cannot create a location reference without a www_root, proxy, location_alias or stub_status defined') } if (($www_root != undef) and ($proxy != undef)) { fail('Cannot define both directory and proxy in a virtual host') diff --git a/templates/vhost/vhost_location_stub_status.erb b/templates/vhost/vhost_location_stub_status.erb new file mode 100644 index 0000000..47ca694 --- /dev/null +++ b/templates/vhost/vhost_location_stub_status.erb @@ -0,0 +1,3 @@ + location <%= location %> { + stub_status on; + }