init.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. # Class: nginx
  2. #
  3. # This module manages NGINX.
  4. #
  5. # Parameters:
  6. #
  7. # There are no default parameters for this class. All module parameters
  8. # are managed via the nginx::params class
  9. #
  10. # Actions:
  11. #
  12. # Requires:
  13. # puppetlabs-stdlib - https://github.com/puppetlabs/puppetlabs-stdlib
  14. #
  15. # Packaged NGINX
  16. # - RHEL: EPEL or custom package
  17. # - Debian/Ubuntu: Default Install or custom package
  18. # - SuSE: Default Install or custom package
  19. #
  20. # stdlib
  21. # - puppetlabs-stdlib module >= 0.1.6
  22. # - plugin sync enabled to obtain the anchor type
  23. #
  24. # Sample Usage:
  25. #
  26. # The module works with sensible defaults:
  27. #
  28. # node default {
  29. # include nginx
  30. # }
  31. class nginx (
  32. $client_body_buffer_size = $nginx::params::nx_client_body_buffer_size,
  33. $client_max_body_size = $nginx::params::nx_client_max_body_size,
  34. $confd_purge = $nginx::params::nx_confd_purge,
  35. $configtest_enable = $nginx::params::nx_configtest_enable,
  36. $conf_dir = $nginx::params::nx_conf_dir,
  37. $conf_template = $nginx::params::nx_conf_template,
  38. $daemon_user = $nginx::params::nx_daemon_user,
  39. $events_use = $nginx::params::nx_events_use,
  40. $fastcgi_cache_inactive = $nginx::params::nx_fastcgi_cache_inactive,
  41. $fastcgi_cache_key = $nginx::params::nx_fastcgi_cache_key,
  42. $fastcgi_cache_keys_zone = $nginx::params::nx_fastcgi_cache_keys_zone,
  43. $fastcgi_cache_levels = $nginx::params::nx_fastcgi_cache_levels,
  44. $fastcgi_cache_max_size = $nginx::params::nx_fastcgi_cache_max_size,
  45. $fastcgi_cache_path = $nginx::params::nx_fastcgi_cache_path,
  46. $fastcgi_cache_use_stale = $nginx::params::nx_fastcgi_cache_use_stale,
  47. $gzip = $nginx::params::nx_gzip,
  48. $http_access_log = $nginx::params::nx_http_access_log,
  49. $http_cfg_append = $nginx::params::nx_http_cfg_append,
  50. $mail = $nginx::params::nx_mail,
  51. $manage_repo = $nginx::params::manage_repo,
  52. $multi_accept = $nginx::params::nx_multi_accept,
  53. $names_hash_bucket_size = $nginx::params::nx_names_hash_bucket_size,
  54. $names_hash_max_size = $nginx::params::nx_names_hash_max_size,
  55. $nginx_error_log = $nginx::params::nx_nginx_error_log,
  56. $nginx_locations = {},
  57. $nginx_mailhosts = {},
  58. $nginx_upstreams = {},
  59. $nginx_vhosts = {},
  60. $package_ensure = $nginx::params::package_ensure,
  61. $package_name = $nginx::params::package_name,
  62. $package_source = $nginx::params::package_source,
  63. $proxy_buffers = $nginx::params::nx_proxy_buffers,
  64. $proxy_buffer_size = $nginx::params::nx_proxy_buffer_size,
  65. $proxy_cache_inactive = $nginx::params::nx_proxy_cache_inactive,
  66. $proxy_cache_keys_zone = $nginx::params::nx_proxy_cache_keys_zone,
  67. $proxy_cache_levels = $nginx::params::nx_proxy_cache_levels,
  68. $proxy_cache_max_size = $nginx::params::nx_proxy_cache_max_size,
  69. $proxy_cache_path = $nginx::params::nx_proxy_cache_path,
  70. $proxy_conf_template = $nginx::params::nx_proxy_conf_template,
  71. $proxy_connect_timeout = $nginx::params::nx_proxy_connect_timeout,
  72. $proxy_headers_hash_bucket_size = $nginx::params::nx_proxy_headers_hash_bucket_size,
  73. $proxy_http_version = $nginx::params::nx_proxy_http_version,
  74. $proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
  75. $proxy_redirect = $nginx::params::nx_proxy_redirect,
  76. $proxy_send_timeout = $nginx::params::nx_proxy_send_timeout,
  77. $proxy_set_header = $nginx::params::nx_proxy_set_header,
  78. $server_tokens = $nginx::params::nx_server_tokens,
  79. $service_ensure = $nginx::params::nx_service_ensure,
  80. $service_restart = $nginx::params::nx_service_restart,
  81. $super_user = $nginx::params::nx_super_user,
  82. $vhost_purge = $nginx::params::nx_vhost_purge,
  83. $worker_connections = $nginx::params::nx_worker_connections,
  84. $worker_processes = $nginx::params::nx_worker_processes,
  85. $worker_rlimit_nofile = $nginx::params::nx_worker_rlimit_nofile,
  86. $geo_mappings = {},
  87. $string_mappings = {},
  88. ) inherits nginx::params {
  89. include stdlib
  90. if (!is_string($worker_processes)) and (!is_integer($worker_processes)) {
  91. fail('$worker_processes must be an integer or have value "auto".')
  92. }
  93. if (!is_integer($worker_connections)) {
  94. fail('$worker_connections must be an integer.')
  95. }
  96. if (!is_integer($worker_rlimit_nofile)) {
  97. fail('$worker_rlimit_nofile must be an integer.')
  98. }
  99. if (!is_string($events_use)) and ($events_use != false) {
  100. fail('$events_use must be a string or false.')
  101. }
  102. validate_string($multi_accept)
  103. validate_string($package_name)
  104. validate_string($package_ensure)
  105. validate_string($package_source)
  106. validate_array($proxy_set_header)
  107. validate_string($proxy_http_version)
  108. validate_bool($confd_purge)
  109. validate_bool($vhost_purge)
  110. if ($proxy_cache_path != false) {
  111. validate_string($proxy_cache_path)
  112. }
  113. if (!is_integer($proxy_cache_levels)) {
  114. fail('$proxy_cache_levels must be an integer.')
  115. }
  116. validate_string($proxy_cache_keys_zone)
  117. validate_string($proxy_cache_max_size)
  118. validate_string($proxy_cache_inactive)
  119. if ($fastcgi_cache_path != false) {
  120. validate_string($fastcgi_cache_path)
  121. }
  122. if (!is_integer($fastcgi_cache_levels)) {
  123. fail('$fastcgi_cache_levels must be an integer.')
  124. }
  125. validate_string($fastcgi_cache_keys_zone)
  126. validate_string($fastcgi_cache_max_size)
  127. validate_string($fastcgi_cache_inactive)
  128. if ($fastcgi_cache_key != false) {
  129. validate_string($fastcgi_cache_key)
  130. }
  131. if ($fastcgi_cache_use_stale != false) {
  132. validate_string($fastcgi_cache_use_stale)
  133. }
  134. validate_bool($configtest_enable)
  135. validate_string($service_restart)
  136. validate_bool($mail)
  137. validate_string($server_tokens)
  138. validate_string($client_max_body_size)
  139. if (!is_integer($names_hash_bucket_size)) {
  140. fail('$names_hash_bucket_size must be an integer.')
  141. }
  142. if (!is_integer($names_hash_max_size)) {
  143. fail('$names_hash_max_size must be an integer.')
  144. }
  145. validate_string($proxy_buffers)
  146. validate_string($proxy_buffer_size)
  147. if ($http_cfg_append != false) {
  148. validate_hash($http_cfg_append)
  149. }
  150. validate_string($nginx_error_log)
  151. validate_string($http_access_log)
  152. validate_hash($nginx_upstreams)
  153. validate_hash($nginx_vhosts)
  154. validate_hash($nginx_locations)
  155. validate_hash($nginx_mailhosts)
  156. validate_bool($manage_repo)
  157. validate_string($proxy_headers_hash_bucket_size)
  158. validate_bool($super_user)
  159. validate_hash($string_mappings)
  160. validate_hash($geo_mappings)
  161. class { 'nginx::package':
  162. package_name => $package_name,
  163. package_source => $package_source,
  164. package_ensure => $package_ensure,
  165. notify => Class['nginx::service'],
  166. manage_repo => $manage_repo,
  167. }
  168. class { 'nginx::config':
  169. client_body_buffer_size => $client_body_buffer_size,
  170. client_max_body_size => $client_max_body_size,
  171. confd_purge => $confd_purge,
  172. conf_dir => $conf_dir,
  173. conf_template => $conf_template,
  174. daemon_user => $daemon_user,
  175. events_use => $events_use,
  176. fastcgi_cache_inactive => $fastcgi_cache_inactive,
  177. fastcgi_cache_key => $fastcgi_cache_key,
  178. fastcgi_cache_keys_zone => $fastcgi_cache_keys_zone,
  179. fastcgi_cache_levels => $fastcgi_cache_levels,
  180. fastcgi_cache_max_size => $fastcgi_cache_max_size,
  181. fastcgi_cache_path => $fastcgi_cache_path,
  182. fastcgi_cache_use_stale => $fastcgi_cache_use_stale,
  183. gzip => $gzip,
  184. http_access_log => $http_access_log,
  185. http_cfg_append => $http_cfg_append,
  186. multi_accept => $multi_accept,
  187. names_hash_bucket_size => $names_hash_bucket_size,
  188. names_hash_max_size => $names_hash_max_size,
  189. nginx_error_log => $nginx_error_log,
  190. proxy_buffers => $proxy_buffers,
  191. proxy_buffer_size => $proxy_buffer_size,
  192. proxy_cache_inactive => $proxy_cache_inactive,
  193. proxy_cache_keys_zone => $proxy_cache_keys_zone,
  194. proxy_cache_levels => $proxy_cache_levels,
  195. proxy_cache_max_size => $proxy_cache_max_size,
  196. proxy_cache_path => $proxy_cache_path,
  197. proxy_conf_template => $proxy_conf_template,
  198. proxy_connect_timeout => $proxy_connect_timeout,
  199. proxy_headers_hash_bucket_size => $proxy_headers_hash_bucket_size,
  200. proxy_http_version => $proxy_http_version,
  201. proxy_read_timeout => $proxy_read_timeout,
  202. proxy_redirect => $proxy_redirect,
  203. proxy_send_timeout => $proxy_send_timeout,
  204. proxy_set_header => $proxy_set_header,
  205. server_tokens => $server_tokens,
  206. super_user => $super_user,
  207. vhost_purge => $vhost_purge,
  208. worker_connections => $worker_connections,
  209. worker_processes => $worker_processes,
  210. worker_rlimit_nofile => $worker_rlimit_nofile,
  211. require => Class['nginx::package'],
  212. notify => Class['nginx::service'],
  213. }
  214. class { 'nginx::service':
  215. }
  216. create_resources('nginx::resource::upstream', $nginx_upstreams)
  217. create_resources('nginx::resource::vhost', $nginx_vhosts)
  218. create_resources('nginx::resource::location', $nginx_locations)
  219. create_resources('nginx::resource::mailhost', $nginx_mailhosts)
  220. create_resources('nginx::resource::map', $string_mappings)
  221. create_resources('nginx::resource::geo', $geo_mappings)
  222. # Allow the end user to establish relationships to the "main" class
  223. # and preserve the relationship to the implementation classes through
  224. # a transitive relationship to the composite class.
  225. anchor{ 'nginx::begin':
  226. before => Class['nginx::package'],
  227. notify => Class['nginx::service'],
  228. }
  229. anchor { 'nginx::end':
  230. require => Class['nginx::service'],
  231. }
  232. }