From 0b4d31065669d479e7589e2e1ecb4c449dab1072 Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Mon, 28 Nov 2011 00:58:53 +0200 Subject: [PATCH] Initial version of nginx module --- nginx/files/passenger.conf | 3 + nginx/manifests/init.pp | 106 +++++++++++++++++++++++++++++++++ nginx/templates/nginx.conf.erb | 18 ++++++ 3 files changed, 127 insertions(+) create mode 100644 nginx/files/passenger.conf create mode 100644 nginx/manifests/init.pp create mode 100644 nginx/templates/nginx.conf.erb diff --git a/nginx/files/passenger.conf b/nginx/files/passenger.conf new file mode 100644 index 0000000..33ef779 --- /dev/null +++ b/nginx/files/passenger.conf @@ -0,0 +1,3 @@ +passenger_root /usr/local/lib/phusion_passenger; +passenger_ruby /usr/local/bin/ruby18; +passenger_log_level 1; diff --git a/nginx/manifests/init.pp b/nginx/manifests/init.pp new file mode 100644 index 0000000..6a25bc6 --- /dev/null +++ b/nginx/manifests/init.pp @@ -0,0 +1,106 @@ +# Install and configure nginx. +# +class nginx { + + case $operatingsystem { + "openbsd": { + $user = "_nginx" + $group = "_nginx" + } + default: { + $user = "nginx" + $group = "nginx" + } + } + + package { "nginx": + ensure => installed, + } + + service { "nginx": + enable => true, + ensure => running, + require => Package["nginx"], + } + + file { "/etc/nginx/nginx.conf": + ensure => present, + mode => 0644, + owner => "root", + group => $operatingsystem ? { + "openbsd" => "wheel", + default => "root", + }, + content => template("nginx/nginx.conf.erb"), + notify => Service["nginx"], + require => Package["nginx"], + } + + file { "/etc/nginx/conf.d": + ensure => directory, + mode => 0644, + owner => "root", + group => $operatingsystem ? { + "openbsd" => "wheel", + default => "root", + }, + purge => true, + force => true, + recurse => true, + source => "puppet:///modules/custom/empty", + require => Package["nginx"], + } + +} + + +# Install and configure nginx with passenger. +# +class nginx::passenger inherits nginx { + + case $operatingsystem { + "openbsd": { + Package["nginx"] { + flavor => "passenger", + } + nginx::configfile { "passenger.conf": + source => "puppet:///modules/nginx/passenger.conf", + } + } + default: { + fail("Not supported on ${operatingsystem}") + } + } + +} + + +# Add nginx configuration file. +# +define nginx::configfile($source="", $content="") { + + file { "/etc/nginx/conf.d/${name}": + ensure => present, + mode => 0644, + owner => "root", + group => $operatingsystem ? { + "openbsd" => "wheel", + default => "root", + }, + notify => Service["nginx"], + require => File["/etc/nginx/conf.d"], + } + + if $source { + File["/etc/nginx/conf.d/${name}"] { + source => $source, + } + } + + if $content { + File["/etc/nginx/conf.d/${name}"] { + content => $content, + } + } + +} diff --git a/nginx/templates/nginx.conf.erb b/nginx/templates/nginx.conf.erb new file mode 100644 index 0000000..4a1bfc0 --- /dev/null +++ b/nginx/templates/nginx.conf.erb @@ -0,0 +1,18 @@ +user <%= user %>; +worker_processes <%= processorcount %>; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + sendfile on; + tcp_nodelay on; + tcp_nopush on; + keepalive_timeout 65; + + include conf.d/*.conf; +}