20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/opzworks/commands/elastic.rb', line 20
def self.run
options = Trollop.options do
banner <<-EOS.unindent
#{ELASTIC.banner}
opzworks elastic stack1 stack2 ... [--start|--stop|--bounce|--rolling]
The stack name can be passed as any unique regex. If there is
more than one match, it will simply be skipped.
Options:
EOS
opt :start, 'Start Elastic', default: false
opt :stop, 'Stop Elastic', default: false
opt :bounce, 'Bounce (stop/start) Elastic', default: false
opt :rolling, 'Perform a rolling restart of Elastic', default: false
opt :old_service_name, "Use 'elasticsearch' as the service name, otherwise use the layer shortname", default: false
end
ARGV.empty? ? Trollop.die('no stacks specified') : false
optarr = []
options.each do |opt, val|
val == true ? optarr << opt : false
end
optarr.empty? ? Trollop.die('no options specified') : false
config = OpzWorks.config
@client = Aws::OpsWorks::Client.new(region: config.aws_region, profile: config.aws_profile)
response = @client.describe_stacks
ARGV.each do |opt|
var = if options[:start]
es_get_input(opt, response, 'start')
else
es_get_input(opt, response)
end
next if var == false
options[:old_service_name] ? @service_name = 'elasticsearch' : false
case options[:rolling]
when true
@ip_addrs.each do |ip|
puts "\n________________________________________________"
puts "Now operating on host #{ip}".foreground(:yellow)
if @disable_shard_allocation
es_enable_allocation(ip, 'none')
sleep 2
end
es_service('restart', [ip], @service_name)
es_wait_for_status(ip, 'yellow')
es_enable_allocation(ip, 'all') if @disable_shard_allocation
es_wait_for_status(ip, 'green')
end
end
case options[:start]
when true
es_service('start', @ip_addrs, @service_name)
@ip_addrs.each do |ip|
es_wait_for_status(ip, 'green')
end
end
case options[:stop]
when true
if @disable_shard_allocation
es_enable_allocation(@ip_addrs.first, 'none')
sleep 2
end
es_service('stop', @ip_addrs, @service_name)
end
case options[:bounce]
when true
if @disable_shard_allocation
es_enable_allocation(@ip_addrs.first, 'none')
sleep 2
end
es_service('restart', @ip_addrs, @service_name)
es_wait_for_status(@ip_addrs.first, 'yellow')
es_enable_allocation(@ip_addrs.first, 'all') if @disable_shard_allocation
es_wait_for_status(@ip_addrs.first, 'green')
end
end
end
|