my-ruby-deployer 1.3.2 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/my-ruby-deployer.rb +72 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c7008336f0a352aea0d52cd7ee276ce2a639c4e3050bb88e94b709382055a10
|
4
|
+
data.tar.gz: 961b17db58794b68f79c8c249eae314226e3dddfe7decb1dd5fab0ca85670c97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f79b6e018e37823038939f1b2d84cfd976a52d03715ffc61033c2608297817c98ca1e48544283e21b855985807c84193388f09e0033cb9c44ad9687cd42859af
|
7
|
+
data.tar.gz: c13af499354d8371e553f5de98f0b4a36903ced7aee4e52d52d6076f6360e1ea6fc092c1bf9c7b936e3b54874cdb6be4260ddc41cd9675ad8e3cdb3820f68c1c
|
data/lib/my-ruby-deployer.rb
CHANGED
@@ -86,6 +86,61 @@ module BlackStack
|
|
86
86
|
s = routine_name || self.deployment_routine
|
87
87
|
BlackStack::Deployer::run_routine(self.name, s, l);
|
88
88
|
end
|
89
|
+
|
90
|
+
# stop all the processes who run in this node
|
91
|
+
def stop(output_file='~/deployment.log')
|
92
|
+
s = '
|
93
|
+
echo "" >>'+output_file+' 2>&1
|
94
|
+
echo "-------------------------------------------------------------------------" >>'+output_file+' 2>&1
|
95
|
+
echo "Stopping at: `date`" >>'+output_file+' 2>&1
|
96
|
+
|
97
|
+
# Activate RVM
|
98
|
+
echo ""
|
99
|
+
echo "Killing processes '+self.parameters[:code_folder]+'..." >>'+output_file+' 2>&1
|
100
|
+
ps ax | grep "'+self.parameters[:code_folder]+'" | grep -v postgres | grep -v grep | cut -b1-7 | xargs -t kill -9 >>'+output_file+' 2>&1
|
101
|
+
'
|
102
|
+
self.ssh.exec!(s)
|
103
|
+
end
|
104
|
+
|
105
|
+
# execute all the processes who run in this node
|
106
|
+
def start(output_file='~/deployment.log')
|
107
|
+
s = '
|
108
|
+
echo "" >>'+output_file+' 2>&1
|
109
|
+
echo "-------------------------------------------------------------------------" >>'+output_file+' 2>&1
|
110
|
+
echo "Starting at: `date`" >>'+output_file+' 2>&1
|
111
|
+
|
112
|
+
# Activate RVM
|
113
|
+
echo ""
|
114
|
+
echo "Activating RVM..." >>'+output_file+' 2>&1
|
115
|
+
source /etc/profile.d/rvm.sh >>'+output_file+' 2>&1
|
116
|
+
|
117
|
+
# Activate Ruby 3.1.2
|
118
|
+
echo ""
|
119
|
+
echo "Activate Ruby 3.1.2..." >>'+output_file+' 2>&1
|
120
|
+
rvm --default use 3.1.2 >>'+output_file+' 2>&1
|
121
|
+
|
122
|
+
# Set RUBYLIB
|
123
|
+
echo ""
|
124
|
+
echo "Set RUBYLIB..." >>'+output_file+' 2>&1
|
125
|
+
export RUBYLIB='+self.parameters[:rubylib]+' >>'+output_file+' 2>&1
|
126
|
+
|
127
|
+
# Change directory to RUBYLIB
|
128
|
+
echo ""
|
129
|
+
echo "Change directory to RUBYLIB..." >>'+output_file+' 2>&1
|
130
|
+
cd $RUBYLIB >>'+output_file+' 2>&1'
|
131
|
+
|
132
|
+
self.parameters[:processes].each { |p|
|
133
|
+
s += '
|
134
|
+
# Change directory to RUBYLIB
|
135
|
+
echo ""
|
136
|
+
echo "Run '+p+'..." >>'+output_file+' 2>&1
|
137
|
+
ruby $RUBYLIB/'+p+' 2>>'+output_file+' 1>>/dev/null &
|
138
|
+
'
|
139
|
+
}
|
140
|
+
|
141
|
+
self.ssh.exec!(s)
|
142
|
+
end
|
143
|
+
|
89
144
|
end # module NodeModule
|
90
145
|
|
91
146
|
# define attributes and methods of a deployer routine
|
@@ -147,14 +202,14 @@ module BlackStack
|
|
147
202
|
h
|
148
203
|
end
|
149
204
|
|
150
|
-
def run(node, l=nil)
|
205
|
+
def run(node, l=nil, params={})
|
151
206
|
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
152
207
|
l.logs "Running routine #{self.name.blue} on node #{node.name.blue}... "
|
153
208
|
i = 0
|
154
209
|
self.commands.each do |c|
|
155
210
|
i += 1
|
156
211
|
l.logs "Command #{i.to_s.blue}... "
|
157
|
-
c.run(node, l)
|
212
|
+
c.run(node, l, params)
|
158
213
|
l.logf 'done'.green
|
159
214
|
end
|
160
215
|
l.logf 'done'.green
|
@@ -210,7 +265,7 @@ module BlackStack
|
|
210
265
|
# running pre-defined commands: :root
|
211
266
|
# calling to other routines: :'change-name'
|
212
267
|
# calling
|
213
|
-
def run(n, l=nil)
|
268
|
+
def run(n, l=nil, params={})
|
214
269
|
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
215
270
|
|
216
271
|
# if self.command is a symbol
|
@@ -224,7 +279,7 @@ module BlackStack
|
|
224
279
|
# look for a routine with this name
|
225
280
|
r = BlackStack::Deployer.routines.select { |r| r.name == self.command.to_s }.first
|
226
281
|
if !r.nil?
|
227
|
-
r.run(n)
|
282
|
+
r.run(n, l, params)
|
228
283
|
else
|
229
284
|
raise "The routine #{self.command.to_s} does not exist"
|
230
285
|
end
|
@@ -234,22 +289,26 @@ module BlackStack
|
|
234
289
|
elsif self.command.is_a?(String)
|
235
290
|
s = self.command.dup
|
236
291
|
|
237
|
-
l.logs "Replacing merge-tags... "
|
292
|
+
#l.logs "Replacing merge-tags... "
|
238
293
|
s.scan(/%[a-zA-Z0-9\_]+%/).uniq.each do |p|
|
239
|
-
l.logs "Replacing #{p.blue}... "
|
294
|
+
#l.logs "Replacing #{p.blue}... "
|
240
295
|
if p == '%timestamp%' # reserved parameter
|
241
296
|
# TODO: move this to a timestamp function on blackstack-core
|
242
297
|
s.gsub!(p, Time.now.to_s.gsub(/\D/, ''))
|
243
298
|
else
|
299
|
+
# replace node parameters
|
244
300
|
if n.parameters.has_key?(p.gsub(/%/, '').to_sym)
|
245
301
|
s.gsub!(p, n.parameters[p.gsub(/%/, '').to_sym].to_s)
|
302
|
+
# replace routine-call parameters
|
303
|
+
elsif params.has_key?(p.gsub(/%/, '').to_sym)
|
304
|
+
s.gsub!(p, params[p.gsub(/%/, '').to_sym].to_s)
|
246
305
|
else
|
247
306
|
raise "The parameter #{p} does not exist in the node descriptor #{n.parameters.to_s}"
|
248
307
|
end
|
249
308
|
end
|
250
|
-
l.logf 'done'.green
|
309
|
+
#l.logf 'done'.green
|
251
310
|
end
|
252
|
-
l.logf 'done'.green
|
311
|
+
#l.logf 'done'.green
|
253
312
|
|
254
313
|
l.logs "Running command... "
|
255
314
|
n.ssh.exec!(s)
|
@@ -318,7 +377,7 @@ module BlackStack
|
|
318
377
|
end # def
|
319
378
|
|
320
379
|
# running a routine on a node
|
321
|
-
def self.run_routine(node_name, routine_name, l=nil)
|
380
|
+
def self.run_routine(node_name, routine_name, l=nil, params={})
|
322
381
|
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
323
382
|
errors = []
|
324
383
|
|
@@ -344,7 +403,7 @@ module BlackStack
|
|
344
403
|
|
345
404
|
# run the routine
|
346
405
|
l.logs "Running routine #{r.name}... "
|
347
|
-
r.run(n, l)
|
406
|
+
r.run(n, l, params)
|
348
407
|
l.done
|
349
408
|
|
350
409
|
# disconnect the node
|
@@ -354,7 +413,7 @@ module BlackStack
|
|
354
413
|
end # def self.run_routine
|
355
414
|
|
356
415
|
module DB
|
357
|
-
LOCKFILE = './
|
416
|
+
LOCKFILE = './my-ruby-deployer.lock'
|
358
417
|
@@checkpoint = nil
|
359
418
|
@@superhuser = nil
|
360
419
|
@@ndb = nil
|
@@ -418,7 +477,7 @@ module BlackStack
|
|
418
477
|
# This method should not be called directly by user code.
|
419
478
|
def self.execute_sentences(sql, chunk_size=200, l=nil)
|
420
479
|
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
421
|
-
|
480
|
+
|
422
481
|
# Fix issue: Ruby `split': invalid byte sequence in UTF-8 (ArgumentError)
|
423
482
|
# Reference: https://stackoverflow.com/questions/11065962/ruby-split-invalid-byte-sequence-in-utf-8-argumenterror
|
424
483
|
#
|
@@ -462,6 +521,7 @@ module BlackStack
|
|
462
521
|
def self.deploy(save_checkpoints=false, lockfilename=BlackStack::Deployer::DB::LOCKFILE, l=nil)
|
463
522
|
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
464
523
|
# get list of `.sql` files in the directory `sql_path`, with a name higher than `last_filename`, sorted by name.
|
524
|
+
|
465
525
|
Dir.entries(@@folder).select {
|
466
526
|
|filename| filename =~ /\.sql$/ && filename > @@checkpoint.to_s
|
467
527
|
}.uniq.sort.each { |filename|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my-ruby-deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blackstack-nodes
|