Class: PoolParty::RemoteInstance
- Includes:
- PoolParty, Callbacks, FileWriter, Remoter
- Defined in:
- lib/poolparty/remote_instance.rb
Instance Attribute Summary collapse
-
#configure_file ⇒ Object
Returns the value of attribute configure_file.
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#keypair ⇒ Object
Returns the value of attribute keypair.
-
#launching_time ⇒ Object
readonly
Returns the value of attribute launching_time.
-
#name ⇒ Object
Internal naming scheme.
-
#number ⇒ Object
Returns the value of attribute number.
-
#plugin_string ⇒ Object
Returns the value of attribute plugin_string.
-
#scp_configure_file ⇒ Object
Returns the value of attribute scp_configure_file.
-
#stack_installed ⇒ Object
readonly
Returns the value of attribute stack_installed.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#associate_public_ip(c) ⇒ Object
Associate a public ip if it is set and this is the master.
- #base_install_script ⇒ Object
-
#become_master ⇒ Object
Become the new master.
- #change_hostname ⇒ Object
-
#conf_file(name) ⇒ Object
User conf file if it exists, or default one.
-
#configure ⇒ Object
Placeholder.
- #configure_authkeys ⇒ Object
- #configure_heartbeat ⇒ Object
- #configure_master ⇒ Object
- #configure_resource_d ⇒ Object
- #configure_tasks(quiet = true) ⇒ Object
-
#description ⇒ Object
Description in the rake task.
-
#haproxy_entry ⇒ Object
Entry for haproxy.
- #haproxy_resources_entry ⇒ Object
-
#heartbeat_entry ⇒ Object
Entry for the heartbeat config file.
-
#hosts_entry ⇒ Object
Host entry for this instance.
- #if_dir_exists(dir, dothis) ⇒ Object
- #if_exists(file, dothis) ⇒ Object
-
#initialize(obj = {}) ⇒ RemoteInstance
constructor
A new instance of RemoteInstance.
-
#install ⇒ Object
Installs with one commandline and an scp, rather than 10.
-
#is_not_master_and_master_is_not_running? ⇒ Boolean
Is this the master and if not, is the master running?.
-
#local_hosts_entry ⇒ Object
Internal host entry for this instance.
-
#login_once ⇒ Object
Login to store the authenticity.
- #mark_installed(caller = nil) ⇒ Object
-
#master? ⇒ Boolean
Is this the master?.
- #mount_s3_drive ⇒ Object
- #move_config_file ⇒ Object
- #move_node_list ⇒ Object
-
#node_entry ⇒ Object
Node entry for heartbeat.
- #node_list_name ⇒ Object
- #secondary? ⇒ Boolean
- #set_hosts(c) ⇒ Object
- #setup_haproxy ⇒ Object
-
#setup_pems ⇒ Object
def configure_monit <<-EOC mv #FileWriter#remote_base_tmp_dir/monitrc /etc/monit/monitrc mkdir -p /etc/monit.d/ mv #FileWriter#remote_base_tmp_dir/monit.d/* /etc/monit.d/ chown #Application.username /etc/monit/monitrc chmod 700 /etc/monit/monitrc EOC end.
- #stack_installed? ⇒ Boolean
- #update_plugin_string ⇒ Object
-
#user_tasks ⇒ Object
.map {|k,v| {k.to_sym => v.nice_runnable(quiet)} }.inject({}) {|a,s| s.merge(a) }.
Methods included from FileWriter
#base_tmp_dir, #clear_base_directory, #make_base_directory, #remote_base_tmp_dir, #with_temp_file, #write_to_file_for, #write_to_temp_file
Methods included from Callbacks
Methods included from PoolParty
#include_cloud_tasks, #load_app, #load_monitors, #load_plugins, #message, #options, #plugin_dir, #read_config_file, #register_monitor, #registered_monitor?, #registered_monitors, #reset!, #root_dir, #timer, #user_dir, #verbose?, #write_to_temp_file
Methods included from Remoter
Constructor Details
#initialize(obj = {}) ⇒ RemoteInstance
Returns a new instance of RemoteInstance.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/poolparty/remote_instance.rb', line 16 def initialize(obj={}) super @ip = obj[:ip] @instance_id = obj[:instance_id] @name = obj[:name] || "node" @number = obj[:number] || 0 # Defaults to the master @status = obj[:status] || "running" @launching_time = obj[:launching_time] || Time.now @keypair = obj[:keypair] || Application.keypair rescue "" end |
Instance Attribute Details
#configure_file ⇒ Object
Returns the value of attribute configure_file.
11 12 13 |
# File 'lib/poolparty/remote_instance.rb', line 11 def configure_file @configure_file end |
#instance_id ⇒ Object (readonly)
Returns the value of attribute instance_id.
10 11 12 |
# File 'lib/poolparty/remote_instance.rb', line 10 def instance_id @instance_id end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
10 11 12 |
# File 'lib/poolparty/remote_instance.rb', line 10 def ip @ip end |
#keypair ⇒ Object
Returns the value of attribute keypair.
10 11 12 |
# File 'lib/poolparty/remote_instance.rb', line 10 def keypair @keypair end |
#launching_time ⇒ Object (readonly)
Returns the value of attribute launching_time.
10 11 12 |
# File 'lib/poolparty/remote_instance.rb', line 10 def launching_time @launching_time end |
#name ⇒ Object
Internal naming scheme
41 42 43 |
# File 'lib/poolparty/remote_instance.rb', line 41 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
11 12 13 |
# File 'lib/poolparty/remote_instance.rb', line 11 def number @number end |
#plugin_string ⇒ Object
Returns the value of attribute plugin_string.
11 12 13 |
# File 'lib/poolparty/remote_instance.rb', line 11 def plugin_string @plugin_string end |
#scp_configure_file ⇒ Object
Returns the value of attribute scp_configure_file.
11 12 13 |
# File 'lib/poolparty/remote_instance.rb', line 11 def scp_configure_file @scp_configure_file end |
#stack_installed ⇒ Object (readonly)
Returns the value of attribute stack_installed.
10 11 12 |
# File 'lib/poolparty/remote_instance.rb', line 10 def stack_installed @stack_installed end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/poolparty/remote_instance.rb', line 10 def status @status end |
Class Method Details
.node_list_name ⇒ Object
179 180 181 |
# File 'lib/poolparty/remote_instance.rb', line 179 def self.node_list_name "nodes.lst" end |
Instance Method Details
#associate_public_ip(c) ⇒ Object
Associate a public ip if it is set and this is the master
190 191 192 |
# File 'lib/poolparty/remote_instance.rb', line 190 def associate_public_ip(c) associate_address_with(Application.public_ip, @instance_id) if master? && Application.public_ip && !Application.public_ip.empty? end |
#base_install_script ⇒ Object
246 247 248 |
# File 'lib/poolparty/remote_instance.rb', line 246 def base_install_script "#{root_dir}/config/installers/#{Application.os.downcase}_install.sh" end |
#become_master ⇒ Object
Become the new master
194 195 196 197 198 199 200 |
# File 'lib/poolparty/remote_instance.rb', line 194 def become_master @master = Master.new @number = 0 @master.nodes[0] = self @master.configure_cloud configure end |
#change_hostname ⇒ Object
145 146 147 148 149 150 |
# File 'lib/poolparty/remote_instance.rb', line 145 def change_hostname <<-EOC #{if_exists "#{name}-hosts", "mv #{remote_base_tmp_dir}/#{name}-hosts /etc/hosts"} hostname -v #{name} EOC end |
#conf_file(name) ⇒ Object
User conf file if it exists, or default one
220 221 222 223 224 225 226 227 |
# File 'lib/poolparty/remote_instance.rb', line 220 def conf_file(name) user_conf = File.join(PoolParty.user_dir, "config", name) if File.file?(user_conf) File.join(PoolParty.user_dir, "config", name) else File.join(PoolParty.root_dir, "config", name) end end |
#configure ⇒ Object
Placeholder
202 203 |
# File 'lib/poolparty/remote_instance.rb', line 202 def configure end |
#configure_authkeys ⇒ Object
103 104 105 106 107 108 |
# File 'lib/poolparty/remote_instance.rb', line 103 def configure_authkeys <<-EOC mkdir -p /etc/ha.d #{if_exists "authkeys", "mv #{remote_base_tmp_dir}/authkeys /etc/ha.d/"} EOC end |
#configure_heartbeat ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/poolparty/remote_instance.rb', line 96 def configure_heartbeat cmd=<<-EOC mv #{remote_base_tmp_dir}/ha.cf /etc/ha.d/ha.cf /etc/init.d/heartbeat start EOC Master.requires_heartbeat? ? cmd : "" end |
#configure_master ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/poolparty/remote_instance.rb', line 110 def configure_master if master? <<-EOC pool maintain -c ~/.config -l ~/plugins EOC else "" end end |
#configure_resource_d ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/poolparty/remote_instance.rb', line 120 def configure_resource_d <<-EOC mkdir -p /etc/ha.d/resource.d/ #{if_exists "cloud_master_takeover", "mv #{remote_base_tmp_dir}/cloud_master_takeover /etc/ha.d/resource.d"} #{if_dir_exists "resource.d/", "mv #{remote_base_tmp_dir}/resource.d/* /etc/ha.d/resource.d"} EOC end |
#configure_tasks(quiet = true) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/poolparty/remote_instance.rb', line 70 def configure_tasks(quiet=true) { :setup_pems => setup_pems, :move_hostfile => change_hostname, :config_master => configure_master, :move_config_file => move_config_file, :mount_s3_drive => mount_s3_drive, :update_plugins => update_plugin_string, :configure_authkeys => configure_authkeys, :configure_resource_d => configure_resource_d, :configure_haproxy => setup_haproxy, :configure_heartbeat => configure_heartbeat, :user_tasks => user_tasks, :node_list => move_node_list }#.map {|k,v| {k.to_sym => v.nice_runnable(quiet)} }.inject({}) {|a,s| s.merge(a) } end |
#description ⇒ Object
Description in the rake task
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/poolparty/remote_instance.rb', line 229 def description case @status when "running" "#{@number}: INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}" when "shutting-down" "(terminating) INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}" when "pending" "(booting) INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}" end end |
#haproxy_entry ⇒ Object
Entry for haproxy
49 50 51 |
# File 'lib/poolparty/remote_instance.rb', line 49 def haproxy_entry "\tserver #{name} #{@ip}:#{Application.client_port} weight 1 minconn 3 maxconn 6 check inter 20000 check" end |
#haproxy_resources_entry ⇒ Object
52 53 54 |
# File 'lib/poolparty/remote_instance.rb', line 52 def haproxy_resources_entry "#{name} #{@ip}" end |
#heartbeat_entry ⇒ Object
Entry for the heartbeat config file
45 46 47 |
# File 'lib/poolparty/remote_instance.rb', line 45 def heartbeat_entry "#{name} #{ip} #{Application.managed_services}" end |
#hosts_entry ⇒ Object
Host entry for this instance
29 30 31 |
# File 'lib/poolparty/remote_instance.rb', line 29 def hosts_entry "#{@ip} #{name}" end |
#if_dir_exists(dir, dothis) ⇒ Object
212 213 214 |
# File 'lib/poolparty/remote_instance.rb', line 212 def if_dir_exists(dir, dothis) "if [ -d #{remote_base_tmp_dir}/#{dir} ]; then #{dothis}; fi" end |
#if_exists(file, dothis) ⇒ Object
209 210 211 |
# File 'lib/poolparty/remote_instance.rb', line 209 def if_exists(file, dothis) "if [ -f #{remote_base_tmp_dir}/#{file} ]; then #{dothis}; fi" end |
#install ⇒ Object
Installs with one commandline and an scp, rather than 10
183 184 |
# File 'lib/poolparty/remote_instance.rb', line 183 def install end |
#is_not_master_and_master_is_not_running? ⇒ Boolean
Is this the master and if not, is the master running?
216 217 218 |
# File 'lib/poolparty/remote_instance.rb', line 216 def is_not_master_and_master_is_not_running? !master? && !Master.is_master_responding? end |
#local_hosts_entry ⇒ Object
Internal host entry for this instance
33 34 35 |
# File 'lib/poolparty/remote_instance.rb', line 33 def local_hosts_entry "127.0.0.1 #{name}\n127.0.0.1 localhost.localdomain localhost ubuntu" end |
#login_once ⇒ Object
Login to store the authenticity
186 187 188 |
# File 'lib/poolparty/remote_instance.rb', line 186 def login_once run_now "ls -l" end |
#mark_installed(caller = nil) ⇒ Object
242 243 244 245 |
# File 'lib/poolparty/remote_instance.rb', line 242 def mark_installed(caller=nil) run_now("echo 'installed' > ~/.installed") @stack_installed = true end |
#master? ⇒ Boolean
Is this the master?
56 57 58 |
# File 'lib/poolparty/remote_instance.rb', line 56 def master? @number == 0 end |
#mount_s3_drive ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/poolparty/remote_instance.rb', line 162 def mount_s3_drive if Application.shared_bucket.empty? "" else <<-EOC mkdir -p /data && /usr/bin/s3fs #{Application.shared_bucket} -o accessKeyId=#{Application.access_key} -o secretAccessKey=#{Application.secret_access_key} -o nonempty /data EOC end end |
#move_config_file ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/poolparty/remote_instance.rb', line 89 def move_config_file <<-EOC #{if_exists "config.yml", "mv #{remote_base_tmp_dir}/config.yml ~/.config"} mkdir -p ~/.ec2 #{if_exists "keypair", "mv #{remote_base_tmp_dir}/keypair ~/.ec2/#{Application.keypair_name}"} EOC end |
#move_node_list ⇒ Object
171 172 173 174 175 |
# File 'lib/poolparty/remote_instance.rb', line 171 def move_node_list <<-EOC #{if_exists node_list_name, "mv #{remote_base_tmp_dir}/nodes.lst ~/.#{node_list_name}"} EOC end |
#node_entry ⇒ Object
Node entry for heartbeat
37 38 39 |
# File 'lib/poolparty/remote_instance.rb', line 37 def node_entry "node #{name}" end |
#node_list_name ⇒ Object
176 177 178 |
# File 'lib/poolparty/remote_instance.rb', line 176 def node_list_name self.class.node_list_name end |
#secondary? ⇒ Boolean
59 60 61 |
# File 'lib/poolparty/remote_instance.rb', line 59 def secondary? @number == 1 end |
#set_hosts(c) ⇒ Object
62 63 |
# File 'lib/poolparty/remote_instance.rb', line 62 def set_hosts(c) end |
#setup_haproxy ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'lib/poolparty/remote_instance.rb', line 152 def setup_haproxy <<-EOS mv #{remote_base_tmp_dir}/haproxy /etc/haproxy.cfg sed -i "s/ENABLED=0/ENABLED=1/g" /etc/default/haproxy sed -i 's/SYSLOGD=""/SYSLOGD="-r"/g' /etc/default/syslogd echo "local0.* /var/log/haproxy.log" >> /etc/syslog.conf && /etc/init.d/sysklogd restart /etc/init.d/haproxy restart EOS end |
#setup_pems ⇒ Object
def configure_monit
<<-EOC
mv #{remote_base_tmp_dir}/monitrc /etc/monit/monitrc
mkdir -p /etc/monit.d/
mv #{remote_base_tmp_dir}/monit.d/* /etc/monit.d/
chown #{Application.username} /etc/monit/monitrc
chmod 700 /etc/monit/monitrc
EOC
end
138 139 140 141 142 143 |
# File 'lib/poolparty/remote_instance.rb', line 138 def setup_pems <<-EOC #{if_exists "cert.pem", "mv #{remote_base_tmp_dir}/cert-*.pem #{Application.keypair_path}/cert-CLOUD.pem"} #{if_exists "pk.pem", "mv #{remote_base_tmp_dir}/pk-*.pem #{Application.keypair_path}/pk-CLOUD.pem"} EOC end |
#stack_installed? ⇒ Boolean
239 240 241 |
# File 'lib/poolparty/remote_instance.rb', line 239 def stack_installed? @stack_installed ||= run("cat ~/.installed") end |
#update_plugin_string ⇒ Object
204 205 206 207 208 |
# File 'lib/poolparty/remote_instance.rb', line 204 def update_plugin_string dir = File.basename(Application.plugin_dir) if_exists "plugins.tar.gz", "mkdir -p #{dir} && tar -zxf #{remote_base_tmp_dir}/plugins.tar.gz -C #{dir}" end |
#user_tasks ⇒ Object
.map {|k,v| {k.to_sym => v.nice_runnable(quiet)} }.inject({}) {|a,s| s.merge(a) }
86 87 88 |
# File 'lib/poolparty/remote_instance.rb', line 86 def user_tasks @@user_tasks ||= [] end |