From af166a9ac519625c539dab799f49d462a8887ec4 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/3] 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 6d78a00a3..66dfe02fa 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -17,6 +17,7 @@ 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 e1363545ae5074fe437ceda8795095e9e34aff15 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/3] 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 c6135fdb0..25c96f9dd 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 ad3afbbaa..d117f51f1 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::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 0cc1fbf36..42d254c80 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 677e2d30a..b05d71d0c 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 e9d984eaafef0806c0b0420f1e195abc427b88ff 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/3] 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. Because vhost_autogen it's not actually managed by puppet but indirectly created by a puppet executed command, it's added as ignore to avoid getting it removed. Better formating for confd purge support Better formating for confd purge support --- manifests/config.pp | 15 ++++++++++++--- manifests/init.pp | 8 +++++--- manifests/params.pp | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 25c96f9dd..e69a9ccc5 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -14,9 +14,10 @@ # # This class file is not called directly 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 + $worker_processes = $nginx::params::nx_worker_processes, + $worker_connections = $nginx::params::nx_worker_connections, + $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,14 @@ file { "${nginx::params::nx_conf_dir}/conf.d": ensure => directory, } + if $confd_purge == true { + File["${nginx::params::nx_conf_dir}/conf.d"] { + ignore => "vhost_autogen.conf", + purge => true, + recurse => true, + } + } + file { "${nginx::config::nx_run_dir}": ensure => directory, diff --git a/manifests/init.pp b/manifests/init.pp index d117f51f1..97ada029f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,9 +29,10 @@ # include 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 + $worker_processes = $nginx::params::nx_worker_processes, + $worker_connections = $nginx::params::nx_worker_connections, + $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 @@ 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 b5c3a6ae2..00a7f81a2 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -18,6 +18,7 @@ $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