abalone 0.3.3 → 0.3.4
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/bin/abalone +8 -0
- data/lib/abalone.rb +6 -0
- data/lib/abalone/watchdog.rb +31 -0
- metadata +3 -3
- data/bin/em.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa5b5ee45c18c4e1c7e2db9945967b297d0820da
|
4
|
+
data.tar.gz: 8baf74e20587c757447985d794195a21d879f965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c9247504cc5c6840796e6287b70436d727793a93c0f66f5c9fb340d356810952cfee98cf32c3c1114d2c14413a2a6a70464969688899c8f564a41038ca382b
|
7
|
+
data.tar.gz: 3909b638e6695e1633e55919798cca9fce3aec5c3db0ee383f667e78c00e9a572547b1ff7004b70e417860f16a753b5a46b3c6e39165ed41c12c9752995f2f9f
|
data/bin/abalone
CHANGED
@@ -86,6 +86,14 @@ if options.include? :ssh
|
|
86
86
|
raise "SSH configuration must include the host" unless options[:ssh].include? :host
|
87
87
|
end
|
88
88
|
|
89
|
+
# If we're running under systemd, start a watchdog to let it know we're still alive.
|
90
|
+
# If four sequential pings fail, then systemd will kill & respawn us.
|
91
|
+
if ENV.include? 'WATCHDOG_USEC'
|
92
|
+
require 'abalone/watchdog'
|
93
|
+
# 1/4 of the timeout period, in seconds
|
94
|
+
Abalone::Watchdog.new(Integer(ENV['WATCHDOG_USEC'])/4000000, options)
|
95
|
+
end
|
96
|
+
|
89
97
|
puts
|
90
98
|
puts
|
91
99
|
puts "Starting Abalone Web Shell. Browse to http://localhost:#{options[:port]}"
|
data/lib/abalone.rb
CHANGED
@@ -24,6 +24,12 @@ class Abalone < Sinatra::Base
|
|
24
24
|
|
25
25
|
}
|
26
26
|
|
27
|
+
# super low cost heartbeat response.
|
28
|
+
# Add this first to ensure that the user route doesn't take precedence.
|
29
|
+
get '/heartbeat/ping' do
|
30
|
+
'alive'
|
31
|
+
end
|
32
|
+
|
27
33
|
get '/?:user?' do
|
28
34
|
if !request.websocket?
|
29
35
|
#redirect '/index.html'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Abalone::Watchdog
|
2
|
+
def initialize(period, options)
|
3
|
+
raise 'Watchdog needs a port to be set' unless options.include? :port
|
4
|
+
raise 'Watchdog needs a logger to be set' unless options.include? :logger
|
5
|
+
logger = options[:logger]
|
6
|
+
|
7
|
+
Thread.new do
|
8
|
+
require 'net/http'
|
9
|
+
sleep 5 # give the service time to wake up
|
10
|
+
|
11
|
+
logger.warn "Starting watchdog with period #{period}"
|
12
|
+
loop do
|
13
|
+
http = Net::HTTP.new('localhost', options[:port])
|
14
|
+
http.open_timeout = 1
|
15
|
+
http.read_timeout = 1
|
16
|
+
begin
|
17
|
+
http.start
|
18
|
+
http.request_get('/heartbeat/ping') do |res|
|
19
|
+
logger.debug "Heartbeat response: #{res.read_body}"
|
20
|
+
system('systemd-notify WATCHDOG=1')
|
21
|
+
end
|
22
|
+
rescue => e
|
23
|
+
logger.warn 'Abalone service failed heartbeat check!'
|
24
|
+
logger.debug e.message
|
25
|
+
end
|
26
|
+
|
27
|
+
sleep period
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abalone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -52,8 +52,8 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- LICENSE
|
54
54
|
- bin/abalone
|
55
|
+
- lib/abalone/watchdog.rb
|
55
56
|
- lib/abalone.rb
|
56
|
-
- bin/em.rb
|
57
57
|
- views/index.erb
|
58
58
|
- public/index.html
|
59
59
|
- public/js/abalone.js
|
data/bin/em.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require "eventmachine"
|
5
|
-
|
6
|
-
|
7
|
-
module ProcessWatcher
|
8
|
-
def receive_data(data)
|
9
|
-
puts "Got: #{data}"
|
10
|
-
end
|
11
|
-
def process_exited
|
12
|
-
puts 'the forked child died!'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
pid = fork{
|
17
|
-
sleep 1
|
18
|
-
puts 'booger'
|
19
|
-
sleep 1
|
20
|
-
puts 'oogles'
|
21
|
-
}
|
22
|
-
|
23
|
-
EM.kqueue=true
|
24
|
-
EventMachine.run {
|
25
|
-
EventMachine.watch_process(pid, ProcessWatcher)
|
26
|
-
EventMachine.add_timer(5){ Process.kill('TERM', pid) }
|
27
|
-
}
|
28
|
-
|
29
|
-
#EM.run{
|
30
|
-
# EM.system('sh', proc { |process|
|
31
|
-
# process.send_data("echo hello\n")
|
32
|
-
# process.send_data("exit\n")
|
33
|
-
# sleep 5
|
34
|
-
# EM.stop
|
35
|
-
# },
|
36
|
-
# proc{ |out,status|
|
37
|
-
# puts(out)
|
38
|
-
# })
|
39
|
-
#}
|
40
|
-
|
41
|
-
#EM.run do
|
42
|
-
# EM.add_periodic_timer(1) { puts 'sec' }
|
43
|
-
# EM.add_timer(1.01) { puts '1 second passed by' }
|
44
|
-
# EM.add_timer(2.01) { puts '2 seconds passed by'; }
|
45
|
-
# EM.add_timer(5.01) do
|
46
|
-
# puts '5 seconds passed by: stopping...'
|
47
|
-
# EM.stop
|
48
|
-
# end
|
49
|
-
#end
|
50
|
-
|