boreman 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ed9642b36454011e57224f32d7f2d2ebca79139
4
+ data.tar.gz: ebe4af6a4c60a82703a65b73dc25e881bd46984f
5
+ SHA512:
6
+ metadata.gz: a26c1be8800f249e423ceda7b65b056c98401b0c7ab4aac09acd7558d88ccdbca2aab28e589b808fea15bb1ed1a42445e3e2192d4f967fffefeeb8465361295c
7
+ data.tar.gz: 106ff6eede799a4d93ddb9b659cbb774822cf170cc3e3049c9be66a0e00db8d6ae727cbb25fa6c4135245305ef370978aa5674f29cd461b8f4e55624993c28cd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
data/Procfile ADDED
@@ -0,0 +1,2 @@
1
+ foo: bin/run-forever
2
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Boreman
2
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+
4
+ task :run do
5
+ load './exe/pm'
6
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "boreman"
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/run-forever ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ while true
4
+ sleep 1
5
+ puts "slept"
6
+ end
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
data/boreman.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boreman/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "boreman"
8
+ spec.version = Boreman::VERSION
9
+ spec.authors = ["Kyle Brett"]
10
+ spec.email = ["kyle@kylebrett.com"]
11
+
12
+ spec.summary = %q{Production process manager for Procfile-based applications.}
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.14"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
data/exe/boreman ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'boreman'
4
+ require 'optparse'
5
+
6
+ opts = {}
7
+
8
+ OptionParser.new do |o|
9
+ o.banner = 'Usage: boreman [start|stop|restart|status] [selector]'
10
+ end.parse!
11
+
12
+ action = ARGV[0]
13
+ selector = ARGV[1]
14
+
15
+ Boreman.run action, selector, opts
@@ -0,0 +1,3 @@
1
+ module Boreman
2
+ VERSION = "0.1.0"
3
+ end
data/lib/boreman.rb ADDED
@@ -0,0 +1,113 @@
1
+ require "boreman/version"
2
+
3
+ module Boreman
4
+ def self.run(action, selector, opts = {})
5
+ self.send action, selector, opts
6
+ end
7
+
8
+ def self.procfile_path
9
+ @procfile_path ||= "#{project_root}/Procfile"
10
+ end
11
+
12
+ # assumes command is run from in a git directory with a Procfile
13
+ # TODO walk upwards from cwd looking for Procfile
14
+ def self.project_root
15
+ @project_root ||= `git rev-parse --show-toplevel`.chomp
16
+ end
17
+
18
+ def self.read_procfile
19
+ File.read(procfile_path).lines.each_with_object({}) do |line, procs|
20
+ if m = /^(\w+):(.+)$/.match(line)
21
+ procs[m[1]] = m[2]
22
+ end
23
+ end
24
+ end
25
+
26
+ def self.procs
27
+ @procs ||= read_procfile
28
+ end
29
+
30
+ # directory for keeping track of pid/status for this process
31
+ def self.proc_dir(selector)
32
+ "#{project_root}/.boreman/#{selector}".tap do |dir|
33
+ `mkdir -p #{dir}`
34
+ end
35
+ end
36
+
37
+ def self.pidfile(selector)
38
+ "#{proc_dir selector}/pid"
39
+ end
40
+
41
+ def self.pid(selector)
42
+ should_be_running?(selector) and File.read(pidfile(selector))
43
+ end
44
+
45
+ def self.should_be_running?(selector)
46
+ File.exists? pidfile(selector)
47
+ end
48
+
49
+ def self.is_running?(selector)
50
+ if id = pid(selector)
51
+ !`ps -o pid= #{id}`.chomp.empty?
52
+ else
53
+ false
54
+ end
55
+ end
56
+
57
+ def self.write_pid(selector, pid)
58
+ File.write(pidfile(selector), pid)
59
+ end
60
+
61
+ #
62
+ # Actions
63
+ #
64
+
65
+ def self.start(selector, opts)
66
+ if should_be_running?(selector)
67
+ puts "#{selector} should already be running, deal with that first"
68
+ return
69
+ end
70
+
71
+ if cmd = procs[selector]
72
+ pid = Process.spawn(cmd)
73
+ write_pid selector, pid
74
+ puts "Started #{selector}, pid = #{pid}"
75
+ else
76
+ puts "Entry #{selector} not found in Procfile"
77
+ end
78
+ end
79
+
80
+ def self.restart(selector, opts)
81
+ if is_running?(selector)
82
+ stop selector, opts
83
+ end
84
+
85
+ start selector, opts
86
+ end
87
+
88
+ def self.stop(selector, opts)
89
+ if !is_running?(selector)
90
+ puts "#{selector} is not currently running"
91
+ return
92
+ end
93
+
94
+ id = pid(selector).to_i
95
+ attempts = 0
96
+
97
+ while is_running?(selector)
98
+ attempts += 1
99
+ if attempts > 5
100
+ puts "attempt number #{attempts}; using KILL"
101
+ signal = 'KILL'
102
+ else
103
+ signal = 'TERM'
104
+ end
105
+
106
+ Process.kill(signal, id) rescue
107
+ sleep attempts
108
+ end
109
+
110
+ `rm #{pidfile(selector)}`
111
+ puts "Stopped #{selector} #{id}"
112
+ end
113
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boreman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Brett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-24 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
+ description:
42
+ email:
43
+ - kyle@kylebrett.com
44
+ executables:
45
+ - boreman
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE
52
+ - Procfile
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/run-forever
57
+ - bin/setup
58
+ - boreman.gemspec
59
+ - exe/boreman
60
+ - lib/boreman.rb
61
+ - lib/boreman/version.rb
62
+ homepage:
63
+ licenses: []
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.6.8
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Production process manager for Procfile-based applications.
85
+ test_files: []