Skip to content

Commit e4ad481

Browse files
author
Tim Meusel
committed
add support for nginx/unicorn
modified puppet::master class for using $webserver. this can be httpd for apache/passanger or nginx for nginx/unicorn. nginx is currently only tested on centos7, but should work on evers OS with systemd the nginx vhost definition is currently a simple file ressource, this should be changed to nginx::resource:vhost in the future
1 parent ba16557 commit e4ad481

File tree

5 files changed

+125
-5
lines changed

5 files changed

+125
-5
lines changed

files/puppetmaster

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# define the new unicorn backend
2+
upstream puppetmaster_unicorn {
3+
server unix:/var/run/puppet/puppetmaster_unicorn.sock fail_timeout=0;
4+
}
5+
6+
# define our proxy for breaking up SSL
7+
server {
8+
ssl on;
9+
ssl_certificate /var/lib/puppet/ssl/certs/puppet.vps.hosteurope.de.pem;
10+
ssl_certificate_key /var/lib/puppet/ssl/private_keys/puppet.vps.hosteurope.de.pem;
11+
ssl_verify_client optional;
12+
ssl_client_certificate /var/lib/puppet/ssl/ca/ca_crt.pem;
13+
ssl_protocols TLSv1.2;
14+
ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';
15+
proxy_set_header Host $host;
16+
proxy_set_header X-Real-IP $remote_addr;
17+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18+
proxy_set_header X-Scheme $scheme;
19+
proxy_set_header X-Client-Verify $ssl_client_verify;
20+
proxy_set_header X-Client-DN $ssl_client_s_dn;
21+
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
22+
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
23+
listen 10.111.2.250:8140 ssl;
24+
root /var/empty;
25+
location / {
26+
proxy_pass http://puppetmaster_unicorn;
27+
proxy_redirect off;
28+
}
29+
access_log /var/log/nginx/puppetmaster-access.log;
30+
error_log /var/log/nginx/puppetmaster-error.log;
31+
}
32+

files/unicorn-puppetmaster.service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Puppet master served by Unicorn
3+
4+
[Service]
5+
ExecStart=/usr/local/bin/unicorn -c /etc/puppet/unicorn.conf
6+
ExecReload=/usr/bin/kill -s HUP $MAINPID
7+
PrivateTmp=yes
8+
# this would be cool, but then the puppetmaster can't reach the puppetdb
9+
#PrivateNetwork=yes
10+
User=puppet
11+
Group=puppet
12+
13+
[Install]
14+
WantedBy=multi-user.target

files/unicorn.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
worker_processes 16
2+
working_directory "/etc/puppet"
3+
listen '/var/run/puppet/puppetmaster_unicorn.sock', :backlog => 512
4+
timeout 180
5+
pid "/var/run/puppet/puppetmaster_unicorn.pid"
6+
7+
# prevent caching of puppetmaster. sucks for auto deployment
8+
preload_app false
9+
if GC.respond_to?(:copy_on_write_friendly=)
10+
GC.copy_on_write_friendly = true
11+
end
12+
13+
before_fork do |server, worker|
14+
old_pid = "#{server.config[:pid]}.oldbin"
15+
if File.exists?(old_pid) && server.pid != old_pid
16+
begin
17+
Process.kill("QUIT", File.read(old_pid).to_i)
18+
rescue Errno::ENOENT, Errno::ESRCH
19+
# someone else did our job for us
20+
end
21+
end
22+
end
23+
24+
# disable default logging
25+
stdout_path "/dev/null"
26+
stderr_path "/dev/null"

manifests/master.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
}
138138
nginx: {
139139
Anchor['puppet::master::begin'] ->
140-
class {'puppet::unicorn':}
140+
class {'puppet::unicorn':} ->
141+
Anchor['puppet::master::end']
141142
}
142143
}
143144
service { $puppet_master_service:

manifests/unicorn.pp

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,54 @@
1-
# this class installs nginx with unicorn infront of puppetmaster
1+
# this class installs nginx with unicorn in front of puppetmaster
2+
# tested only on centos 7
3+
24
class puppet::unicorn () {
35
include nginx
4-
# nginx::resource::vhost {'puppetmaster':
5-
# www_root => '/var/empty',
6-
# }
6+
# install unicorn
7+
package {['unicorn', 'rack']:
8+
ensure => 'latest',
9+
provider => 'gem',
10+
} ->
11+
file {'copy-config':
12+
path => '/etc/puppet/config.ru',
13+
source => '/usr/share/puppet/ext/rack/config.ru',
14+
} ->
15+
file {'unicorn-conf':
16+
path => '/etc/puppet/unicorn.conf',
17+
source => 'puppet:///modules/puppet/unicorn.conf',
18+
19+
} ->
20+
file {'unicorn-service':
21+
path => '/usr/lib/systemd/system/unicorn-puppetmaster.service',
22+
source => 'puppet:///modules/puppet/unicorn-puppetmaster.service',
23+
notify => Exec['systemd-reload'],
24+
}
25+
exec{'systemd-reload':
26+
exec => 'systemctl daemon-reload',
27+
refreshonly => 'true',
28+
notify => Service['unicorn-puppetmaster'],
29+
}
30+
unless defined(Service['unicorn-puppetmaster']) {
31+
service{'unicorn-puppetmaster':
32+
ensure => 'running',
33+
enable => 'enable',
34+
}
35+
}
36+
# hacky vhost
37+
file {'puppetmaster-vhost':
38+
path => '/etc/nginx/sites-available/puppetmaster',
39+
source => 'puppet:///puppet/puppetmaster',
40+
} ->
41+
file {'enable-puppetmaster-vhost':
42+
path => '/etc/nginx/sites-enabled/puppetmaster',
43+
ensure => 'link',
44+
target => '/etc/nginx/sites-available/puppetmaster',
45+
notify => Service['nginx'],
46+
}
47+
unless defined(Service['nginx']) {
48+
service{'nginx':
49+
ensure => 'running',
50+
enable => 'enable',
51+
}
52+
}
753
}
54+

0 commit comments

Comments
 (0)