Using Passenger

Version 19 (Jeff McCune, 11/12/2010 03:06 pm)

1 1
# Using Passenger
2 1
3 1
**This support is present in release 0.24.6 and later versions only - it is not supported in earlier releases**
4 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**
5 1
6 1
Alternatively see: [[Using Mongrel]]
7 1
8 1
## Why You'd Do This
9 1
10 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.
11 1
12 1
## What is Passenger ?
13 1
14 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.
15 1
16 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.
17 1
18 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].
19 1
20 1
## Dependency versions
21 1
22 1
**Puppet: (>0.24.6)**
23 1
24 3 Patrick Mohr
**Passenger: See below**
25 1
26 13 Nathan Rich
**Rack: version 1.1.0 is known to work.  0.3.0 is known to NOT work**
27 1
28 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**
29 15 Nathan Rich
30 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/)
31 18 Jeff McCune
32 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**.
33 1
34 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
35 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.
36 1
37 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.
38 9 Al Tobey
39 6 micah -
## Installation Summary for Debian/Ubuntu and RHEL5
40 1
41 17 James Turnbull
Please see [ext/rack/README in the puppet source](http://github.com/puppetlabs/puppet/tree/master/ext/rack) tree for instructions.
42 1
43 1
Whatever you do, make sure your config.ru file is owned by the puppet user! Passenger will setuid to that user.
44 1
45 1
Make sure puppetmasterd ran at least once, so puppetmasterd SSL certificates are setup initially.
46 1
47 5 micah -
### Setup your puppet.conf
48 1
49 1
Make sure you have the following set in your puppetmaster's puppet.conf:
50 5 micah -
51 12 Jacob Helwig
    [puppetmasterd]
52 12 Jacob Helwig
      ssl_client_header = SSL_CLIENT_S_DN
53 12 Jacob Helwig
      ssl_client_verify_header = SSL_CLIENT_VERIFY
54 5 micah -
55 5 micah -
### Install Apache2, Rack and Passenger
56 5 micah -
57 6 micah -
For Debian/Ubuntu you just need to do the following (no gems needed):
58 5 micah -
59 11 Bruno Leon
    apt-get install apache2 libapache2-mod-passenger rails librack-ruby libmysql-ruby
60 5 micah -
61 1
NOTE: you should have 0.25.4-6 or later of the puppetmaster package installed
62 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.
63 5 micah -
64 6 micah -
For RHEL5 (needs the [EPEL](https://fedoraproject.org/wiki/EPEL) repository enabled) do the following:
65 1
66 1
    yum install httpd httpd-devel ruby-devel rubygems
67 6 micah -
    The latest version of Passenger (2.2.5) appears to work fine on RHEL5:
68 13 Nathan Rich
    gem install -v 1.1.0 rack
69 1
    gem install passenger
70 1
    passenger-install-apache2-module
71 1
72 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
73 12 Jacob Helwig
correct versions to your gem command:
74 6 micah -
75 12 Jacob Helwig
    gem install -v 0.4.0 rack
76 12 Jacob Helwig
    gem install -v 2.2.2 passenger 
77 1
78 12 Jacob Helwig
Enable Apache modules "ssl" and "headers":
79 6 micah -
80 12 Jacob Helwig
*   For RHEL5:
81 5 micah -
82 12 Jacob Helwig
        yum install mod_ssl
83 12 Jacob Helwig
84 12 Jacob Helwig
*   Debian and Ubuntu have these enabled by default, but if you need to, this is how you enable them:
85 12 Jacob Helwig
86 12 Jacob Helwig
        a2enmod ssl
87 12 Jacob Helwig
        a2enmod headers
88 1
89 1
### Configure Apache
90 1
91 1
For Debian/Ubuntu:
92 1
93 5 micah -
    cp /usr/share/doc/puppetmaster/examples/apache2.conf /etc/apache2/sites-available/puppetmasterd  (see below for the file contents)
94 5 micah -
    $EDITOR /etc/apache2/conf.d/puppetmasterd (replace the hostnames)
95 5 micah -
    a2ensite puppetmasterd
96 1
97 1
For RHEL5:
98 1
99 1
    cp puppetmaster.conf /etc/httpd/conf.d/ (see below for file contents)
100 1
    vim /etc/httpd/conf.d/puppetmaster.conf (replace hostnames with corrent values)
101 1
102 1
    Install the rack application [1] (Debian users do not need to do this)
103 1
104 1
    mkdir -p /usr/share/puppet/rack/puppetmasterd
105 1
    mkdir /usr/share/puppet/rack/puppetmasterd/public /usr/share/puppet/rack/puppetmasterd/tmp
106 13 Nathan Rich
    cp config.ru /usr/share/puppet/rack/puppetmasterd (look below on where to find this file)
107 1
    chown puppet /usr/share/puppet/rack/puppetmasterd/config.ru
108 1
109 5 micah -
Restart apache:
110 1
111 1
    # For Debian/Ubuntu
112 5 micah -
    /etc/init.d/puppetmaster stop - make sure puppetmaster is stopped before you continue
113 1
    /etc/init.d/apache2 restart
114 1
    
115 1
    # For RHEL5
116 1
    /etc/init.d/httpd restart
117 1
118 5 micah -
If all works well, you'll want to make sure your puppmetmasterd init script does not get called anymore:
119 1
120 1
    # For Debian/Ubuntu
121 5 micah -
    $EDITOR /etc/default/puppetmaster - change START=yes to START=no
122 5 micah -
123 1
    # For RHEL5
124 1
    chkconfig puppetmaster off
125 1
    chkconfig httpd on
126 1
127 1
[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 shall be owned by the puppet user.
128 5 micah -
129 1
## Apache Configuration for Puppet 0.24.x
130 1
131 1
This Apache Virtual Host configures the puppetmaster on the default
132 1
puppetmaster port (8140).
133 1
134 1
    Listen 8140
135 1
    <VirtualHost *:8140>
136 1
    
137 1
        SSLEngine on
138 1
        SSLCipherSuite SSLv2:-LOW:-EXPORT:RC4+RSA
139 16 Nathan Rich
        SSLCertificateFile      /var/lib/puppet/ssl/certs/YOUR-PUPPETMASTER-FQDN.pem
140 16 Nathan Rich
        SSLCertificateKeyFile   /var/lib/puppet/ssl/private_keys/YOUR-PUPPETMASTER-FQDN.pem
141 1
        SSLCertificateChainFile /var/lib/puppet/ssl/ca/ca_crt.pem
142 1
        SSLCACertificateFile    /var/lib/puppet/ssl/ca/ca_crt.pem
143 1
        # CRL checking should be enabled; if you have problems with Apache complaining about the CRL, disable the next line
144 1
        SSLCARevocationFile     /var/lib/puppet/ssl/ca/ca_crl.pem
145 1
        SSLVerifyClient optional
146 1
        SSLVerifyDepth  1
147 1
        SSLOptions +StdEnvVars
148 1
    
149 1
        # The following client headers allow the same configuration to work with Pound.
150 1
        RequestHeader set X-SSL-Subject %{SSL_CLIENT_S_DN}e
151 1
        RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e
152 1
        RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e
153 1
    
154 1
        RackAutoDetect On
155 1
        DocumentRoot /usr/share/puppet/rack/puppetmasterd/public/
156 1
        <Directory /usr/share/puppet/rack/puppetmasterd/>
157 1
            Options None
158 1
            AllowOverride None
159 1
            Order allow,deny
160 1
            allow from all
161 1
        </Directory>
162 1
    </VirtualHost>
163 1
164 1
If the current puppetmaster is not a certificate authority, you may
165 1
need to change the following lines. The certs/ca.pem file should
166 1
exist as long as the puppetmaster has been signed by the CA.
167 1
168 1
      SSLCertificateChainFile /var/lib/puppet/ssl/certs/ca.pem
169 6 micah -
      SSLCACertificateFile    /var/lib/puppet/ssl/certs/ca.pem
170 1
171 1
For RHEL hosts you may need to add:
172 1
173 13 Nathan Rich
       LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
174 13 Nathan Rich
       PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15
175 1
       PassengerRuby /usr/bin/ruby
176 1
177 5 micah -
For details about enabling and configuring Passenger, see the [Passenger install guide](http://www.modrails.com/install.html).
178 1
179 1
## The config.ru file for Puppet 0.24.x
180 1
181 1
    # This file is mostly based on puppetmasterd, which is part of
182 1
    # the standard puppet distribution.
183 1
    
184 1
    require 'rack'
185 1
    require 'puppet'
186 1
    require 'puppet/network/http_server/rack'
187 1
    
188 1
    # startup code stolen from bin/puppetmasterd
189 1
    Puppet.parse_config
190 1
    Puppet::Util::Log.level = :info
191 1
    Puppet::Util::Log.newdestination(:syslog)
192 1
    # A temporary solution, to at least make the master work for now.
193 1
    Puppet::Node::Facts.terminus_class = :yaml
194 1
    # Cache our nodes in yaml.  Currently not configurable.
195 1
    Puppet::Node.cache_class = :yaml
196 1
    
197 1
    
198 1
    # The list of handlers running inside this puppetmaster
199 1
    handlers = {
200 1
        :Status => {},
201 1
        :FileServer => {},
202 1
        :Master => {},
203 1
        :CA => {},
204 1
        :FileBucket => {},
205 1
        :Report => {}
206 1
    }
207 1
    
208 1
    # Fire up the Rack-Server instance
209 1
    server = Puppet::Network::HTTPServer::Rack.new(handlers)
210 1
    
211 1
    # prepare the rack app
212 1
    app = proc do |env|
213 1
        server.process(env)
214 1
    end
215 1
    
216 1
    # Go.
217 1
    run app
218 1
219 5 micah -
If you don't want to run with the CA enabled, you could drop the :CA => {} line from the config.ru above.
220 1
221 1
## The config.ru file for 0.25.x
222 1
223 16 Nathan Rich
Please see ext/rack in the 0.25 source tree for the proper config.ru file. Same for 26.
224 1
225 1
## Suggested Tweaks
226 1
227 5 micah -
Based upon my (Larry Ludwig) testing of passenger/puppetmasterd I recommend adjusting these options in your apache configuration.
228 1
229 1
-   PassengerPoolIdleTime 300 - Set to 5 min (300 seconds) or less.
230 1
    The shorting this option allows for puppetmasterd to get refreshed
231 1
    at some interval. This option is also somewhat dependent upon the
232 1
    amount of puppetd nodes connecting and at what interval.
233 1
-   PassengerMaxPoolSize 15 - to 15% more instances than what's
234 1
    needed. This will allow idle puppetmasterd to get recycled. The net
235 1
    effect is less memory will be used, not more.
236 1
-   PassengerUseGlobalQueue on - Since communication with the
237 1
    puppetmaster from puppetd is a long process (more than 20 seconds
238 1
    in most cases) and will allow for processes to get recycled better
239 1
-   PassengerHighPerformance on - The additional Passenger features
240 1
    for apache compatibility are not needed with Puppet.
241 1
242 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.
243 1
244 5 micah -
To monitor the age of your puppetmasterd processes within Passenger, run
245 1
246 1
    passenger-status | grep PID | sort
247 1
248 1
      PID: 14590   Sessions: 1    Processed: 458     Uptime: 3m 40s
249 1
      PID: 7117    Sessions: 0    Processed: 10980   Uptime: 1h 43m 41s
250 1
      PID: 7355    Sessions: 0    Processed: 9736    Uptime: 1h 38m 38s
251 1
      PID: 7575    Sessions: 0    Processed: 9395    Uptime: 1h 32m 27s
252 1
      PID: 9950    Sessions: 0    Processed: 6581    Uptime: 1h 2m 35s
253 1
254 1
My personal preference is having Passenger recycling puppetmasterd every few hours to ensure memory/garbage collection from Ruby is not a factor.
255 8 Jeff McCune
256 8 Jeff McCune
257 8 Jeff McCune
## Troubleshooting
258 8 Jeff McCune
259 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"