node_heartbeat 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Dockerfile +26 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-entrypoint.sh +8 -0
- data/exe/node_heartbeat +5 -0
- data/lib/node_heartbeat.rb +6 -0
- data/lib/node_heartbeat/base.rb +13 -0
- data/lib/node_heartbeat/beat_once.rb +19 -0
- data/lib/node_heartbeat/cli.rb +17 -0
- data/lib/node_heartbeat/get_private_ip.rb +15 -0
- data/lib/node_heartbeat/run_heartbeat.rb +42 -0
- data/lib/node_heartbeat/upload_ip.rb +22 -0
- data/lib/node_heartbeat/version.rb +3 -0
- data/node_heartbeat.gemspec +27 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07cd169f8231f1ce87666f75b3ea4d5b2bbea70f
|
4
|
+
data.tar.gz: 787e9b5120b560f4e403777effa9c38d3092f44b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf15c9a5159a3d84f70a9b6b4c6ef3b3a1fd93a28d6aa9136f8080b6fa602ebb2e94a905ad790c509abf3d151e1ed53ed27089b0dc7501ae9df1c83cdbf4477e
|
7
|
+
data.tar.gz: 41c3de267ea1967abe6c86f9fc41207750ff1fa9d993e8c35f42b2ddd71a7da58f1d825a64e304a88c6729ab4917ea8f83a97ec707571902687b21d5382368be
|
data/.gitignore
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
FROM outstand/ruby-base:2.2.4-alpine
|
2
|
+
MAINTAINER Ryan Schlesinger <ryan@outstand.com>
|
3
|
+
|
4
|
+
RUN addgroup heartbeat && \
|
5
|
+
adduser -S -G heartbeat heartbeat
|
6
|
+
|
7
|
+
# Use this to install an official release
|
8
|
+
RUN apk --no-cache add libxml2 libxslt2 \
|
9
|
+
&& apk --no-cache add --virtual build-dependencies build-base libxml2-dev libxslt-dev \
|
10
|
+
&& gem install nokogiri -- --use-system-libraries \
|
11
|
+
&& gem install node_heartbeat \
|
12
|
+
&& apk del build-dependencies
|
13
|
+
|
14
|
+
# Use this to install a development version
|
15
|
+
# RUN apk --no-cache add build-base libxml2-dev libxslt-dev
|
16
|
+
# COPY . /node_heartbeat/
|
17
|
+
# RUN cd /node_heartbeat \
|
18
|
+
# && bundle config build.nokogiri --use-system-libraries \
|
19
|
+
# && bundle install \
|
20
|
+
# && bundle exec rake install
|
21
|
+
|
22
|
+
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
23
|
+
|
24
|
+
ENV DUMB_INIT_SETSID 0
|
25
|
+
ENTRYPOINT ["/docker-entrypoint.sh"]
|
26
|
+
CMD []
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Node Heartbeat
|
2
|
+
|
3
|
+
This gem is used to publish server node IPs to an S3 bucket. The idea is that you can enable an S3 lifecycle rule to delete keys older than a day and have this send updates at least once a day.
|
4
|
+
|
5
|
+
Example usecase: Publish consul master server nodes for cluster bootstrapping.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'node_heartbeat'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install node_heartbeat
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
$ docker run outstand/node_heartbeat start --bucket=<s3 bucket>
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
32
|
+
|
33
|
+
To release a new version:
|
34
|
+
- update the version number in `version.rb`
|
35
|
+
- run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org)
|
36
|
+
- run `docker build -t outstand/node_heartbeat:latest .` to build a new docker image
|
37
|
+
- run `docker push outstand/node_heartbeat:latest` to push the image to docker hub
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/outstand/node_heartbeat.
|
42
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "node_heartbeat"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/node_heartbeat
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'node_heartbeat/base'
|
2
|
+
require 'node_heartbeat/get_private_ip'
|
3
|
+
require 'node_heartbeat/upload_ip'
|
4
|
+
|
5
|
+
module NodeHeartbeat
|
6
|
+
class BeatOnce < Base
|
7
|
+
attr_accessor :bucket
|
8
|
+
|
9
|
+
def initialize(bucket:)
|
10
|
+
self.bucket = bucket
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
puts 'Heartbeat!'
|
15
|
+
private_ip = GetPrivateIP.call.private_ip
|
16
|
+
UploadIP.call(ip: private_ip, bucket: self.bucket)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module NodeHeartbeat
|
4
|
+
class CLI < Thor
|
5
|
+
desc 'version', 'Print out the version string'
|
6
|
+
def version
|
7
|
+
say NodeHeartbeat::VERSION.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'start', 'Start the heartbeat'
|
11
|
+
option :bucket, aliases: '-b', required: true, type: :string, banner: '<s3_bucket>'
|
12
|
+
def start
|
13
|
+
require 'node_heartbeat/run_heartbeat'
|
14
|
+
RunHeartbeat.call(bucket: options[:bucket])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'node_heartbeat/base'
|
2
|
+
require 'excon'
|
3
|
+
|
4
|
+
module NodeHeartbeat
|
5
|
+
class GetPrivateIP < Base
|
6
|
+
URL = 'http://169.254.169.254/latest/meta-data/local-ipv4'.freeze
|
7
|
+
|
8
|
+
def call
|
9
|
+
response = Excon.get(URL, expects: [200], connect_timeout: 10, read_timeout: 10, write_timeout: 10, tcp_nodelay: true)
|
10
|
+
OpenStruct.new(
|
11
|
+
private_ip: response.body
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'node_heartbeat/base'
|
2
|
+
require 'node_heartbeat/beat_once'
|
3
|
+
|
4
|
+
module NodeHeartbeat
|
5
|
+
class RunHeartbeat < Base
|
6
|
+
attr_accessor :bucket
|
7
|
+
|
8
|
+
SLEEP_TIME = 60 * 60 # 1 hour
|
9
|
+
ERROR_SLEEP_TIME = 5
|
10
|
+
|
11
|
+
def initialize(bucket:)
|
12
|
+
self.bucket = bucket
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
%w(INT TERM).each do |sig|
|
17
|
+
begin
|
18
|
+
trap sig do
|
19
|
+
raise Interrupt
|
20
|
+
end
|
21
|
+
rescue ArgumentError
|
22
|
+
puts "Signal #{sig} not supported"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
while true
|
28
|
+
timeout = SLEEP_TIME
|
29
|
+
begin
|
30
|
+
BeatOnce.call(bucket: self.bucket)
|
31
|
+
rescue => e
|
32
|
+
puts "Warning: #{e.message}"
|
33
|
+
timeout = ERROR_SLEEP_TIME
|
34
|
+
end
|
35
|
+
sleep timeout
|
36
|
+
end
|
37
|
+
rescue Interrupt
|
38
|
+
puts 'Exiting'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'node_heartbeat/base'
|
2
|
+
require 'fog/aws'
|
3
|
+
|
4
|
+
module NodeHeartbeat
|
5
|
+
class UploadIP < Base
|
6
|
+
attr_accessor :ip, :bucket
|
7
|
+
|
8
|
+
def initialize(ip:, bucket:)
|
9
|
+
self.ip = ip
|
10
|
+
self.bucket = bucket
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
puts "Uploading ip #{self.ip} to bucket #{self.bucket}"
|
15
|
+
storage = Fog::Storage.new provider: 'AWS', use_iam_profile: true
|
16
|
+
bucket = storage.directories.get(self.bucket)
|
17
|
+
bucket.files.create(
|
18
|
+
key: self.ip
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'node_heartbeat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "node_heartbeat"
|
8
|
+
spec.version = NodeHeartbeat::VERSION
|
9
|
+
spec.authors = ["Ryan Schlesinger"]
|
10
|
+
spec.email = ["ryan@outstand.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Heartbeat server IPs to S3}
|
13
|
+
spec.homepage = 'https://github.com/outstand/node_heartbeat'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = 'exe'
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'thor', '~> 0.19'
|
21
|
+
spec.add_runtime_dependency 'excon', '~> 0.49.0'
|
22
|
+
spec.add_runtime_dependency 'fog-aws', '~> 0.9'
|
23
|
+
spec.add_runtime_dependency 'mime-types', '~> 3.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: node_heartbeat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Schlesinger
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.19'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: excon
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.49.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.49.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fog-aws
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mime-types
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.11'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- ryan@outstand.com
|
100
|
+
executables:
|
101
|
+
- node_heartbeat
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Dockerfile
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- docker-entrypoint.sh
|
113
|
+
- exe/node_heartbeat
|
114
|
+
- lib/node_heartbeat.rb
|
115
|
+
- lib/node_heartbeat/base.rb
|
116
|
+
- lib/node_heartbeat/beat_once.rb
|
117
|
+
- lib/node_heartbeat/cli.rb
|
118
|
+
- lib/node_heartbeat/get_private_ip.rb
|
119
|
+
- lib/node_heartbeat/run_heartbeat.rb
|
120
|
+
- lib/node_heartbeat/upload_ip.rb
|
121
|
+
- lib/node_heartbeat/version.rb
|
122
|
+
- node_heartbeat.gemspec
|
123
|
+
homepage: https://github.com/outstand/node_heartbeat
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.4.8
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Heartbeat server IPs to S3
|
146
|
+
test_files: []
|