23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/rack/handler/apache.rb', line 23
def self.run(app, options={})
unless ::File.exists? ::PhusionPassenger::APACHE2_MODULE
puts "Fatal: Passenger apache module missing, did you run passenger-install-apache2-module?"
exit
end
@root = ::Dir.pwd
@port = options[:Port] || 8080
@host = options[:Host] || '127.0.0.1'
@pid_file = "#{@root}/tmp/rack-helper-apache.pid"
@conf_file = "#{@root}/tmp/httpd.conf"
piam = ::File.expand_path("../../bin/passenger-install-apache2-module", $".find {|f|f=~/phusion_passenger.rb$/})
@passenger = `#{piam} --snippet`
puts "Warning: Please use SSLCertificateFile, not SSLCertificate" if
options[:SSLCertificate] && !options[:SSLCertificateFile]
puts "Warning: Please use SSLPrivateKeyFile, not SSLPrivateKey" if
options[:SSLPrivateKey] && !options[:SSLPrivateKeyFile]
config = " \#{@passenger}\n User \#{Etc.getlogin}\n Listen \#{@host}:\#{@port}\n PidFile \#{@pid_file}\n ErrorLog \#{$stdout.ttyname}\n LockFile \#{@root}/tmp/rack-helper-apache.lock\n ServerName localhost\n <VirtualHost *:\#{@port}>\n ServerName localhost\n \#{options[:SSLEnable] ? \"SSLEngine on\" : \"\"}\n DocumentRoot \#{@root}/public\n <Directory \#{@root}/public>\n AllowOverride all\n Options -MultiViews\n </Directory>\n \#{options[:HostConfig]}\n </VirtualHost>\n \#{options[:ServerConfig]}\n EOD\n\n if options[:SSLEnable]\n config = <<-EOD.gsub(/^ {12}/, '')+config\n LoadModule ssl_module libexec/apache2/mod_ssl.so\n SSLCertificateFile \#{options[:SSLCertificateFile]}\n SSLCertificateKeyFile \#{options[:SSLPrivateKeyFile]}\n SSLSessionCache none\n EOD\n end\n\n ::Dir.mkdir(\"tmp\") unless ::Dir.exists? \"tmp\"\n\n kill_httpd()\n ::File.open(@conf_file, 'w') { |f| f.write(config) }\n system(apache_bin,'-f',@conf_file)\n\n print \"Waiting for apache to start...\"\n 10.times { break if is_running?; sleep 0.5; print \".\"; STDOUT.flush }\n\n if is_running?\n puts \"...started [pid:\#{get_pid}]\"\n puts \"Available at \#{options[:SSLEnable]?'https':'http'}://\#{@host}:\#{@port}\"\n sleep 0.5 while is_running?\n puts \"Apache terminated.\"\n else\n puts \"...never started!\"\n exit\n end\n\nend\n".gsub(/^ {10}/, '')
|