Class: Pave::VirtualHost
- Inherits:
-
Object
- Object
- Pave::VirtualHost
- Includes:
- Shell
- Defined in:
- lib/pave/virtual_host.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
Instance Method Summary collapse
- #backup_vhost ⇒ Object
- #create_vhost ⇒ Object
-
#initialize(host) ⇒ VirtualHost
constructor
A new instance of VirtualHost.
- #remove_vhost ⇒ Object
- #restart_apache ⇒ Object
- #restore_vhost ⇒ Object
Methods included from Shell
Constructor Details
#initialize(host) ⇒ VirtualHost
Returns a new instance of VirtualHost.
10 11 12 |
# File 'lib/pave/virtual_host.rb', line 10 def initialize(host) @hostname = host end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/pave/virtual_host.rb', line 8 def hostname @hostname end |
Instance Method Details
#backup_vhost ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/pave/virtual_host.rb', line 27 def backup_vhost File.delete(vhosts_conf_file_backup) if File.exist?(vhosts_conf_file_backup) FileUtils.cp vhosts_conf_file, vhosts_conf_file_backup File.delete(hosts_file_backup) if File.exist?(hosts_file_backup) FileUtils.cp hosts_file, hosts_file_backup say "Backed up vhosts conf and hosts file. Use `pave vh:restore` to restore them." end |
#create_vhost ⇒ Object
14 15 16 17 18 19 |
# File 'lib/pave/virtual_host.rb', line 14 def create_vhost return say "No virtual host backup found. Run `pave vh:backup` before adding a virtual host." unless check_backup return say "No host name provided. Run `pave help` for more details." unless hostname.size > 0 add_vhost_to_conf && add_hosts_entry && restart_apache && say("Created virtual host for #{hostname}.") end |
#remove_vhost ⇒ Object
21 22 23 24 25 |
# File 'lib/pave/virtual_host.rb', line 21 def remove_vhost return say "No virtual host backup found. Run `pave vh:backup` before adding a virtual host." unless check_backup remove_vhost_from_conf && remove_hosts_entry && restart_apache && say("Removed virtual host for #{hostname}.") end |
#restart_apache ⇒ Object
49 50 51 52 53 |
# File 'lib/pave/virtual_host.rb', line 49 def restart_apache code = sh "sudo apachectl restart" say "Apache restarted." true end |
#restore_vhost ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pave/virtual_host.rb', line 35 def restore_vhost return say "Couldn't find vhosts backup." unless File.exist?(vhosts_conf_file_backup) File.delete(vhosts_conf_file) FileUtils.cp vhosts_conf_file_backup, vhosts_conf_file return say "Couldn't find host file backup." unless File.exist?(hosts_file_backup) File.delete(hosts_file) FileUtils.cp hosts_file_backup, hosts_file restart_apache say "Restored vhosts conf and host file." end |