grid_runner 0.0.2

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: 65264a594e4b9b55c5d803407aa27f0de261eb39
4
+ data.tar.gz: dc9014e259f1f928367306505decdca62e2f2db6
5
+ SHA512:
6
+ metadata.gz: bb2ebd711783abf55e3a15afb6c7c8a77b300787b828c9f13bd27955b25be49143753e0e4d8ab27e8a1e42e10efc749d4bf0f0a15c0d3e8dda2034d41ccfaab0
7
+ data.tar.gz: 43069cd586175de62d9d3ccc4bb157db399ade036bcfb3ba65eb358281800b2fd4ef1a27accfa0828a1efd43e95ff6f031501587385dfab840e9fca7df93e04a
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem "rainbow"
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grid_runner (0.0.1)
5
+ gli (= 2.13.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aruba (0.11.2)
11
+ childprocess (~> 0.5.6)
12
+ contracts (~> 0.9)
13
+ cucumber (>= 1.3.19)
14
+ event-bus (~> 0.2)
15
+ ffi (~> 1.9.10)
16
+ rspec-expectations (>= 2.99)
17
+ thor (~> 0.19)
18
+ builder (3.2.2)
19
+ childprocess (0.5.8)
20
+ ffi (~> 1.0, >= 1.0.11)
21
+ contracts (0.12.0)
22
+ cucumber (2.1.0)
23
+ builder (>= 2.1.2)
24
+ cucumber-core (~> 1.3.0)
25
+ diff-lcs (>= 1.1.3)
26
+ gherkin3 (~> 3.1.0)
27
+ multi_json (>= 1.7.5, < 2.0)
28
+ multi_test (>= 0.1.2)
29
+ cucumber-core (1.3.0)
30
+ gherkin3 (~> 3.1.0)
31
+ diff-lcs (1.2.5)
32
+ event-bus (0.2.1)
33
+ ffi (1.9.10)
34
+ gherkin3 (3.1.2)
35
+ gli (2.13.4)
36
+ json (1.8.3)
37
+ multi_json (1.11.2)
38
+ multi_test (0.1.2)
39
+ rainbow (2.0.0)
40
+ rake (10.4.2)
41
+ rdoc (4.2.0)
42
+ json (~> 1.4)
43
+ rspec-expectations (3.4.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.4.0)
46
+ rspec-support (3.4.1)
47
+ thor (0.19.1)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ aruba
54
+ grid_runner!
55
+ rainbow
56
+ rake
57
+ rdoc
data/Procfile ADDED
@@ -0,0 +1,9 @@
1
+ elasticsearch: cd elasticsearch; ./dev-start.sh
2
+ media-api: sbt "project media-api" "~ run 9001"
3
+ thrall: sbt "project thrall" "~ run 9002"
4
+ image-loader: sbt "project image-loader" "~ run 9003"
5
+ ftp-watcher: sbt -Dftp.active=true "project ftp-watcher" "~ run 9004"
6
+ kahuna: sbt "project kahuna" "~ run 9005"
7
+ cropper: sbt "project cropper" "~ run 9006"
8
+ metadata-editor: sbt "project metadata-editor" "~ run 9007"
9
+ collections: sbt "project collections" "~ run 9010"
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ Grid Runner
2
+ ===========
3
+
4
+ A command line tool for running Grid microservices
5
+
6
+ Install
7
+ -------
8
+
9
+ ``` gem install grid_runner ```
10
+
11
+
12
+ Requirements
13
+ ------------
14
+
15
+ grid_runner uses a Procfile at the root of your project similar to [Foreman](https://github.com/ddollar/foreman)
16
+
17
+
18
+ Commands
19
+ --------
20
+
21
+ * ``` grid_runner list ```
22
+ * ``` grid_runner run <APP_NAME || 'all' > ```
23
+ * ``` grid_runner kill <APP_NAME || 'all' > ```
24
+ * ``` grid_runner restart <APP_NAME || 'all' > ```
25
+
26
+
27
+ Logs
28
+ ----
29
+
30
+ Currently grid_runner will put all logs in ./logs/APPNAME.log
31
+
32
+ * To watch all logs I use ``` tail -f logs/* ```
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
+ rd.title = 'Your application title'
11
+ end
12
+
13
+ spec = eval(File.read('grid_runner.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+ require 'rake/testtask'
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "test"
41
+ t.test_files = FileList['test/*_test.rb']
42
+ end
43
+
44
+ task :default => [:test,:features]
data/bin/grid_runner ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'rainbow'
4
+ require 'grid_runner'
5
+
6
+ include GLI::App
7
+
8
+ program_desc 'A simple CLI to manage The Grid sub processes'
9
+
10
+ subcommand_option_handling :normal
11
+ arguments :strict
12
+
13
+
14
+ def apps_from_args(args)
15
+ return App.all if args.first == "all"
16
+ return App.find(args) if args.first
17
+ end
18
+
19
+ desc 'Describe run'
20
+ arg_name 'Describe arguments to run here'
21
+ command :run do |c|
22
+ c.desc 'Describe a flag to run'
23
+ c.default_value 'default'
24
+ c.flag :f
25
+ c.action do |global_options,options,args|
26
+ apps_from_args(args).each do |app|
27
+ if app.status == :running
28
+ puts Rainbow("#{app.name} already running!").red
29
+ puts
30
+ else
31
+ app.run
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ desc 'Describe restart'
38
+ arg_name "app names separated by a SPACE or 'all'"
39
+ command :restart do |c|
40
+ c.action do |global_options,options,args|
41
+ colors = COLORS.shuffle
42
+ apps_from_args(args).each do |app|
43
+ begin
44
+ if app.status == :running
45
+ Process.kill("HUP", app.pid.to_i)
46
+ puts "kilt #{app.name}"
47
+ end
48
+ app.display
49
+ ensure
50
+ app.run
51
+ end
52
+ end
53
+
54
+ puts "restart command ran"
55
+ end
56
+ end
57
+
58
+ desc 'Describe list here'
59
+ arg_name 'Describe arguments to list here'
60
+ command :list do |c|
61
+ c.action do |global_options,options,args|
62
+ App.all.each_with_index do |app, ix|
63
+ app.display(ix)
64
+ end
65
+ end
66
+ end
67
+
68
+ desc 'kills selected app'
69
+ arg_name 'provide an app name'
70
+ command :kill do |c|
71
+ c.action do |global_options,options,args|
72
+ apps_from_args(args).each do |app|
73
+ puts "No app with that name found" and return unless app
74
+ app.display
75
+ app.kill!
76
+ end
77
+ puts
78
+ end
79
+ end
80
+
81
+ exit run(ARGV)
Binary file
@@ -0,0 +1,19 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','grid_runner','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'grid_runner'
5
+ s.version = GridRunner::VERSION
6
+ s.author = 'NickyPStraightStylinOnEm'
7
+ s.email = 'np1249a@gmail.com'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = 'A lil appy to run them small apz'
10
+ s.files = `git ls-files`.split("
11
+ ")
12
+ s.require_paths << 'lib'
13
+ s.bindir = 'bin'
14
+ s.executables << 'grid_runner'
15
+ s.add_development_dependency('rake')
16
+ s.add_development_dependency('rdoc')
17
+ s.add_development_dependency('aruba')
18
+ s.add_runtime_dependency('gli','2.13.4')
19
+ end
data/grid_runner.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = grid_runner
2
+
3
+ Generate this with
4
+ grid_runner rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,3 @@
1
+ require 'grid_runner/version.rb'
2
+ require 'grid_runner/colors.rb'
3
+ require 'grid_runner/applications.rb'
@@ -0,0 +1,85 @@
1
+ require 'open3'
2
+
3
+ class App
4
+ PROCFILE = File.open(Dir.pwd + "/Procfile")
5
+
6
+ attr_reader :name, :command, :status, :pid
7
+
8
+ def initialize(name, command, status, pid)
9
+ @name = name
10
+ @command = command
11
+ @status = status
12
+ @pid = pid
13
+ end
14
+
15
+ def self.all
16
+ PROCFILE.map do |line|
17
+ App.from_procfile(line)
18
+ end
19
+ end
20
+
21
+ def self.find(args)
22
+ App.all.select { |app| args.include?( app.name ) }
23
+ end
24
+
25
+ def self.from_procfile(line)
26
+ name = line.split(":")[0]
27
+ cmd = line.split(":")[1]
28
+ ps_out = ps_out(name)
29
+ status = ps_out[:status]
30
+ pid = ps_out[:pid]
31
+
32
+ App.new(name, cmd, status, pid)
33
+ end
34
+
35
+ def display(color_index = rand(0..COLORS.length))
36
+ puts Rainbow("#{name} ").send(COLORS[color_index % COLORS.length]).underline
37
+ puts "status: #{status}"
38
+ puts "pid: #{pid}" if status == :running
39
+ puts "log: #{log.path}"
40
+ puts
41
+ end
42
+
43
+ def kill!
44
+ if status == :running
45
+ Process.kill("HUP", pid.to_i)
46
+ puts Rainbow("killing #{name}").red
47
+ end
48
+ end
49
+
50
+ def log
51
+ File.open((Dir.pwd + "/logs/" + "#{name}.log"), "w+")
52
+ end
53
+
54
+ def run
55
+ puts Rainbow("running #{app.name}").green
56
+
57
+ Process.spawn(
58
+ ENV,
59
+ command,
60
+ out: [log.path, "w"],
61
+ err: [log.path, "w"],
62
+ :in => "/dev/null"
63
+ )
64
+ end
65
+
66
+ def status
67
+ @status ||= App.ps_out(name)[:status]
68
+ end
69
+
70
+ private
71
+
72
+ def self.ps_out(name)
73
+ stdout, stderr, cmd_status = Open3.capture3("ps aux | grep #{name}")
74
+ if cmd_status.success?
75
+ # find processes that are either sbt or ES, and filter out the grep command itself
76
+ if p = stdout.split(/\n/).find {|l| (l.match("sbt") || l.match("elasticsearch")) && !l.match("grep") }
77
+ proc_status = :running
78
+ pid = p.match(/\d{1,8}\s/)[0]
79
+ else
80
+ proc_status = :not_running
81
+ end
82
+ end
83
+ {status: proc_status, pid: pid}
84
+ end
85
+ end
@@ -0,0 +1,9 @@
1
+ COLORS = [
2
+ :red,
3
+ :green,
4
+ :yellow,
5
+ :blue,
6
+ :magenta,
7
+ :cyan,
8
+ :white
9
+ ]
@@ -0,0 +1,3 @@
1
+ module GridRunner
2
+ VERSION = '0.0.2'
3
+ end
data/test.rb ADDED
@@ -0,0 +1,2 @@
1
+ puts File.expand_path(File.dirname(__FILE__)) + ".butt"
2
+
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ # Add test libraries you want to use here, e.g. mocha
4
+
5
+ class Test::Unit::TestCase
6
+
7
+ # Add global extensions to the test case class here
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grid_runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - NickyPStraightStylinOnEm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.4
69
+ description:
70
+ email: np1249a@gmail.com
71
+ executables:
72
+ - grid_runner
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - Procfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/grid_runner
82
+ - grid_runner-0.0.1.gem
83
+ - grid_runner.gemspec
84
+ - grid_runner.rdoc
85
+ - lib/grid_runner.rb
86
+ - lib/grid_runner/applications.rb
87
+ - lib/grid_runner/colors.rb
88
+ - lib/grid_runner/version.rb
89
+ - test.rb
90
+ - test/default_test.rb
91
+ - test/test_helper.rb
92
+ homepage:
93
+ licenses: []
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.14
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A lil appy to run them small apz
116
+ test_files: []