Sha256: cd733d092c8335e37e548e568ec2fec4031aa80e11ee208fe6f8d3d8e366739b

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

#!/usr/bin/ruby
require 'rubygems'
require 'optparse'
require 'poolparty'
require "fileutils"

# Set defaults
commandables = %w(ssh cmd scp restart start stop install start_maintain stop_maintain)
options = PoolParty.options(:optsparse => 
  { :banner => <<-EOU
Usage: instance [OPTIONS] { #{commandables.join(" | ")} }
-----------------------------------------------------------------
    EOU
    })
PoolParty.load_plugins
master = PoolParty::Master.new
list = PoolParty::Optioner.parse(ARGV.dup, %w(-v))
num = list.reject {|a| commandables.include?(a) }.pop

instance = master.get_node(num)

unless instance
  puts "Cloud is not running"
  exit
end

case list[0]
when "ssh"
  PoolParty.message "Ssh'ing into #{instance.ip}"
  instance.ssh
when "cmd"
  PoolParty.message "Executing #{instance_options[:cmd]} on #{instance.ip}"
  instance.ssh instance_options[:cmd]
when "scp"
  instance.scp instance_options[:src], instance_options[:dest]
when "restart"
  PoolParty.message "Restarting services"
  instance.restart_with_monit
when "start"
  PoolParty.message "Starting services"
  instance.start_with_monit
when "stop"
  PoolParty.message "Stopping services"
  instance.stop_with_monit
when "install"
  PoolParty.message "Installing services"
  instance.install
when "start_maintain"
  PoolParty.message "Running heartbeat failover service"
  pid = Master.run_thread_loop(:daemonize => true) do
    instance.become_master if instance.is_not_master_and_master_is_not_running?
  end
  File.open(Application.maintain_pid_path) {|f| f.write(pid)}
when "stop_maintain"
  PoolParty.message "Stopping heartbeat failover service"
  pid = open(Application.maintain_pid_path).read
  `kill -9 #{pid}`
  FileUtils.rm Application.maintain_pid_path # Check this
else
  puts master.list
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
auser-poolparty-0.0.8 bin/instance
dreadpiratepj-poolparty-0.0.8 bin/instance