dolphin 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dolphin.rb +28 -77
  3. data/lib/dolphin/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd0208f9074f8be9502f8e03836774c861c49943
4
- data.tar.gz: 1aad911df6b5328bab43b6857affc253fbd30298
3
+ metadata.gz: 96307e5f4700eaa30d22be8103a85ddcf32c8132
4
+ data.tar.gz: fc210b44ca75f5683e537f271063a15a373bca0a
5
5
  SHA512:
6
- metadata.gz: 9559dddc9db2798166616886a03539314f95b129937e62ad3b625bac89abc24c1884adfdab208dc5cffb3fd5319363e9d0a42967efe89f2e3dc48ea84edefdc2
7
- data.tar.gz: 468e2df8516c91badb5ceccb9fe504d49087ab7906905381c13f9529c265f8d5594af0f170903022c00950f284d4fb006593443741633f69ed894726afdf8d81
6
+ metadata.gz: 546c32db70818adbf42cc99a2959d6613a5bfd354ce052040e12e8818a1a885fd521bdff61491718aa8752184c4d03a2cd5bdf41012369e01cb5f21d5e7ad8c5
7
+ data.tar.gz: 7ae901e6f2bda4e7c9e546c7902fbd3aabdcdce0efaba45f60e2b7d67e862a873f631e5df601b57c60991c6cff4dd418f31e29a6cc97a79eca247287cc83a7e3
data/lib/dolphin.rb CHANGED
@@ -33,25 +33,21 @@ module Dolphin
33
33
 
34
34
  end
35
35
 
36
- def parse_commands(menu, join=false)
36
+ def parse_commands(menu)
37
37
  # Helper method to parse a list of text menu of possible commands,
38
38
  # which may contain empty lines or commented out with #
39
- # commands from one menu item will be joined into one command
39
+ # commands can be separated into groups
40
40
 
41
41
  commands = []
42
- menu.each do |item|
42
+ menu.each do |group|
43
43
  buffer = []
44
- item.split(/\r?\n/).each do |line|
44
+ group.split(/\r?\n/).each do |line|
45
45
  line = line.strip
46
46
  unless line.empty? or line.start_with?('#') # empty or commented out
47
47
  buffer << line
48
48
  end
49
49
  end
50
- if join
51
- commands << buffer.join('; ')
52
- else
53
- commands.push(*buffer)
54
- end
50
+ commands.push(*buffer)
55
51
  end
56
52
  commands
57
53
  end
@@ -64,54 +60,7 @@ module Dolphin
64
60
  end
65
61
  end
66
62
 
67
- def ssh_exec(command, &block)
68
- status = nil
69
- output = ''
70
-
71
- channel = ssh_connection.open_channel do |chan|
72
- chan.exec(command) do |ch, success|
73
- puts "#{'!'*10} command failed: #{command}" unless success
74
- # ch.request_pty
75
-
76
- ch.on_data do |c, data|
77
- output << data
78
- yield(c, :stdout, data)
79
- end
80
-
81
- ch.on_extended_data do |c, type, data|
82
- output << data
83
- yield(c, :stderr, data)
84
- end
85
-
86
- ch.on_request "exit-status" do |c, data|
87
- status = data.read_long
88
- end
89
- end
90
- end
91
-
92
- channel.wait
93
- [status, output]
94
- end
95
-
96
63
  def execute(menu)
97
- # execute commands defined in menu
98
- commands = parse_commands(menu, true)
99
-
100
- puts "Executing on [#{@host}]"
101
- commands.each do |command|
102
- puts "\n#{'='*60}\n#{command}\n...... =>\n\n"
103
-
104
- status, output = ssh_exec command do |ch, stream, data|
105
- case stream
106
- when :stdout then $stdout.print data
107
- when :stderr then $stderr.print data
108
- end
109
- ch.send_data(askpass) if data =~ /^sudo password: /
110
- end
111
- end
112
- end
113
-
114
- def run(menu)
115
64
  # execute commands defined in menu
116
65
  commands = parse_commands(menu)
117
66
  puts "#{'*'*10}Executing commands#{'*'*10}\n"
@@ -120,14 +69,14 @@ module Dolphin
120
69
  end
121
70
  puts "#{'='*60}\n"
122
71
 
123
- # use Parallel to run commands on multiple servers in parallel
72
+ # use Parallel to execute commands on multiple servers in parallel
124
73
  tracks = @servers.size
125
74
  # 3 threads maximum
126
75
  tracks = 3 if tracks > 3
127
76
  # record output to display at the end
