Class: PoolParty::Resources::Hermes

Inherits:
PoolParty::Resource show all
Defined in:
lib/poolparty/plugins/hermes.rb

Instance Attribute Summary

Attributes inherited from PoolParty::Resource

#exists, #graph_index, #meta_not_if, #meta_notifies, #meta_only_if, #meta_subscribes

Attributes inherited from Base

#base_name, #init_opts

Instance Method Summary collapse

Methods inherited from PoolParty::Resource

#after_loaded_requires_parent, #before_compile, #case_of, #cloud, #compile, define_resource, define_resource_methods, defined, defined_resources, #does_not_exist!, #exists!, #has_method_name, has_method_name, inherited, #initialize, is_base_resource_class?, method_defined!, method_defined?, #not_if, #notifies, #only_if, #pool, #print_to_chef, #print_variable, #requires, #subscribes

Methods inherited from Base

#add_ordered_resources_to_result, #all_resources, #before_load, #clouds_dot_rb_dir, clouds_dot_rb_dir, #clouds_dot_rb_file, clouds_dot_rb_file, #compile_opts, #create_graph, #dependencies, #get_resource, #has_searchable_paths, #initialize, #method_missing, #ordered_resources, #output_resources_graph, #resources, #resources_graph, #resources_with_dependencies, #resources_without_dependencies, #run_in_context, #run_with_callbacks, #to_s, #valid?, #validations

Methods included from Delayed

included

Methods included from Callbacks

included

Methods included from SearchablePaths

included

Constructor Details

This class inherits a constructor from PoolParty::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PoolParty::Base

Instance Method Details

#add_unpackObject



56
57
58
59
60
61
62
63
64
# File 'lib/poolparty/plugins/hermes.rb', line 56

def add_unpack
  has_exec "install_hermes",
    :command => "cd /tmp/hermes && escript target_system install hermes-#{hermes_release_version} #{remote_hermes_deployed_dir}", 
    :creates => "#{remote_hermes_deployed_dir}/releases/#{hermes_release_version}",
    :requires => get_package("erlang-dev")
    
  has_link  :name => "collectd_dir", 
            :to => "/var/lib/collectd/rrd/\#{`hostname -f`.chomp}", :source => "/var/lib/collectd/localhost"
end

#after_compileObject



21
22
# File 'lib/poolparty/plugins/hermes.rb', line 21

def after_compile
end

#after_loadedObject



13
14
15
16
17
18
19
# File 'lib/poolparty/plugins/hermes.rb', line 13

def after_loaded
  run_dependencies
  build_rsync_directory
  add_unpack
  run_dependencies
  run_if_needed
end

#build_nodes_configObject

write out a conf file listing all of the seed nodes based on the nodes in the cluster



48
49
50
51
52
53
54
# File 'lib/poolparty/plugins/hermes.rb', line 48

def build_nodes_config
  etc_poolparty = cloud.tmp_path + "/etc/poolparty"
  FileUtils.mkdir_p(etc_poolparty)
  node_names = cloud.nodes.collect{|n| n.internal_ip || n.dns_name}.compact.collect{|n| "hermes@#{n}"}
  contents = node_names.collect{|n| %Q{'#{n}'.}}.join("\n")
  File.open(etc_poolparty + "/seeds.conf", "w") {|f| f.puts contents}
end

#build_rsync_directoryObject



39
40
41
42
43
44
45
# File 'lib/poolparty/plugins/hermes.rb', line 39

def build_rsync_directory
  hermes_dir = cloud.tmp_path + "/tmp/hermes"
  FileUtils.mkdir_p(hermes_dir)
  FileUtils.cp(hermes_release_tar_gz, hermes_dir)
  FileUtils.cp(target_system_file, hermes_dir)
  build_nodes_config
end

#run_dependenciesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/poolparty/plugins/hermes.rb', line 24

def run_dependencies
  install_packages = case cloud.platform
  when false
  else
    ["erlang-nox", "erlang-dev"]
  end
  has_package "rrdtool"
  has_exec "install_erlang" do
    command "echo ''"
    install_packages.each do |pkg|
      has_package pkg
    end
  end
end

#run_if_neededObject



66
67
68
69
70
# File 'lib/poolparty/plugins/hermes.rb', line 66

def run_if_needed
  has_exec "env GEN_CLUSTER_SEED_CONFIG=/etc/poolparty/seeds.conf HERMES_RRD_DIRECTORY=/var/lib/collectd/localhost #{remote_hermes_deployed_dir}/bin/erl -boot #{remote_hermes_deployed_dir}/releases/#{hermes_release_version}/start -noshell -detached", 
    :not_if => "ps aux | grep -v grep | grep hermes | grep beam",
    :requires => [get_exec("install_hermes")]
end