aws_site_monitor 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/aws/site_monitor/cli.rb +4 -1
- data/lib/aws/site_monitor/site.rb +41 -0
- data/lib/aws/site_monitor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e84a55fbc38e5cd50eafc7d9356957c906322587
|
4
|
+
data.tar.gz: e01a652c8a7e4bdb68b789649d25f69125d74dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4582e145791b09af30ce1679e2cc51829029c669e4729c403db7473c7659d157a538ab5aa839b675807bacfdbf0ca026eea0054f7c9fc3e44c241a2c6df7062
|
7
|
+
data.tar.gz: bf2db8bc432d4d8923cce891a45aa84e5ea90f4e2da7fd2e41afbe056d248347d5a1a7c0bd80619c6d49e73a14a7760acf420fe33776259aaa9d16a9b1af6156
|
data/Gemfile.lock
CHANGED
data/lib/aws/site_monitor/cli.rb
CHANGED
@@ -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.
|
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
|
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.
|
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-
|
11
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|