Class: PassengerPane::HttpdConf
- Inherits:
-
Object
- Object
- PassengerPane::HttpdConf
- Defined in:
- lib/passenger_pane/httpd_conf.rb
Instance Attribute Summary collapse
- #contents ⇒ Object
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #configure_passenger ⇒ Object
-
#initialize(configuration) ⇒ HttpdConf
constructor
A new instance of HttpdConf.
- #passenger_configuration_snippet ⇒ Object
- #passenger_configured? ⇒ Boolean
- #passenger_module_installed? ⇒ Boolean
- #passenger_vhost_include ⇒ Object
- #restart ⇒ Object
- #valid? ⇒ Boolean
- #write ⇒ Object
Constructor Details
#initialize(configuration) ⇒ HttpdConf
Returns a new instance of HttpdConf.
5 6 7 8 |
# File 'lib/passenger_pane/httpd_conf.rb', line 5 def initialize(configuration) @configuration = configuration @filename = File.(configuration.httpd_conf, configuration.apache_directory) end |
Instance Attribute Details
#contents ⇒ Object
10 11 12 |
# File 'lib/passenger_pane/httpd_conf.rb', line 10 def contents @contents ||= File.read(@filename) end |
#filename ⇒ Object
Returns the value of attribute filename.
3 4 5 |
# File 'lib/passenger_pane/httpd_conf.rb', line 3 def filename @filename end |
Instance Method Details
#configure_passenger ⇒ Object
55 56 57 58 |
# File 'lib/passenger_pane/httpd_conf.rb', line 55 def configure_passenger self.contents << "\n\n" self.contents << passenger_configuration_snippet end |
#passenger_configuration_snippet ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/passenger_pane/httpd_conf.rb', line 20 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 |
#passenger_configured? ⇒ Boolean
51 52 53 |
# File 'lib/passenger_pane/httpd_conf.rb', line 51 def passenger_configured? !!(contents =~ /Include.*#{@configuration.passenger_vhosts}/) end |
#passenger_module_installed? ⇒ Boolean
47 48 49 |
# File 'lib/passenger_pane/httpd_conf.rb', line 47 def passenger_module_installed? `#{@configuration.httpd_binary} -D DUMP_MODULES 2>&1`.include? 'passenger_module' end |
#passenger_vhost_include ⇒ Object
16 17 18 |
# File 'lib/passenger_pane/httpd_conf.rb', line 16 def passenger_vhost_include "Include #{@configuration.apache_directory}/#{@configuration.passenger_vhosts}/*.#{@configuration.passenger_vhosts_ext}" end |
#restart ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/passenger_pane/httpd_conf.rb', line 39 def restart if valid? system @configuration.apache_restart_command else puts "[!] Apache configuration is not valid, skipping Apache restart" end end |
#valid? ⇒ Boolean
35 36 37 |
# File 'lib/passenger_pane/httpd_conf.rb', line 35 def valid? `#{@configuration.httpd_binary} -t 2>&1`.strip.end_with?('Syntax OK') end |
#write ⇒ Object
60 61 62 63 64 |
# File 'lib/passenger_pane/httpd_conf.rb', line 60 def write File.open(@filename, 'w') do |file| file.write(contents) end end |