1 require 'spec_helper_acceptance'
3 describe 'apache::mod::passenger class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
6 service_name = 'apache2'
7 mod_dir = '/etc/apache2/mods-available/'
8 conf_file = "#{mod_dir}passenger.conf"
9 load_file = "#{mod_dir}zpassenger.load"
11 case fact('operatingsystem')
13 case fact('lsbdistrelease')
15 passenger_root = '/usr'
16 passenger_ruby = '/usr/bin/ruby'
18 passenger_root = '/usr'
19 passenger_ruby = '/usr/bin/ruby'
21 passenger_root = '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini'
22 passenger_ruby = '/usr/bin/ruby'
23 passenger_default_ruby = '/usr/bin/ruby'
25 # This may or may not work on Ubuntu releases other than the above
26 passenger_root = '/usr'
27 passenger_ruby = '/usr/bin/ruby'
30 case fact('lsbdistcodename')
32 passenger_root = '/usr'
33 passenger_ruby = '/usr/bin/ruby'
35 passenger_root = '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini'
36 passenger_ruby = '/usr/bin/ruby'
37 passenger_default_ruby = '/usr/bin/ruby'
39 # This may or may not work on Debian releases other than the above
40 passenger_root = '/usr'
41 passenger_ruby = '/usr/bin/ruby'
45 passenger_module_path = '/usr/lib/apache2/modules/mod_passenger.so'
46 rackapp_user = 'www-data'
47 rackapp_group = 'www-data'
49 service_name = 'httpd'
50 mod_dir = '/etc/httpd/conf.d/'
51 conf_file = "#{mod_dir}passenger.conf"
52 load_file = "#{mod_dir}zpassenger.load"
53 # sometimes installs as 3.0.12, sometimes as 3.0.19 - so just check for the stable part
54 passenger_root = '/usr/lib/ruby/gems/1.8/gems/passenger-3.0.1'
55 passenger_ruby = '/usr/bin/ruby'
56 passenger_tempdir = '/var/run/rubygem-passenger'
57 passenger_module_path = 'modules/mod_passenger.so'
58 rackapp_user = 'apache'
59 rackapp_group = 'apache'
63 /* a simple ruby rack 'hellow world' app */
64 file { '/var/www/passenger':
66 owner => '#{rackapp_user}',
67 group => '#{rackapp_group}',
68 require => Class['apache::mod::passenger'],
70 file { '/var/www/passenger/config.ru':
72 owner => '#{rackapp_user}',
73 group => '#{rackapp_group}',
74 content => "app = proc { |env| [200, { \\"Content-Type\\" => \\"text/html\\" }, [\\"hello <b>world</b>\\"]] }\\nrun app",
75 require => File['/var/www/passenger'] ,
77 apache::vhost { 'passenger.example.com':
79 docroot => '/var/www/passenger/public',
80 docroot_group => '#{rackapp_group}' ,
81 docroot_owner => '#{rackapp_user}' ,
82 custom_fragment => "PassengerRuby #{passenger_ruby}\\nRailsEnv development" ,
83 require => File['/var/www/passenger/config.ru'] ,
85 host { 'passenger.example.com': ip => '127.0.0.1', }
90 context "default passenger config" do
91 it 'succeeds in puppeting passenger' do
93 /* stock apache and mod_passenger */
95 class { 'apache::mod::passenger': }
98 apply_manifest(pp, :catch_failures => true)
101 describe service(service_name) do
102 it { is_expected.to be_enabled }
103 it { is_expected.to be_running }
106 describe file(conf_file) do
107 it { is_expected.to contain "PassengerRoot \"#{passenger_root}\"" }
109 case fact('operatingsystem')
111 case fact('lsbdistrelease')
113 it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
114 it { is_expected.not_to contain "/PassengerDefaultRuby/" }
116 it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
117 it { is_expected.not_to contain "/PassengerDefaultRuby/" }
119 it { is_expected.to contain "PassengerDefaultRuby \"#{passenger_ruby}\"" }
120 it { is_expected.not_to contain "/PassengerRuby/" }
122 # This may or may not work on Ubuntu releases other than the above
123 it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
124 it { is_expected.not_to contain "/PassengerDefaultRuby/" }
127 case fact('lsbdistcodename')
129 it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
130 it { is_expected.not_to contain "/PassengerDefaultRuby/" }
132 it { is_expected.to contain "PassengerDefaultRuby \"#{passenger_ruby}\"" }
133 it { is_expected.not_to contain "/PassengerRuby/" }
135 # This may or may not work on Debian releases other than the above
136 it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
137 it { is_expected.not_to contain "/PassengerDefaultRuby/" }
142 describe file(load_file) do
143 it { is_expected.to contain "LoadModule passenger_module #{passenger_module_path}" }
146 it 'should output status via passenger-memory-stats' do
147 shell("PATH=/usr/bin:$PATH /usr/sbin/passenger-memory-stats") do |r|
148 expect(r.stdout).to match(/Apache processes/)
149 expect(r.stdout).to match(/Nginx processes/)
150 expect(r.stdout).to match(/Passenger processes/)
152 # passenger-memory-stats output on newer Debian/Ubuntu verions do not contain
154 unless ((fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '14.04') or
155 (fact('operatingsystem') == 'Debian' && fact('operatingsystemrelease') == '8.0'))
156 expect(r.stdout).to match(/### Processes: [0-9]+/)
157 expect(r.stdout).to match(/### Total private dirty RSS: [0-9\.]+ MB/)
160 expect(r.exit_code).to eq(0)
164 # passenger-status fails under stock ubuntu-server-12042-x64 + mod_passenger,
165 # even when the passenger process is successfully installed and running
166 unless fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '12.04'
167 it 'should output status via passenger-status' do
168 # xml output not available on ubunutu <= 10.04, so sticking with default pool output
169 shell("PATH=/usr/bin:$PATH /usr/sbin/passenger-status") do |r|
171 expect(r.stdout).to match(/[\-]+ General information [\-]+/)
172 if fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '14.04'
173 expect(r.stdout).to match(/Max pool size[ ]+: [0-9]+/)
174 expect(r.stdout).to match(/Processes[ ]+: [0-9]+/)
175 expect(r.stdout).to match(/Requests in top-level queue[ ]+: [0-9]+/)
177 expect(r.stdout).to match(/max[ ]+= [0-9]+/)
178 expect(r.stdout).to match(/count[ ]+= [0-9]+/)
179 expect(r.stdout).to match(/active[ ]+= [0-9]+/)
180 expect(r.stdout).to match(/inactive[ ]+= [0-9]+/)
181 expect(r.stdout).to match(/Waiting on global queue: [0-9]+/)
184 expect(r.exit_code).to eq(0)
189 it 'should answer to passenger.example.com' do
190 shell("/usr/bin/curl passenger.example.com:80") do |r|
191 expect(r.stdout).to match(/^hello <b>world<\/b>$/)
192 expect(r.exit_code).to eq(0)
199 # no fedora 18 passenger package yet, and rhel5 packages only exist for ruby 1.8.5
200 unless (fact('operatingsystem') == 'Fedora' and fact('operatingsystemrelease').to_f >= 18) or (fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '5' and fact('rubyversion') != '1.8.5')
202 if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '7'
203 pending('test passenger - RHEL7 packages don\'t exist')
205 context "default passenger config" do
206 it 'succeeds in puppeting passenger' do
208 /* EPEL and passenger repositories */
210 exec { 'passenger.repo GPG key':
211 command => '/usr/bin/curl -o /etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc http://passenger.stealthymonkeys.com/RPM-GPG-KEY-stealthymonkeys.asc',
212 creates => '/etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc',
214 file { 'passenger.repo GPG key':
216 path => '/etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc',
217 require => Exec['passenger.repo GPG key'],
219 epel::rpm_gpg_key { 'passenger.stealthymonkeys.com':
220 path => '/etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc',
223 File['passenger.repo GPG key'],
226 $releasever_string = $operatingsystem ? {
228 default => '$releasever',
230 yumrepo { 'passenger':
231 baseurl => "http://passenger.stealthymonkeys.com/rhel/${releasever_string}/\\$basearch" ,
232 descr => "Red Hat Enterprise ${releasever_string} - Phusion Passenger",
235 gpgkey => 'http://passenger.stealthymonkeys.com/RPM-GPG-KEY-stealthymonkeys.asc',
236 mirrorlist => 'http://passenger.stealthymonkeys.com/rhel/mirrors',
238 Epel::Rpm_gpg_key['passenger.stealthymonkeys.com'],
241 /* apache and mod_passenger */
247 class { 'apache::mod::passenger':
254 apply_manifest(pp, :catch_failures => true)
257 describe service(service_name) do
258 it { is_expected.to be_enabled }
259 it { is_expected.to be_running }
262 describe file(conf_file) do
263 it { is_expected.to contain "PassengerRoot #{passenger_root}" }
264 it { is_expected.to contain "PassengerRuby #{passenger_ruby}" }
265 it { is_expected.to contain "PassengerTempDir #{passenger_tempdir}" }
268 describe file(load_file) do
269 it { is_expected.to contain "LoadModule passenger_module #{passenger_module_path}" }
272 it 'should output status via passenger-memory-stats' do
273 shell("/usr/bin/passenger-memory-stats", :pty => true) do |r|
274 expect(r.stdout).to match(/Apache processes/)
275 expect(r.stdout).to match(/Nginx processes/)
276 expect(r.stdout).to match(/Passenger processes/)
277 expect(r.stdout).to match(/### Processes: [0-9]+/)
278 expect(r.stdout).to match(/### Total private dirty RSS: [0-9\.]+ MB/)
280 expect(r.exit_code).to eq(0)
284 it 'should output status via passenger-status' do
285 shell("PASSENGER_TMPDIR=/var/run/rubygem-passenger /usr/bin/passenger-status") do |r|
287 r.stdout.should =~ /[\-]+ General information [\-]+/
288 r.stdout.should =~ /max[ ]+= [0-9]+/
289 r.stdout.should =~ /count[ ]+= [0-9]+/
290 r.stdout.should =~ /active[ ]+= [0-9]+/
291 r.stdout.should =~ /inactive[ ]+= [0-9]+/
292 r.stdout.should =~ /Waiting on global queue: [0-9]+/
294 r.exit_code.should == 0
298 it 'should answer to passenger.example.com' do
299 shell("/usr/bin/curl passenger.example.com:80") do |r|
300 r.stdout.should =~ /^hello <b>world<\/b>$/
301 r.exit_code.should == 0