Using Passenger

Version 1 (Anonymous, 03/13/2010 08:02 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 1
5 1
Alternatively see: [[Using Mongrel]]
6 1
7 1
## Why You'd Do This
8 1
9 1
Traditionally, the puppetmaster would embed a WEBrick or Mongrel
10 1
Web Server to serve the puppet clients. This may work well for you,
11 1
but a few people feel like using a proven web server like Apache
12 1
would be superior for this purpose.
13 1
14 1
## What is Passenger ?
15 1
16 1
[Passenger](http://www.modrails.com/) (AKA mod\_rails or mod\_rack)
17 1
is the Apache 2.x Extension which lets you run Rails or Rack
18 1
applications inside Apache.
19 1
20 1
Puppet (>0.24.6) now ships with a Rack application which can embed
21 1
a puppetmaster. While it should be compatible with every Rack
22 1
application server, it has only been tested with Passenger.
23 1
24 1
Depending on your operating system, the versions of Puppet, Apache
25 1
and Passenger may not support this implementation. Specifically,
26 1
Ubuntu Hardy ships with an older version of puppet (0.24.4) and
27 1
doesn't include passenger at all, however updated packages for
28 1
puppet can be found
29 1
[here](https://launchpad.net/~bitpusher/+archive/ppa). There are
30 1
also some passenger packages there, but as of 2009-09-28 they do
31 1
not seem to have the latest passenger (2.2.5), so better install
32 1
passenger from a gem as per the instructions at [modrails.com].
33 1
34 1
Note: Passenger versions 2.2.3 and 2.2.4 have known bugs regarding
35 1
to the SSL environment variables, which make them unsuitable for
36 1
hosting a puppetmaster. So use either 2.2.2, or 2.2.5. Note that
37 1
while it was expected that Passenger 2.2.2 would be the last
38 1
version which can host a 0.24.x puppetmaster, that turns out to be
39 1
not true, cf.
40 1
[this bug report](http://projects.reductivelabs.com/issues/2386#change-9238).
41 1
So, passenger 2.2.5 works fine.
42 1
43 1
## Installation Instructions for Puppet 0.25.x
44 1
45 1
Please see
46 1
[ext/rack/README in the puppet source](http://github.com/reductivelabs/puppet/tree/master/ext/rack)
47 1
tree for instructions.
48 1
49 1
Whatever you do, make sure your config.ru file is owned by the
50 1
puppet user! Passenger will setuid to that user.
51 1
52 1
## Installation Summary for Puppet 0.24.x for Debian/Ubuntu and RHEL5
53 1
54 1
Make sure puppetmasterd ran at least once, so puppetmasterd SSL
55 1
certificates are setup intially.
56 1
57 1
### Install Apache 2, Rack and Passenger
58 1
59 1
For Debian/Ubuntu:
60 1
61 1
    apt-get install apache2
62 1
    apt-get install ruby1.8-dev
63 1
64 1
For RHEL5 (needs the [EPEL](https://fedoraproject.org/wiki/EPEL)
65 1
repository enabled):
66 1
67 1
    yum install httpd httpd-devel ruby-devel rubygems
68 1
69 1
### Install Rack/Passenger
70 1
71 1
The latest version of Passenger (2.2.5) appears to work fine on
72 1
RHEL5:
73 1
74 1
    gem install rack
75 1
    gem install passenger
76 1
    passenger-install-apache2-module
77 1
78 1
If you want the older 2.2.2 gem, you could manually download the
79 1
.gem file from
80 1
[RubyForge](http://rubyforge.org/frs/?group_id=5873). Or, you could
81 1
just add the correct versions to your gem command:
82 1
83 1
      gem install -v 0.4.0 rack
84 1
      gem install -v 2.2.2 passenger 
85 1
86 1
Enable Apache modules "ssl" and "headers":
87 1
88 1
    # for Debian or Ubuntu:
89 1
    a2enmod ssl
90 1
    a2enmod headers
91 1
    
92 1
    # for RHEL5
93 1
    yum install mod_ssl
94 1
95 1
### Configure Apache
96 1
97 1
For Debian/Ubuntu:
98 1
99 1
    cp apache2.conf /etc/apache2/sites-available/puppetmasterd  (see below for the file contents)
100 1
    ln -s /etc/apache2/sites-available/puppetmasterd /etc/apache2/sites-enabled/puppetmasterd
101 1
    vim /etc/apache2/conf.d/puppetmasterd (replace the hostnames)
102 1
103 1
For RHEL5:
104 1
105 1
    cp puppetmaster.conf /etc/httpd/conf.d/ (see below for file contents)
106 1
    vim /etc/httpd/conf.d/puppetmaster.conf (replace hostnames with corrent values)
107 1
108 1
Install the rack application [1]:
109 1
110 1
    mkdir -p /usr/share/puppet/rack/puppetmasterd
111 1
    mkdir /usr/share/puppet/rack/puppetmasterd/public /usr/share/puppet/rack/puppetmasterd/tmp
112 1
    cp config.ru /usr/share/puppet/rack/puppetmasterd
113 1
    chown puppet /usr/share/puppet/rack/puppetmasterd/config.ru
114 1
115 1
Go:
116 1
117 1
    # For Debian/Ubuntu
118 1
    /etc/init.d/apache2 restart
119 1
    
120 1
    # For RHEL5
121 1
    /etc/init.d/httpd restart
122 1
123 1
If all works well, you'll want to make sure your puppmetmasterd
124 1
init script does not get called anymore:
125 1
126 1
    # For Debian/Ubuntu
127 1
    update-rc.d -f puppetmaster remove
128 1
    
129 1
    # For RHEL5
130 1
    chkconfig puppetmaster off
131 1
    chkconfig httpd on
132 1
133 1
[1] Passenger will not let applications run as root or the Apache
134 1
user, instead an implicit setuid will be done, to the user whom
135 1
owns config.ru. Therefore, config.ru shall be owned by the puppet
136 1
user.
137 1
138 1
## Apache Configuration for Puppet 0.24.x
139 1
140 1
This Apache Virtual Host configures the puppetmaster on the default
141 1
puppetmaster port (8140).
142 1
143 1
    Listen 8140
144 1
    <VirtualHost *:8140>
145 1
    
146 1
        SSLEngine on
147 1
        SSLCipherSuite SSLv2:-LOW:-EXPORT:RC4+RSA
148 1
        SSLCertificateFile      /var/lib/puppet/ssl/certs/puppet-server.inqnet.at.pem
149 1
        SSLCertificateKeyFile   /var/lib/puppet/ssl/private_keys/puppet-server.inqnet.at.pem
150 1
        SSLCertificateChainFile /var/lib/puppet/ssl/ca/ca_crt.pem
151 1
        SSLCACertificateFile    /var/lib/puppet/ssl/ca/ca_crt.pem
152 1
        # CRL checking should be enabled; if you have problems with Apache complaining about the CRL, disable the next line
153 1
        SSLCARevocationFile     /var/lib/puppet/ssl/ca/ca_crl.pem
154 1
        SSLVerifyClient optional
155 1
        SSLVerifyDepth  1
156 1
        SSLOptions +StdEnvVars
157 1
    
158 1
        # The following client headers allow the same configuration to work with Pound.
159 1
        RequestHeader set X-SSL-Subject %{SSL_CLIENT_S_DN}e
160 1
        RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e
161 1
        RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e
162 1
    
163 1
        RackAutoDetect On
164 1
        DocumentRoot /usr/share/puppet/rack/puppetmasterd/public/
165 1
        <Directory /usr/share/puppet/rack/puppetmasterd/>
166 1
            Options None
167 1
            AllowOverride None
168 1
            Order allow,deny
169 1
            allow from all
170 1
        </Directory>
171 1
    </VirtualHost>
172 1
173 1
If the current puppetmaster is not a certificate authority, you may
174 1
need to change the following lines. The certs/ca.pem file should
175 1
exist as long as the puppetmaster has been signed by the CA.
176 1
177 1
      SSLCertificateChainFile /var/lib/puppet/ssl/certs/ca.pem
178 1
        SSLCACertificateFile    /var/lib/puppet/ssl/certs/ca.pem
179 1
180 1
For Debian hosts you might wish to add:
181 1
182 1
      LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
183 1
        PassengerRoot /var/lib/gems/1.8/gems/passenger-2.2.5
184 1
        PassengerRuby /usr/bin/ruby1.8
185 1
186 1
For RHEL hosts you may need to add:
187 1
188 1
       LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
189 1
       PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5
190 1
       PassengerRuby /usr/bin/ruby
191 1
192 1
For details about enabling and configuring Passenger, see the
193 1
[Passenger install guide](http://www.modrails.com/install.html).
194 1
195 1
## The config.ru file for Puppet 0.24.x
196 1
197 1
    # This file is mostly based on puppetmasterd, which is part of
198 1
    # the standard puppet distribution.
199 1
    
200 1
    require 'rack'
201 1
    require 'puppet'
202 1
    require 'puppet/network/http_server/rack'
203 1
    
204 1
    # startup code stolen from bin/puppetmasterd
205 1
    Puppet.parse_config
206 1
    Puppet::Util::Log.level = :info
207 1
    Puppet::Util::Log.newdestination(:syslog)
208 1
    # A temporary solution, to at least make the master work for now.
209 1
    Puppet::Node::Facts.terminus_class = :yaml
210 1
    # Cache our nodes in yaml.  Currently not configurable.
211 1
    Puppet::Node.cache_class = :yaml
212 1
    
213 1
    
214 1
    # The list of handlers running inside this puppetmaster
215 1
    handlers = {
216 1
        :Status => {},
217 1
        :FileServer => {},
218 1
        :Master => {},
219 1
        :CA => {},
220 1
        :FileBucket => {},
221 1
        :Report => {}
222 1
    }
223 1
    
224 1
    # Fire up the Rack-Server instance
225 1
    server = Puppet::Network::HTTPServer::Rack.new(handlers)
226 1
    
227 1
    # prepare the rack app
228 1
    app = proc do |env|
229 1
        server.process(env)
230 1
    end
231 1
    
232 1
    # Go.
233 1
    run app
234 1
235 1
If you don't want to run with the CA enabled, you could drop the
236 1
:CA => {} line from the config.ru above.
237 1
238 1
## The config.ru file for 0.25.x
239 1
240 1
Please see ext/rack in the 0.25 source tree for the proper
241 1
config.ru file.
242 1
243 1
## Suggested Tweaks
244 1
245 1
Based upon my (Larry Ludwig) testing of passenger/puppetmasterd I
246 1
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 1
No different than with traditional web servers, once your service
262 1
starts using swap performance degradation will occur. So be mindful
263 1
of your memory/swap usage on your Puppetmaster.
264 1
265 1
To monitor the age of your puppetmasterd processes within
266 1
Passenger, run
267 1
268 1
    passenger-status | grep PID | sort
269 1
270 1
      PID: 14590   Sessions: 1    Processed: 458     Uptime: 3m 40s
271 1
      PID: 7117    Sessions: 0    Processed: 10980   Uptime: 1h 43m 41s
272 1
      PID: 7355    Sessions: 0    Processed: 9736    Uptime: 1h 38m 38s
273 1
      PID: 7575    Sessions: 0    Processed: 9395    Uptime: 1h 32m 27s
274 1
      PID: 9950    Sessions: 0    Processed: 6581    Uptime: 1h 2m 35s
275 1
276 1
My personal preference is having Passenger recycling puppetmasterd
277 1
every few hours to ensure memory/garbage collection from Ruby is
278 1
not a factor.