Module: BlackStack::Deployer::NodeModule

Includes:
Infrastructure::NodeModule
Included in:
Node
Defined in:
lib/my-ruby-deployer.rb

Overview

inherit BlackStack::Infrastructure::NodeModule, including features of deployer.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deployment_routineObject

Returns the value of attribute deployment_routine.



25
26
27
# File 'lib/my-ruby-deployer.rb', line 25

def deployment_routine
  @deployment_routine
end

#parametersObject

Returns the value of attribute parameters.



25
26
27
# File 'lib/my-ruby-deployer.rb', line 25

def parameters
  @parameters
end

Class Method Details

.descriptor_errors(h) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/my-ruby-deployer.rb', line 53

def self.descriptor_errors(h)
  errors = BlackStack::Infrastructure::NodeModule.descriptor_errors(h)
 
  # validate: does not exist any other element in @@nodes with the same value for the parameter h[:name]
  errors << "The parameter h[:name] is not unique" if BlackStack::Deployer.nodes.select{|n| n.name == h[:name]}.length > 0 

  # validate: h[:deployment_routine] is not nil
  errors << "The parameter h[:deployment_routine] is required" if h[:deployment_routine].nil?

  # validate: h[:deployment_routine] is a string
  # This value is no longer mandatory
  #errors << "The parameter h[:deployment_routine] is not a string" unless h[:deployment_routine].is_a?(String)
  
  # return list of errors
  errors.uniq
end

.eth0_ip(insterface) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/my-ruby-deployer.rb', line 29

def self.eth0_ip(insterface)
  ret = nil
  a = `ip addr show dev #{insterface}`.scan(/inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)
  if a.size > 0
    ret = a.last.to_s.gsub(/inet /, '')           
  else
    raise "Cannot get ip address of the interface #{insterface}"
  end
  ret
end

Instance Method Details

#deploy(routine_name = nil, l = nil) ⇒ Object

def to_hash



84
85
86
87
88
# File 'lib/my-ruby-deployer.rb', line 84

def deploy(routine_name=nil, l=nil)
  l = BlackStack::DummyLogger.new(nil) if l.nil?
  s = routine_name || self.deployment_routine
  BlackStack::Deployer::run_routine(self.name, s, l);
end

#eth0_ipObject

get the IP address for an interface using the ip addr command. this is a helper method for installing cockroachdb nodes.



42
43
44
45
46
47
48
49
50
51
# File 'lib/my-ruby-deployer.rb', line 42

def eth0_ip()
  ret = nil
  a = self.ssh.exec!("ip addr show dev #{parameters[:laninterface]}").scan(/inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)
  if a.size > 0
    ret = a.last.to_s.gsub(/inet /, '')           
  else
    raise "Cannot get ip address of the interface #{parameters[:laninterface]}"
  end
  ret
end

#initialize(h, i_logger = nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/my-ruby-deployer.rb', line 70

def initialize(h, i_logger=nil)
  self.parameters = h
  errors = BlackStack::Deployer::NodeModule.descriptor_errors(h)
  raise "The node descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0
  super(h, i_logger)
  self.deployment_routine = h[:deployment_routine]
end

#start(output_file = '~/deployment.log') ⇒ Object

execute all the processes who run in this node



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/my-ruby-deployer.rb', line 106

def start(output_file='~/deployment.log')
  s = '
    echo "" >>'+output_file+' 2>&1
    echo "-------------------------------------------------------------------------" >>'+output_file+' 2>&1
    echo "Starting at: `date`" >>'+output_file+' 2>&1

    # Activate RVM
    echo ""
    echo "Activating RVM..." >>'+output_file+' 2>&1      
    source /etc/profile.d/rvm.sh >>'+output_file+' 2>&1
    
    # Activate Ruby 3.1.2
    echo ""
    echo "Activate Ruby 3.1.2..." >>'+output_file+' 2>&1       
    rvm --default use 3.1.2 >>'+output_file+' 2>&1
    
    # Set RUBYLIB
    echo ""
    echo "Set RUBYLIB..." >>'+output_file+' 2>&1     
    export RUBYLIB='+self.parameters[:rubylib]+' >>'+output_file+' 2>&1
    
    # Change directory to RUBYLIB
    echo ""
    echo "Change directory to RUBYLIB..." >>'+output_file+' 2>&1      
    cd $RUBYLIB >>'+output_file+' 2>&1'

  self.parameters[:processes].each { |p|
    s += '
    # Change directory to RUBYLIB
    echo ""
    echo "Run '+p+'..." >>'+output_file+' 2>&1       
    ruby $RUBYLIB/'+p+' 2>>'+output_file+' 1>>/dev/null &
  '
  }
  
  self.ssh.exec!(s)
end

#stop(output_file = '~/deployment.log') ⇒ Object

stop all the processes who run in this node



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/my-ruby-deployer.rb', line 91

def stop(output_file='~/deployment.log')
  s = '
    echo "" >>'+output_file+' 2>&1
    echo "-------------------------------------------------------------------------" >>'+output_file+' 2>&1
    echo "Stopping at: `date`" >>'+output_file+' 2>&1

    # Activate RVM
    echo ""
    echo "Killing processes '+self.parameters[:code_folder]+'..." >>'+output_file+' 2>&1      
    ps ax | grep "'+self.parameters[:code_folder]+'" | grep -v postgres | grep -v grep | cut -b1-7 | xargs -t kill -9 >>'+output_file+' 2>&1
  '
  self.ssh.exec!(s)
end

#to_hashObject

def self.create(h)



78
79
80
81
82
# File 'lib/my-ruby-deployer.rb', line 78

def to_hash
  h = super
  h[:deployment_routine] = self.deployment_routine
  h
end