aws_site_monitor 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b4efdad1bd774afcda2cdfb73079a02d503ee84
4
- data.tar.gz: 7f076bb696837c26bf682705dba6cf1723eedc1d
3
+ metadata.gz: e84a55fbc38e5cd50eafc7d9356957c906322587
4
+ data.tar.gz: e01a652c8a7e4bdb68b789649d25f69125d74dae
5
5
  SHA512:
6
- metadata.gz: ce4dbcc315b7cc39fce9afb36596774752162f5dbb9f543367941b9e5c14ceca25cccd1dd19342efa5ef7eeb4a8cd8140cd68e681739ad91b6878a892bd4eb64
7
- data.tar.gz: 4b768c6daa6ed908d4d6582b4a090da4d61b115664d4902f27aeb2af1bd70b7524083ef87721771d62b75441c84caa964843430f775c322b6cc4f060fc86e47f
6
+ metadata.gz: a4582e145791b09af30ce1679e2cc51829029c669e4729c403db7473c7659d157a538ab5aa839b675807bacfdbf0ca026eea0054f7c9fc3e44c241a2c6df7062
7
+ data.tar.gz: bf2db8bc432d4d8923cce891a45aa84e5ea90f4e2da7fd2e41afbe056d248347d5a1a7c0bd80619c6d49e73a14a7760acf420fe33776259aaa9d16a9b1af6156
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aws_site_monitor (0.1.2)
4
+ aws_site_monitor (0.1.3)
5
5
  activesupport
6
6
  aws-sdk
7
7
  concurrent-ruby
@@ -5,6 +5,7 @@ module Aws
5
5
  option :aws_region, :type => :string, :default => 'us-east-1', :desc => 'AWS region'
6
6
  option :killswitch_url, :type => :string, :desc => 'If a file no longer exists at this url, kill script'
7
7
  option :request_timeout_seconds, :type => :numeric, :default => 15, :desc => 'How long to wait for response before request times out which will trigger a reboot'
8
+ option :attempts_until_hard_stop, :type => :numeric, :default => 0, :desc => 'How many reboot attempts before attempting hard stop, 0 = disabled'
8
9
 
9
10
  desc "start", "Start Watching"
10
11
  def start
@@ -83,9 +84,11 @@ module Aws
83
84
 
84
85
  if result[0] == "2"
85
86
  puts "GOT 200 EVERYTHING OK"
87
+ site.reset_failure_count
86
88
  else
89
+ site.track_failure
87
90
  ::Aws::SiteMonitor::Event.create(:status_code => result)
88
- site.reboot_instances!
91
+ site.handle_failure!(options)
89
92
  end
90
93
  end
91
94
  end
@@ -3,6 +3,39 @@ module Aws
3
3
  class Site
4
4
  include ::Aws::SiteMonitor::PstoreRecord
5
5
 
6
+ def initialize(**options)
7
+ super(**options)
8
+ @failure_count ||= 0
9
+ end
10
+
11
+ #this handles issues where instance cannot be restarted due to normal reboot.
12
+ #since hard stopping takes longer, we don't want to do it unless necessary.
13
+ #the reset failure count is semi wonky because it will reset even if success
14
+ #hasnt yet been reached, however it is much less complicated than trying to
15
+ #query state of multiple instances. basically if threshold is reached, hard stop
16
+ #the instances, then on next pass since we reset the failure count, it should attempt
17
+ #normal reboot, which will cause the instances to start
18
+ def handle_failure!(options)
19
+ hard_stop_enabled = options.attempts_until_hard_stop > 0
20
+
21
+ if hard_stop_enabled && self[:failure_count] == options.attempts_until_hard_stop
22
+ reset_failure_count
23
+ stop_instances!
24
+ else
25
+ reboot_instances!
26
+ end
27
+ end
28
+
29
+ def track_failure
30
+ @failure_count = @failure_count + 1
31
+ save
32
+ end
33
+
34
+ def reset_failure_count
35
+ @failure_count = 0
36
+ save
37
+ end
38
+
6
39
  def reboot_instances!
7
40
  puts "RESTARTING SITE #{self.attributes}"
8
41
  ::Aws::SiteMonitor.ec2_client.reboot_instances(
@@ -19,6 +52,14 @@ module Aws
19
52
  instance_ids: self[:instance_ids]
20
53
  )
21
54
  end
55
+
56
+ def stop_instances!
57
+ ::Aws::SiteMonitor.ec2_client.stop_instances(
58
+ instance_ids: self[:instance_ids]
59
+ )
60
+ rescue ::Aws::EC2::Errors::IncorrectState => e
61
+ start_instances!
62
+ end
22
63
  end
23
64
  end
24
65
  end
@@ -1,5 +1,5 @@
1
1
  module Aws
2
2
  module SiteMonitor
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_site_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Ayre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2018-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler