lib/dogids/reload.rb in dogids-cli-0.0.20 vs lib/dogids/reload.rb in dogids-cli-0.0.21
- old
+ new
@@ -1,5 +1,6 @@
+require "net/ssh"
require "thor"
module Dogids
class Cli < Thor
desc "reload", "Reloads the specified machine. Defaults to development"
@@ -7,12 +8,19 @@
# TODO add environments
# @param [string] app_name
def reload(app_name = nil)
if yes?("-----> Reload development? [no]")
reload_development_machine
+ elsif yes?("-----> Restart LAMP stack? [no]")
+ ssh_address = get_config_url("dev","dev")
+ restart_lamp(ssh_address, "dogids")
+ elsif yes?("-----> Restart LB and LAMP stack? [no]")
+ restart_all
+ elsif yes?("-----> Update Vagrant Box? (NOT RECOMMENDED) [no]")
+ update_vagrant_box
else
- update_vagrant_box if yes?("-----> Update Vagrant Box? (NOT RECOMMENDED) [no]")
+ say("Fine, I didn't want you to do anything anyway.")
end
end
no_commands do
@@ -32,8 +40,35 @@
def reload_development_machine
say("-----> Reloading the development machine...","\e[32m")
system("cd ~/dogids-vagrant && vagrant reload")
end
+ # Restarts HAProxy, Apache, HHVM, and MySQL
+ def restart_all
+ dev_machines = get_config_url("dev")
+ dev_machines.each do |key,dev_machine|
+ ssh_address = get_config_url("dev",dev_machine)
+ lamp_restart_command(dev_machine, "dogids") if dev_machine == dev
+ lb_restart_command(dev_machine, "dogids") if dev_machine == lb
+ end
+ end
+
+ def restart_lamp(ssh_address,user)
+ Net::SSH.start(ssh_address, "dogids") do |ssh|
+ lamp_restart_command = "sudo service apache2 restart && sudo service hhvm restart && sudo service mysql restart"
+ ssh.exec!(lamp_restart_command) do |_channel, _stream, data|
+ print_command(data)
+ end
+ end
+ end
+
+ def restart_lb(ssh_address,user)
+ Net::SSH.start(ssh_address, "dogids") do |ssh|
+ lb_restart_command = "sudo service haproxy restart"
+ ssh.exec!(lb_restart_command) do |_channel, _stream, data|
+ print_command(data)
+ end
+ end
+ end
end
end
end