eyemanager 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f29f914bd2d3cc25e0b65992914ff0f3065b1f77
4
+ data.tar.gz: 4ee6ed82137befc41db9a5d7b294ae336f1e206c
5
+ SHA512:
6
+ metadata.gz: d56f9004008efe7c0858bf201b08221ff7e976038da2473e31136332bec75e6a0d608d277a37cb501d10b1892a68e0a281545a321112d058c3fced28d4da4dfb
7
+ data.tar.gz: 611e76bf0a2415112ec99ea63c13091bdab803d6c03affae99d43fd1827cc4d363f9f8fb97977def183bfabfa734aed97052870598663cc19dbf490d42cf8637
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eyemanager.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "rb-fsevent", :require => false if RUBY_PLATFORM =~ /darwin/i
8
+ gem "guard-rspec"
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,44 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # Feel free to open issues for suggestions and improvements
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+
17
+ # Rails files
18
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
19
+ dsl.watch_spec_files_for(rails.app_files)
20
+ dsl.watch_spec_files_for(rails.views)
21
+
22
+ watch(rails.controllers) do |m|
23
+ [
24
+ rspec.spec.call("routing/#{m[1]}_routing"),
25
+ rspec.spec.call("controllers/#{m[1]}_controller"),
26
+ rspec.spec.call("acceptance/#{m[1]}")
27
+ ]
28
+ end
29
+
30
+ # Rails config changes
31
+ watch(rails.spec_helper) { rspec.spec_dir }
32
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
33
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
34
+
35
+ # Capybara features specs
36
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
37
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
38
+
39
+ # Turnip features and steps
40
+ watch(%r{^spec/acceptance/(.+)\.feature$})
41
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
42
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
43
+ end
44
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 joshweir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Eyemanager
2
+
3
+ Ruby wrapper for the [Eye process monitoring tool command line interface](https://github.com/kostya/eye#commands).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'eyemanager'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install eyemanager
20
+
21
+ ## Usage
22
+
23
+ ### Start
24
+
25
+ This:
26
+
27
+ ```ruby
28
+ EyeManager.start config: 'eye.test.rb', application: 'test'
29
+ ```
30
+
31
+ is equivelant to:
32
+
33
+ ```bash
34
+ eye load eye.test.rb
35
+ eye start test
36
+ ```
37
+
38
+ ### Stop
39
+
40
+ This:
41
+
42
+ ```ruby
43
+ EyeManager.stop application: 'test',
44
+ process: 'sample'
45
+ EyeManager.stop application: 'test2',
46
+ group: 'samples', process: 'sample'
47
+ ```
48
+
49
+ is equivelant to:
50
+
51
+ ```bash
52
+ eye stop test:sample
53
+ eye stop test:samples:sample
54
+ ```
55
+
56
+ ### Status
57
+
58
+ This:
59
+
60
+ ```ruby
61
+ EyeManager.status application: 'test',
62
+ process: 'sample'
63
+ ```
64
+
65
+ will retrieve the state of the `test` application's `sample` process.
66
+
67
+ If your process is within a `group` block, ensure to include the `group`:
68
+
69
+ ```ruby
70
+ EyeManager.stop application: 'test2',
71
+ group: 'samples', process: 'sample'
72
+ ```
73
+
74
+ ### Destroy
75
+
76
+ Stop Eye processes and quite Eye:
77
+
78
+ ```ruby
79
+ EyeManager.destroy
80
+ ```
81
+
82
+ equivelant to:
83
+
84
+ ```bash
85
+ eye q -s
86
+ ```
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joshweir/eyemanager.
91
+
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
96
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eyemanager"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eyemanager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eyemanager"
8
+ spec.version = EyeManager::VERSION
9
+ spec.authors = ["joshweir"]
10
+ spec.email = ["joshua.weir@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for the Eye process monitoring tool cli.}
13
+ spec.homepage = "https://github.com/joshweir/eye-manager"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ #else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_dependency "eye"
36
+ end
@@ -0,0 +1,3 @@
1
+ module EyeManager
2
+ VERSION = "0.1.0"
3
+ end
data/lib/eyemanager.rb ADDED
@@ -0,0 +1,114 @@
1
+ require "eyemanager/version"
2
+ require "json"
3
+
4
+ module EyeManager
5
+ class << self
6
+ def start params={}
7
+ validate_start_params params
8
+ load_config_and_verify params[:config] if params[:config]
9
+ start_and_verify params[:application]
10
+ end
11
+
12
+ def stop params={}
13
+ validate_stop_params params
14
+ stop_and_verify params
15
+ end
16
+
17
+ def status params={}
18
+ validate_status_params params
19
+ eye_status_filtered_by params
20
+ end
21
+
22
+ def destroy
23
+ cmd = "eye q -s"
24
+ output = `#{cmd}`
25
+ raise "Eye destroy failed. " +
26
+ "Command: #{cmd}. Output: #{output}." unless
27
+ /^Eye quit|socket\(.+\) not found/.match(output)
28
+ end
29
+
30
+ private
31
+
32
+ def validate_start_params params={}
33
+ raise ":application is required" unless params[:application]
34
+ end
35
+
36
+ def validate_stop_params params={}
37
+ raise ":application is required" unless params[:application]
38
+ raise ":process is required" unless params[:process]
39
+ end
40
+
41
+ def validate_status_params params={}
42
+ raise ":process is required" unless params[:process]
43
+ end
44
+
45
+ def load_config_and_verify config
46
+ cmd = "eye load #{config}"
47
+ output = `#{cmd}`
48
+ raise "Eye load failed to load config. " +
49
+ "Command: #{cmd}. Output: #{output}." unless
50
+ /Config loaded/.match(output)
51
+ end
52
+
53
+ def start_and_verify application
54
+ cmd = "eye start #{application}"
55
+ output = `#{cmd}`
56
+ raise "Eye start failed. " +
57
+ "Command: #{cmd}. Output: #{output}." unless
58
+ /command :start sent to \[#{Regexp.escape(application)}\]/.match(output)
59
+ end
60
+
61
+ def stop_and_verify params
62
+ eye_process_key = build_eye_process_key_with(params)
63
+ cmd = "eye stop #{eye_process_key}"
64
+ output = `#{cmd}`
65
+ raise "Eye stop failed. " +
66
+ "Command: #{cmd}. Output: #{output}." unless
67
+ /command :stop sent to \[#{Regexp.escape(eye_process_key)}\]/.match(output)
68
+ end
69
+
70
+ def build_eye_process_key_with params={}
71
+ "#{params[:application]}:" +
72
+ "#{(params[:group] ? "#{params[:group]}:" : "")}" +
73
+ "#{params[:process]}"
74
+ end
75
+
76
+ def eye_status_filtered_by params={}
77
+ process_status = 'unknown'
78
+ eye_status_apps_filtered_by(params[:application]).each do |app|
79
+ eye_status_groups_filtered_by(params[:group], app["subtree"])
80
+ .each do |group|
81
+ process_status = eye_status_process_status_filtered_by(
82
+ params[:process], group["subtree"])
83
+ break unless process_status == 'unknown'
84
+ end
85
+ end
86
+ process_status
87
+ rescue JSON::ParserError => e
88
+ 'unknown'
89
+ end
90
+
91
+ def eye_status_apps_filtered_by app
92
+ status_apps = JSON.parse(`eye i -j`)['subtree']
93
+ app.to_s.length > 0 ?
94
+ status_apps
95
+ .select{|a| a["name"] == "#{app}" &&
96
+ a["type"] == "application"} :
97
+ status_apps
98
+ end
99
+
100
+ def eye_status_groups_filtered_by group, app_groups
101
+ the_group = group.to_s.length > 0 ? group : '__default__'
102
+ app_groups.select{|grp| grp["name"] == "#{the_group}" &&
103
+ grp["type"] == "group"}
104
+ end
105
+
106
+ def eye_status_process_status_filtered_by process, group_processes
107
+ the_process =
108
+ group_processes.select{|prc| prc["name"] == "#{process}" &&
109
+ prc["type"] == "process"}
110
+ the_process[0] && the_process[0]["state"] ?
111
+ the_process[0]["state"] : 'unknown'
112
+ end
113
+ end
114
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eyemanager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - joshweir
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: eye
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - joshua.weir@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - eyemanager.gemspec
87
+ - lib/eyemanager.rb
88
+ - lib/eyemanager/version.rb
89
+ homepage: https://github.com/joshweir/eye-manager
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Ruby wrapper for the Eye process monitoring tool cli.
113
+ test_files: []