This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
httpd_conf.rb
66 lines (55 loc) · 1.67 KB
/
httpd_conf.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
module PassengerPane
class HttpdConf
attr_accessor :filename
def initialize(configuration)
@configuration = configuration
@filename = File.expand_path(configuration.httpd_conf, configuration.apache_directory)
end
def contents
@contents ||= File.read(@filename)
end
attr_writer :contents
def passenger_vhost_include
"Include #{@configuration.apache_directory}/#{@configuration.passenger_vhosts}/*.#{@configuration.passenger_vhosts_ext}"
end
def passenger_configuration_snippet
%{
# Added by the Passenger preference pane
# Make sure to include the Passenger configuration (the LoadModule,
# PassengerRoot, and PassengerRuby directives) before this section.
<IfModule passenger_module>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName _default_
</VirtualHost>
#{passenger_vhost_include}
</IfModule>
}.strip
end
def valid?
`#{@configuration.httpd_binary} -t 2>&1`.strip == 'Syntax OK'
end
def restart
if valid?
system @configuration.apache_restart_command
else
puts "[!] Apache configuration is not valid, skipping Apache restart"
end
end
def passenger_module_installed?
`#{@configuration.httpd_binary} -D DUMP_MODULES 2>&1`.include? 'passenger_module'
end
def passenger_configured?
!!(contents =~ /Include.*#{@configuration.passenger_vhosts}/)
end
def configure_passenger
self.contents << "\n\n"
self.contents << passenger_configuration_snippet
end
def write
File.open(@filename, 'w') do |file|
file.write(contents)
end
end
end
end