128
77
  output = {}
129
78
 
130
- Parallel.map(@servers, in_threads: 3) do |server|
79
+ Parallel.map(@servers, in_threads: tracks) do |server|
131
80
  session = ssh_connection(server)
132
81
  output[server] = [] # output from this server
133
82
 
@@ -198,10 +147,12 @@ module Dolphin
198
147
  def chruby
199
148
  menu = [
200
149
  "
201
- # install chruby
202
- wget -O chruby-0.3.5.tar.gz https://github.com/postmodern/chruby/archive/v0.3.5.tar.gz
203
- tar -xzvf chruby-0.3.5.tar.gz
204
- cd chruby-0.3.5/
150
+ # git clone
151
+ if [ ! -d 'chruby' ]; then git clone https://github.com/postmodern/chruby.git ; fi
152
+ # checkout tag
153
+ cd chruby
154
+ git checkout v0.3.5
155
+ # install
205
156
  sudo make install
206
157
  ",
207
158
  ]
@@ -267,7 +218,7 @@ module Dolphin
267
218
  ",
268
219
  ]
269
220
 
270
- run menu
221
+ execute menu
271
222
  end
272
223
 
273
224
  desc "rvm", "remove rvm"
@@ -279,7 +230,7 @@ module Dolphin
279
230
  ",
280
231
  ]
281
232
 
282
- run menu
233
+ execute menu
283
234
  end
284
235
 
285
236
  desc "apache", "remove apache"
@@ -292,7 +243,7 @@ module Dolphin
292
243
  ",
293
244
  ]
294
245
 
295
- run menu
246
+ execute menu
296
247
  end
297
248
 
298
249
  desc "git", "install latest git"
@@ -318,7 +269,7 @@ module Dolphin
318
269
  ",
319
270
  ]
320
271
 
321
- run menu
272
+ execute menu
322
273
  end
323
274
 
324
275
  end
@@ -342,7 +293,7 @@ module Dolphin
342
293
  ",
343
294
  ]
344
295
 
345
- run menu
296
+ execute menu
346
297
  end
347
298
 
348
299
  desc "conf", "config nginx"
@@ -353,7 +304,7 @@ module Dolphin
353
304
  ",
354
305
  ]
355
306
 
356
- run menu
307
+ execute menu
357
308
  end
358
309
 
359
310
  desc "start", "start nginx"
@@ -365,7 +316,7 @@ module Dolphin
365
316
  ",
366
317
  ]
367
318
 
368
- run menu
319
+ execute menu
369
320
  end
370
321
 
371
322
  desc "stop", "stop nginx"
@@ -377,7 +328,7 @@ module Dolphin
377
328
  ",
378
329
  ]
379
330
 
380
- run menu
331
+ execute menu
381
332
  end
382
333
 
383
334
  desc "restart", "restart nginx"
@@ -389,7 +340,7 @@ module Dolphin
389
340
  ",
390
341
  ]
391
342
 
392
- run menu
343
+ execute menu
393
344
  end
394
345
 
395
346
  end
@@ -407,7 +358,7 @@ module Dolphin
407
358
  ",
408
359
  ]
409
360
 
410
- run menu
361
+ execute menu
411
362
  end
412
363
 
413
364
  desc "go", "normal deploy procedure"
@@ -432,7 +383,7 @@ module Dolphin
432
383
  ",
433
384
  ]
434
385
 
435
- run menu
386
+ execute menu
436
387
  end
437
388
 
438
389
  end
@@ -455,7 +406,7 @@ module Dolphin
455
406
  ",
456
407
  ]
457
408
 
458
- run menu
409
+ execute menu
459
410
  end
460
411
 
461
412
  end
@@ -473,7 +424,7 @@ module Dolphin
473
424
  ",
474
425
  ]
475
426
 
476
- run menu
427
+ execute menu
477
428
  end
478
429
 
479
430
  desc "stop", "stop puma"
@@ -485,7 +436,7 @@ module Dolphin
485
436
  ",
486
437
  ]
487
438
 
488
- run menu
439
+ execute menu
489
440
  end
490
441
 
491
442
  desc "restart", "restart puma"
@@ -498,7 +449,7 @@ module Dolphin
498
449
  ",
499
450
  ]
500
451
 
501
- run menu
452
+ execute menu
502
453
  end
503
454
 
504
455
  end
@@ -1,3 +1,3 @@
1
1
  module Dolphin
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolphin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - |
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-07 00:00:00.000000000 Z
12
+ date: 2013-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor