rack-handler-apache 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack-handler-apache.rb +1 -0
- data/lib/rack/handler/apache.rb +135 -0
- metadata +46 -0
@@ -0,0 +1 @@
|
|
1
|
+
require "rack/handler/apache"
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "phusion_passenger"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module Handler
|
5
|
+
class Apache
|
6
|
+
|
7
|
+
def self.valid_options
|
8
|
+
{
|
9
|
+
"Port=PORT" => "Port to listen on (default: 8080)",
|
10
|
+
#TODO#"Host=HOST" => "Hostname to listen on (default: localhost)",
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.run(app, options={})
|
15
|
+
|
16
|
+
unless ::File.exists? ::PhusionPassenger::APACHE2_MODULE
|
17
|
+
puts "Passenger apache module missing, did you run passenger-install-apache2-module?"
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
@root = ::Dir.pwd
|
22
|
+
@port = options[:Port] || 8080
|
23
|
+
@pid_file = "#{@root}/tmp/rack-helper-apache.pid"
|
24
|
+
@conf_file = "#{@root}/tmp/httpd.conf"
|
25
|
+
@passenger = `bundle exec passenger-install-apache2-module --snippet`
|
26
|
+
|
27
|
+
puts "Warning: Please use SSLCertificateFile, not SSLCertificate" if
|
28
|
+
options[:SSLCertificate] && !options[:SSLCertificateFile]
|
29
|
+
|
30
|
+
puts "Warning: Please use SSLPrivateKeyFile, not SSLPrivateKey" if
|
31
|
+
options[:SSLPrivateKey] && !options[:SSLPrivateKeyFile]
|
32
|
+
|
33
|
+
config = <<-EOD.gsub(/^ {10}/, '')
|
34
|
+
#{@passenger}
|
35
|
+
User #{Etc.getlogin}
|
36
|
+
Listen #{@port}
|
37
|
+
PidFile #{@pid_file}
|
38
|
+
ErrorLog #{@root}/log/rack-helper-apache_error.log
|
39
|
+
LockFile #{@root}/tmp/rack-helper-apache.lock
|
40
|
+
ServerName localhost
|
41
|
+
<VirtualHost *:#{@port}>
|
42
|
+
ServerName localhost
|
43
|
+
#{options[:SSLEnable] ? "SSLEngine on" : ""}
|
44
|
+
DocumentRoot #{@root}/public
|
45
|
+
<Directory #{@root}/public>
|
46
|
+
AllowOverride all
|
47
|
+
Options -MultiViews
|
48
|
+
</Directory>
|
49
|
+
</VirtualHost>
|
50
|
+
EOD
|
51
|
+
|
52
|
+
if options[:SSLEnable]
|
53
|
+
config = <<-EOD.gsub(/^ {12}/, '')+config
|
54
|
+
LoadModule ssl_module libexec/apache2/mod_ssl.so
|
55
|
+
SSLCertificateFile #{options[:SSLCertificateFile]}
|
56
|
+
SSLCertificateKeyFile #{options[:SSLPrivateKeyFile]}
|
57
|
+
SSLSessionCache none
|
58
|
+
EOD
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
kill_httpd()
|
64
|
+
::File.open(@conf_file, 'w') { |f| f.write(config) }
|
65
|
+
system(apache_bin,'-f',@conf_file)
|
66
|
+
|
67
|
+
print "Waiting for apache to start..."
|
68
|
+
10.times { break if is_running?; sleep 0.5; print "."; STDOUT.flush }
|
69
|
+
|
70
|
+
if is_running?
|
71
|
+
puts "...started [pid:#{get_pid}]"
|
72
|
+
sleep 0.5 while is_running?
|
73
|
+
puts "Apache terminated."
|
74
|
+
else
|
75
|
+
puts "...never started!"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def self.shutdown()
|
83
|
+
kill_httpd()
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
|
89
|
+
# Locate apache - since sbin is often not in the path,
|
90
|
+
# we check there too - with a strong OS-X bias
|
91
|
+
def self.apache_bin()
|
92
|
+
[ 'apache2', 'httpd' ].each do |b|
|
93
|
+
ENV['PATH'].split(':')+[
|
94
|
+
'/opt/local/sbin',
|
95
|
+
'/sw/sbin',
|
96
|
+
'/usr/local/sbin',
|
97
|
+
'/usr/sbin'
|
98
|
+
].each do |d|
|
99
|
+
d_b = ::File.join(d,b)
|
100
|
+
return d_b if ::File.executable? d_b
|
101
|
+
end
|
102
|
+
end
|
103
|
+
return false;
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def self.get_pid
|
108
|
+
if ::File.exists? @pid_file
|
109
|
+
::File.read(@pid_file).to_i
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.is_running?
|
114
|
+
if pid=get_pid
|
115
|
+
begin
|
116
|
+
::Process.kill 0, pid
|
117
|
+
return true
|
118
|
+
rescue Errno::ESRCH => e
|
119
|
+
end
|
120
|
+
end
|
121
|
+
return false
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.kill_httpd()
|
125
|
+
if pid = get_pid
|
126
|
+
puts "Killing apache [pid:#{pid}]..."
|
127
|
+
::Process.kill "TERM", pid
|
128
|
+
::File.unlink @pid_file
|
129
|
+
sleep 1
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-handler-apache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gavin Brock
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2010-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A rack-handler like gem for apache/passenger
|
15
|
+
email: gavin@brock-family.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/rack/handler/apache.rb
|
21
|
+
- lib/rack-handler-apache.rb
|
22
|
+
homepage: https://github.com/brockgr/rack-handler-apache
|
23
|
+
licenses: []
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.23
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Rack::Handle::Apache
|
46
|
+
test_files: []
|