18
19
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
|
# File 'lib/opzworks/commands/elastic.rb', line 18
def self.run
options = Trollop.options do
banner " \#{ELASTIC.banner}\n\n opzworks elastic stack1 stack2 ... [--start|--stop|--bounce|--rolling]\n\n The stack name can be passed as any unique regex. If there is\n more than one match, it will simply be skipped.\n\n Options:\n EOS\n opt :start, 'Start Elastic', default: false\n opt :stop, 'Stop Elastic', default: false\n opt :bounce, 'Bounce (stop/start) Elastic', default: false\n opt :rolling, 'Perform a rolling restart of Elastic', default: false\n opt :old_service_name, \"Use 'elasticsearch' as the service name, otherwise use the layer shortname\", default: false\n end\n ARGV.empty? ? Trollop.die('no stacks specified') : false\n\n optarr = []\n options.each do |opt, val|\n val == true ? optarr << opt : false\n end\n optarr.empty? ? Trollop.die('no options specified') : false\n\n config = OpzWorks.config\n @client = Aws::OpsWorks::Client.new(region: config.aws_region, profile: config.aws_profile)\n response = @client.describe_stacks\n\n # loops over inputs\n ARGV.each do |opt|\n var = if options[:start]\n es_get_input(opt, response, 'start')\n else\n es_get_input(opt, response)\n end\n next if var == false\n\n options[:old_service_name] ? @service_name = 'elasticsearch' : false\n\n case options[:rolling]\n when true\n # cycle through all the hosts, waiting for status\n @ip_addrs.each do |ip|\n puts \"\\n________________________________________________\"\n puts \"Now operating on host \#{ip}\".foreground(:yellow)\n\n if @disable_shard_allocation\n es_enable_allocation(ip, 'none')\n sleep 2\n end\n\n es_service('restart', [ip], @service_name)\n es_wait_for_status(ip, 'yellow')\n es_enable_allocation(ip, 'all') if @disable_shard_allocation\n es_wait_for_status(ip, 'green')\n end\n end\n\n case options[:start]\n when true\n es_service('start', @ip_addrs, @service_name)\n\n @ip_addrs.each do |ip|\n es_wait_for_status(ip, 'green')\n end\n end\n\n case options[:stop]\n when true\n # use the first host to disable shard allocation\n if @disable_shard_allocation\n es_enable_allocation(@ip_addrs.first, 'none')\n sleep 2\n end\n\n es_service('stop', @ip_addrs, @service_name)\n end\n\n case options[:bounce]\n when true\n # use the first host to disable shard allocation\n if @disable_shard_allocation\n es_enable_allocation(@ip_addrs.first, 'none')\n sleep 2\n end\n\n es_service('restart', @ip_addrs, @service_name)\n\n es_wait_for_status(@ip_addrs.first, 'yellow')\n es_enable_allocation(@ip_addrs.first, 'all') if @disable_shard_allocation\n es_wait_for_status(@ip_addrs.first, 'green')\n end\n end\nend\n".unindent
|