Using Passenger

Version 25 (Omry Yadan, 09/25/2011 03:43 am)

1 1
# Using Passenger
2 1
3 25 Omry Yadan
See [http://docs.puppetlabs.com/guides/passenger.html](http://docs.puppetlabs.com/guides/passenger.html) for official docs
4 25 Omry Yadan
5 1
**This support is present in release 0.24.6 and later versions only - it is not supported in earlier releases**
6 10 Klavs Klavsen
**This documentation is found in updated form in each puppet release source tarball under ext/rack folder - look there for correct info for your puppet version**
7 1
8 1
Alternatively see: [[Using Mongrel]]
9 1
10 1
## Why You'd Do This
11 1
12 6 micah -
Traditionally, the puppetmaster would embed a WEBrick or Mongrel Web Server to serve the puppet clients. This may work well for you, but a few people feel like using a proven web server like Apache would be superior for this purpose.
13 1
14 1
## What is Passenger ?
15 1
16 6 micah -
[Passenger](http://www.modrails.com/) (AKA mod\_rails or mod\_rack) is the Apache 2.x Extension which lets you run Rails or Rack applications inside Apache.
17 1
18 6 micah -
Puppet (>0.24.6) now ships with a Rack application which can embed a puppetmaster. While it should be compatible with every Rack application server, it has only been tested with Passenger.
19 1
20 6 micah -
Depending on your operating system, the versions of Puppet, Apache and Passenger may not support this implementation. Specifically, Ubuntu Hardy ships with an older version of puppet (0.24.4) and doesn't include passenger at all, however updated packages for puppet can be found [here](https://launchpad.net/~bitpusher/+archive/ppa). There are also some passenger packages there, but as of 2009-09-28 they do not seem to have the latest passenger (2.2.5), so better install passenger from a gem as per the instructions at [modrails.com].
21 1
22 1
## Dependency versions
23 1
24 1
**Puppet: (>0.24.6)**
25 1
26 3 Patrick Mohr
**Passenger: See below**
27 1
28 13 Nathan Rich
**Rack: version 1.1.0 is known to work.  0.3.0 is known to NOT work**
29 1
30 1
**JJM Recommended Versions: As of July 2010, Passenger 2.2.11 and Rack 1.0.1 are confirmed to be working.  To install, gem install -v=1.0.1 rack, gem install -v=2.2.11 passenger**
31 15 Nathan Rich
32 23 Scott Merrill
**SDM Passenger 3.0.7 works just fine with Rack 1.2.2 on Red Hat Enterprise Linux 6.**
33 22 Scott Merrill
34 19 Jeff McCune
Pre-compiled passenger RPM's for Enterprise Linux 5 are available at: [http://yum.puppetlabs.com/prosvc/5/](http://yum.puppetlabs.com/prosvc/5/)
35 18 Jeff McCune
36 14 Nathan Rich
n4th4nr1ch verified: rack 1.1.0 with passenger 2.2.15 DOES work and I've updated the versions listed throughout here to reflect those. **As of September 13th 2010 the latest version of rack does NOT work**.
37 1
38 6 micah -
Note: Passenger versions 2.2.3 and 2.2.4 have known bugs regarding to the SSL environment variables, which make them unsuitable for hosting a puppetmaster. So use either 2.2.2, or 2.2.5. Note that while it was expected that Passenger 2.2.2 would be the last version which can host a 0.24.x puppetmaster, that turns out to be
39 17 James Turnbull
not true, cf. [this bug report](http://projects.puppetlabs.com/issues/2386#change-9238). So, passenger 2.2.5 works fine. Passenger 2.2.15 is known working.
40 1
41 9 Al Tobey
Another Note: It appears that the Rack 0.4.0 distributed in EPEL does not work with Puppet 0.25.5 or 0.26 (git as of 2010-07-09).    Updating Rack to 1.0.1 as recommended above makes things start working.
42 9 Al Tobey
43 6 micah -
## Installation Summary for Debian/Ubuntu and RHEL5
44 1
45 17 James Turnbull
Please see [ext/rack/README in the puppet source](http://github.com/puppetlabs/puppet/tree/master/ext/rack) tree for instructions.
46 1
47 1
Whatever you do, make sure your config.ru file is owned by the puppet user! Passenger will setuid to that user.
48 1
49 1
Make sure puppetmasterd ran at least once, so puppetmasterd SSL certificates are setup initially.
50 1
51 5 micah -
### Setup your puppet.conf
52 1
53 1
Make sure you have the following set in your puppetmaster's puppet.conf:
54 5 micah -
55 12 Jacob Helwig
    [puppetmasterd]
56 12 Jacob Helwig
      ssl_client_header = SSL_CLIENT_S_DN
57 12 Jacob Helwig
      ssl_client_verify_header = SSL_CLIENT_VERIFY
58 5 micah -
59 5 micah -
### Install Apache2, Rack and Passenger
60 5 micah -
61 6 micah -
For Debian/Ubuntu you just need to do the following (no gems needed):
62 5 micah -
63 11 Bruno Leon
    apt-get install apache2 libapache2-mod-passenger rails librack-ruby libmysql-ruby
64 5 micah -
65 1
NOTE: you should have 0.25.4-6 or later of the puppetmaster package installed
66 22 Scott Merrill
67 5 micah -
NOTE2: if you are running Debian Stable (ie. Lenny), you will need to use the [backports.org packages](http://backports.org), specifically make sure you install at least version 2.2.11debian-1~bpo50+1 of libapache2-mod-passenger, and 1.0.0-2~bpo50+1 of librack-ruby. The rack library in Lenny is too old, and passenger does not exist in Lenny.
68 5 micah -
69 6 micah -
For RHEL5 (needs the [EPEL](https://fedoraproject.org/wiki/EPEL) repository enabled) do the following:
70 1
71 1
    yum install httpd httpd-devel ruby-devel rubygems
72 6 micah -
    The latest version of Passenger (2.2.5) appears to work fine on RHEL5:
73 13 Nathan Rich
    gem install -v 1.1.0 rack
74 1
    gem install passenger
75 1
    passenger-install-apache2-module
76 1
77 12 Jacob Helwig
If you want the older 2.2.2 gem, you could manually download the .gem file from [RubyForge](http://rubyforge.org/frs/?group_id=5873). Or, you could just add the
78 12 Jacob Helwig
correct versions to your gem command:
79 6 micah -
80 12 Jacob Helwig
    gem install -v 0.4.0 rack
81 12 Jacob Helwig
    gem install -v 2.2.2 passenger 
82 12 Jacob Helwig
83 6 micah -
Enable Apache modules "ssl" and "headers":
84 1
85 22 Scott Merrill
*   For RHEL5 and RHEL6:
86 5 micah -
87 12 Jacob Helwig
        yum install mod_ssl
88 12 Jacob Helwig
89 12 Jacob Helwig
*   Debian and Ubuntu have these enabled by default, but if you need to, this is how you enable them:
90 12 Jacob Helwig
91 12 Jacob Helwig
        a2enmod ssl
92 12 Jacob Helwig
        a2enmod headers
93 1
94 1
### Configure Apache
95 1
96 1
For Debian/Ubuntu:
97 1
98 5 micah -
    cp /usr/share/doc/puppetmaster/examples/apache2.conf /etc/apache2/sites-available/puppetmasterd  (see below for the file contents)
99 24 Roman Ovchinnikov
    $EDITOR /etc/apache2/sites-available/puppetmasterd (replace the hostnames)
100 5 micah -
    a2ensite puppetmasterd
101 1
102 1
For RHEL5:
103 1
104 1
    cp puppetmaster.conf /etc/httpd/conf.d/ (see below for file contents)
105 1
    vim /etc/httpd/conf.d/puppetmaster.conf (replace hostnames with corrent values)
106 1
107 1
    Install the rack application [1] (Debian users do not need to do this)
108 1
109 1
    mkdir -p /usr/share/puppet/rack/puppetmasterd
110 1
    mkdir /usr/share/puppet/rack/puppetmasterd/public /usr/share/puppet/rack/puppetmasterd/tmp
111 13 Nathan Rich
    cp config.ru /usr/share/puppet/rack/puppetmasterd (look below on where to find this file)
112 1
    chown puppet /usr/share/puppet/rack/puppetmasterd/config.ru
113 1
114 22 Scott Merrill
For RHEL6:
115 22 Scott Merrill
116 22 Scott Merrill
    cp /usr/share/puppet/ext/rack/files/apache2.conf /etc/httpd/conf.d/rack.conf
117 22 Scott Merrill
    vim /etc/httpd/conf.d/puppetmaster.conf (replace cert paths/filenames with corrent values)
118 22 Scott Merrill
119 22 Scott Merrill
    mkdir -p /etc/puppet/rack/public
120 22 Scott Merrill
    mkdir -p /etc/puppet/rack/tmp
121 22 Scott Merrill
    cp /usr/share/puppet/ext/rack/files/config.ru /etc/puppet/rack
122 22 Scott Merrill
    chown puppet /etc/puppet/rack/config.ru
123 22 Scott Merrill
124 1
Restart apache:
125 1
126 5 micah -
    # For Debian/Ubuntu
127 1
    /etc/init.d/puppetmaster stop - make sure puppetmaster is stopped before you continue
128 1
    /etc/init.d/apache2 restart
129 1
    
130 1
    # For RHEL5
131 1
    /etc/init.d/httpd restart
132 5 micah -
133 1
If all works well, you'll want to make sure your puppmetmasterd init script does not get called anymore:
134 1
135 5 micah -
    # For Debian/Ubuntu
136 1
    $EDITOR /etc/default/puppetmaster - change START=yes to START=no
137 5 micah -
138 22 Scott Merrill
    # For RHEL5 and RHEL6
139 1
    chkconfig puppetmaster off
140 1
    chkconfig httpd on
141 1
142 21 Patrick Mohr
[1] Passenger will not let applications run as root or the Apache user, instead an implicit setuid will be done, to the user whom owns config.ru. Therefore, **config.ru must be owned by the puppet user**.
143 5 micah -
144 1
## Apache Configuration for Puppet 0.24.x
145 1
146 1
This Apache Virtual Host configures the puppetmaster on the default
147 1
puppetmaster port (8140).
148 1
149 1
    Listen 8140
150 1
    <VirtualHost *:8140>
151 1
    
152 1
        SSLEngine on
153 1
        SSLCipherSuite SSLv2:-LOW:-EXPORT:RC4+RSA
154 16 Nathan Rich
        SSLCertificateFile      /var/lib/puppet/ssl/certs/YOUR-PUPPETMASTER-FQDN.pem
155 16 Nathan Rich
        SSLCertificateKeyFile   /var/lib/puppet/ssl/private_keys/YOUR-PUPPETMASTER-FQDN.pem
156 1
        SSLCertificateChainFile /var/lib/puppet/ssl/ca/ca_crt.pem
157 1
        SSLCACertificateFile    /var/lib/puppet/ssl/ca/ca_crt.pem
158 1
        # CRL checking should be enabled; if you have problems with Apache complaining about the CRL, disable the next line
159 1
        SSLCARevocationFile     /var/lib/puppet/ssl/ca/ca_crl.pem
160 1
        SSLVerifyClient optional
161 1
        SSLVerifyDepth  1
162 1
        SSLOptions +StdEnvVars
163 1
    
164 1
        # The following client headers allow the same configuration to work with Pound.
165 1
        RequestHeader set X-SSL-Subject %{SSL_CLIENT_S_DN}e
166 1
        RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e
167 1
        RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e
168 1
    
169 1
        RackAutoDetect On
170 1
        DocumentRoot /usr/share/puppet/rack/puppetmasterd/public/
171 1
        <Directory /usr/share/puppet/rack/puppetmasterd/>
172 1
            Options None
173 1
            AllowOverride None
174 1
            Order allow,deny
175 1
            allow from all
176 1
        </Directory>
177 1
    </VirtualHost>
178 1
179 1
If the current puppetmaster is not a certificate authority, you may
180 1
need to change the following lines. The certs/ca.pem file should
181 1
exist as long as the puppetmaster has been signed by the CA.
182 1
183 1
      SSLCertificateChainFile /var/lib/puppet/ssl/certs/ca.pem
184 6 micah -
      SSLCACertificateFile    /var/lib/puppet/ssl/certs/ca.pem
185 1
186 1
For RHEL hosts you may need to add:
187 1
188 13 Nathan Rich
       LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
189 13 Nathan Rich
       PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15
190 1
       PassengerRuby /usr/bin/ruby
191 1
192 5 micah -
For details about enabling and configuring Passenger, see the [Passenger install guide](http://www.modrails.com/install.html).
193 1
194 1
## The config.ru file for Puppet 0.24.x
195 1
196 1
    # This file is mostly based on puppetmasterd, which is part of
197 1
    # the standard puppet distribution.
198 1
    
199 1
    require 'rack'
200 1
    require 'puppet'
201 1
    require 'puppet/network/http_server/rack'
202 1
    
203 1
    # startup code stolen from bin/puppetmasterd
204 1
    Puppet.parse_config
205 1
    Puppet::Util::Log.level = :info
206 1
    Puppet::Util::Log.newdestination(:syslog)
207 1
    # A temporary solution, to at least make the master work for now.
208 1
    Puppet::Node::Facts.terminus_class = :yaml
209 1
    # Cache our nodes in yaml.  Currently not configurable.
210 1
    Puppet::Node.cache_class = :yaml
211 1
    
212 1
    
213 1
    # The list of handlers running inside this puppetmaster
214 1
    handlers = {
215 1
        :Status => {},
216 1
        :FileServer => {},
217 1
        :Master => {},
218 1
        :CA => {},
219 1
        :FileBucket => {},
220 1
        :Report => {}
221 1
    }
222 1
    
223 1
    # Fire up the Rack-Server instance
224 1
    server = Puppet::Network::HTTPServer::Rack.new(handlers)
225 1
    
226 1
    # prepare the rack app
227 1
    app = proc do |env|
228 1
        server.process(env)
229 1
    end
230 1
    
231 1
    # Go.
232 1
    run app
233 1
234 5 micah -
If you don't want to run with the CA enabled, you could drop the :CA => {} line from the config.ru above.
235 1
236 1
## The config.ru file for 0.25.x
237 1
238 16 Nathan Rich
Please see ext/rack in the 0.25 source tree for the proper config.ru file. Same for 26.
239 1
240 1
## Suggested Tweaks
241 1
242 20 Jeff McCune
To simply the management of the Puppet Master service, Jeff McCune recommends setting PassengerMaxRequests in Apache.  This setting automatically restarts the ruby process hosting the puppet master application service and will ensure the process remains fresh without any disruption in service.
243 20 Jeff McCune
244 20 Jeff McCune
    PassengerMaxRequests 10000
245 20 Jeff McCune
246 5 micah -
Based upon my (Larry Ludwig) testing of passenger/puppetmasterd I recommend adjusting these options in your apache configuration.
247 1
248 1
-   PassengerPoolIdleTime 300 - Set to 5 min (300 seconds) or less.
249 1
    The shorting this option allows for puppetmasterd to get refreshed
250 1
    at some interval. This option is also somewhat dependent upon the
251 1
    amount of puppetd nodes connecting and at what interval.
252 1
-   PassengerMaxPoolSize 15 - to 15% more instances than what's
253 1
    needed. This will allow idle puppetmasterd to get recycled. The net
254 1
    effect is less memory will be used, not more.
255 1
-   PassengerUseGlobalQueue on - Since communication with the
256 1
    puppetmaster from puppetd is a long process (more than 20 seconds
257 1
    in most cases) and will allow for processes to get recycled better
258 1
-   PassengerHighPerformance on - The additional Passenger features
259 1
    for apache compatibility are not needed with Puppet.
260 1
261 5 micah -
No different than with traditional web servers, once your service starts using swap performance degradation will occur. So be mindful of your memory/swap usage on your Puppetmaster.
262 1
263 5 micah -
To monitor the age of your puppetmasterd processes within Passenger, run
264 1
265 1
    passenger-status | grep PID | sort
266 1
267 1
      PID: 14590   Sessions: 1    Processed: 458     Uptime: 3m 40s
268 1
      PID: 7117    Sessions: 0    Processed: 10980   Uptime: 1h 43m 41s
269 1
      PID: 7355    Sessions: 0    Processed: 9736    Uptime: 1h 38m 38s
270 1
      PID: 7575    Sessions: 0    Processed: 9395    Uptime: 1h 32m 27s
271 1
      PID: 9950    Sessions: 0    Processed: 6581    Uptime: 1h 2m 35s
272 1
273 1
My personal preference is having Passenger recycling puppetmasterd every few hours to ensure memory/garbage collection from Ruby is not a factor.
274 8 Jeff McCune
275 8 Jeff McCune
276 8 Jeff McCune
## Troubleshooting
277 8 Jeff McCune
278 8 Jeff McCune
JJM GOTCHA: When working with Apache, make sure the CA certificate and the SSL certificate configured contain a different CN field.  For example, if `/etc/puppet/ssl/certs/hyel.puppetlabs.lan.pem` and `/etc/puppet/ssl/ca/ca_crt.pem` have the same CN field, Apache will have an issue verifying certificate revocation lists.  The error received looks like: `err: Could not retrieve catalog from remote server: tlsv1 alert decrypt error`.  To fix, use the --ca_name configuration setting/option, e.g. ca_name = "Puppet CA"