Class: Web::Install::Apache
- Includes:
- FileUtils
- Defined in:
- lib/web/sapi/install/apache.rb
Instance Attribute Summary collapse
-
#httpd_conf ⇒ Object
Returns the value of attribute httpd_conf.
-
#install_dir ⇒ Object
Returns the value of attribute install_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #apache ⇒ Object
- #apache_root ⇒ Object
- #backup ⇒ Object
-
#initialize(install_dir, httpd_conf) ⇒ Apache
constructor
A new instance of Apache.
- #install ⇒ Object
- #ruby_conf ⇒ Object
- #temp ⇒ Object
- #test_config_cmd ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(install_dir, httpd_conf) ⇒ Apache
Returns a new instance of Apache.
12 13 14 15 |
# File 'lib/web/sapi/install/apache.rb', line 12 def initialize( install_dir, httpd_conf ) @install_dir = install_dir @httpd_conf = httpd_conf end |
Instance Attribute Details
#httpd_conf ⇒ Object
Returns the value of attribute httpd_conf.
11 12 13 |
# File 'lib/web/sapi/install/apache.rb', line 11 def httpd_conf @httpd_conf end |
#install_dir ⇒ Object
Returns the value of attribute install_dir.
11 12 13 |
# File 'lib/web/sapi/install/apache.rb', line 11 def install_dir @install_dir end |
Class Method Details
Instance Method Details
#apache ⇒ Object
21 22 23 24 25 26 |
# File 'lib/web/sapi/install/apache.rb', line 21 def apache [apache_root + "/Apache.exe", apache_root + "/bin/Apache.exe" ].find do |f| File.exists? f end end |
#apache_root ⇒ Object
17 18 19 |
# File 'lib/web/sapi/install/apache.rb', line 17 def apache_root File.dirname( File.dirname( httpd_conf ) ) end |
#backup ⇒ Object
41 42 43 |
# File 'lib/web/sapi/install/apache.rb', line 41 def backup "#{httpd_conf}.ruby-web.backup.#{Time::now::strftime('%Y.%m.%d') }" end |
#install ⇒ Object
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 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/web/sapi/install/apache.rb', line 57 def install puts "******************************************", "* Installing .rhtml and .rb mappings *", "* for Apache *", "******************************************" new_conf = '' lines = File.open( httpd_conf, "r" ) {|f| f.read } lines.each do |line| if line =~ /index.html/ && ! line =~ /index.rhtml/ line.gsub!(/index.html/,'index.html index.php') end if line =~ /AddHandler cgi-script.*(\.rb|\.rhtml)/ ruby_conf.delete_at(0) end new_conf += line + "\n" end cp( httpd_conf, backup ) config_file_changed = false if ruby_conf.empty? # apparently there is nothing to do... else new_conf += "\n\n################# Ruby Web ###################\n" new_conf += ruby_conf.join "\n" File.open(temp, "w") do |f| f.write new_conf end cp( temp, httpd_conf ) config_file_changed = true # ----------- Restart Apache ------------ unless system(test_config_cmd) puts("[ruby-web #{$0}]: Unable that the Apache webserver is running correcly with the new module and the configuration file changes using the '#{test_config_cmd}' command. Ruby-Web itself has been installed sucessfully, but it has not been activated. Your old #{httpd_conf} file is untouched...") puts "[ruby-web #{$0}]: The modified config file is available in '#{temp}' so you can examine it and try to activate Ruby-Web" cp( backup, conf ) else # restart apache system('net stop apache') system('net start apache') end end end |
#ruby_conf ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/web/sapi/install/apache.rb', line 49 def ruby_conf unless @ruby_conf @ruby_conf = Array.new @ruby_conf.push "AddHandler cgi-script .rb .rhtml" end @ruby_conf end |
#temp ⇒ Object
45 46 47 |
# File 'lib/web/sapi/install/apache.rb', line 45 def temp "#{httpd_conf}.ruby-web.temp" end |
#test_config_cmd ⇒ Object
28 29 30 |
# File 'lib/web/sapi/install/apache.rb', line 28 def test_config_cmd apache + " -t" if apache end |
#version ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/web/sapi/install/apache.rb', line 32 def version case apache when apache_root + "/Apache.exe" 1 when apache_root + "/bin/Apache.exe" 2 end end |