foreman-monit 1.0 → 1.0.2
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/.rspec +2 -0
- data/.ruby-version +1 -0
- data/README.md +13 -3
- data/Rakefile +6 -1
- data/foreman-monit.gemspec +6 -5
- data/lib/foreman-monit/cli.rb +1 -0
- data/lib/foreman-monit/exporter.rb +16 -4
- data/lib/foreman-monit/version.rb +1 -1
- data/spec/Procfile +3 -0
- data/spec/lib/foreman-monit/exporter_spec.rb +102 -0
- data/spec/spec_helper.rb +23 -0
- data/templates/monitrc.erb +2 -2
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dae214da7d53772a0aa9d75be46ff2a6d5d8e37f
|
4
|
+
data.tar.gz: 2966aa3eaa93c4e9a07c18502fc055639cc86219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36dae762cbd692eb4c5f3bb79f8b8a29791c6c29d7d759480e366a44ef8181f8e46617c936748593b142d86bdc1728f5ddc7612e4e05fa532913e2c7e969ffb1
|
7
|
+
data.tar.gz: 2ebbae052262822fe76e4e74e7a3162bba133c8636d73d66e147b6b03eaaa993e3ed7abcace722554115ab3773f63bebf69c882be8391258174833faf6067da7
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/README.md
CHANGED
@@ -7,6 +7,8 @@ Small command-line too to export from Procfile to monit control files
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
gem 'foreman-monit', github: 'capita/foreman-monit'
|
10
|
+
or
|
11
|
+
gem 'foreman-monit, '~> v1.0.1'
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
@@ -19,8 +21,10 @@ has to be called from the projects root directory and outputs to /tmp/foreman-mo
|
|
19
21
|
via Capistrano to automate restarting of processes or changing the processes configuration/definition after or inside
|
20
22
|
your deployment routine
|
21
23
|
|
22
|
-
You have to provide --user, --env
|
23
|
-
to use an a general application-indentifier to name control files and groups accordingly.
|
24
|
+
You have to provide --user, --env and --app to specify the user that will be running the processes, the RAILS_ENV
|
25
|
+
to use an a general application-indentifier to name control files and groups accordingly. Additional parameters
|
26
|
+
are --target, which specifies a non-default directory to store the control files in, and --procfile if your Procfile
|
27
|
+
resides outside of the directory you call foreman-monit from.
|
24
28
|
|
25
29
|
Inside your procfile, you can use PORT, PID_FILE and RAILS_ENV in your process command, e.g.
|
26
30
|
|
@@ -29,7 +33,13 @@ Inside your procfile, you can use PORT, PID_FILE and RAILS_ENV in your process c
|
|
29
33
|
|
30
34
|
Monit will fork the command in a shell for the specified user and will redirect each output to ./<target>/<app>-<process>.log
|
31
35
|
|
32
|
-
|
36
|
+
Include the newly exported control files in your monitrc (which normally resides in /etc/monit/monitrc or /etc/monit) with
|
37
|
+
a
|
38
|
+
include /tmp/foreman-monit/*.conf
|
39
|
+
or
|
40
|
+
include /your/path/to/foreman-monit/*.conf
|
41
|
+
|
42
|
+
and simply reload/restart monit with /etc/init.d/monit reload (or restart)
|
33
43
|
|
34
44
|
You can start or stop the app's jobs by issuing
|
35
45
|
|
data/Rakefile
CHANGED
data/foreman-monit.gemspec
CHANGED
@@ -4,18 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'foreman-monit/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'foreman-monit'
|
8
8
|
gem.version = Foreman::Monit::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email =
|
9
|
+
gem.authors = ['Sebastian Georgi']
|
10
|
+
gem.email = %w(sgeorgi@capita.de)
|
11
11
|
gem.description = %q{Outputs bash-wrapped launchers and control files for monit}
|
12
12
|
gem.summary = %q{...}
|
13
|
-
gem.homepage =
|
13
|
+
gem.homepage = ''
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.add_dependency('foreman')
|
17
17
|
gem.add_dependency('thor')
|
18
|
+
gem.add_development_dependency('rspec')
|
18
19
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
20
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
-
gem.require_paths =
|
21
|
+
gem.require_paths = %w(lib)
|
21
22
|
end
|
data/lib/foreman-monit/cli.rb
CHANGED
@@ -10,6 +10,7 @@ module ForemanMonit
|
|
10
10
|
|
11
11
|
method_option 'app', :type => :string, :required => true
|
12
12
|
method_option 'user', :type => :string, :required => true
|
13
|
+
method_option 'procfile', :type => :string, :default => 'Procfile'
|
13
14
|
method_option 'target', :type => :string, :default => '/tmp/foreman-monit'
|
14
15
|
method_option 'env', :type => :string, :required => true
|
15
16
|
method_option 'chruby', :type => :string, :required => false
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'foreman/engine'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
module ForemanMonit
|
@@ -9,6 +9,10 @@ module ForemanMonit
|
|
9
9
|
@target = options[:target]
|
10
10
|
@env = options[:env]
|
11
11
|
@chruby = options[:chruby]
|
12
|
+
@procfile = options[:procfile]
|
13
|
+
|
14
|
+
@su = which_su
|
15
|
+
@bash = which_bash
|
12
16
|
|
13
17
|
@engine = Foreman::Engine.new
|
14
18
|
load_procfile
|
@@ -21,7 +25,7 @@ module ForemanMonit
|
|
21
25
|
FileUtils.rm Dir.glob("#{@target}/*.conf")
|
22
26
|
@engine.each_process do |name, process|
|
23
27
|
file_name = File.join(@target, "#{@app}-#{name}.conf")
|
24
|
-
File.open(file_name, 'w') { |f| f.write ERB.new(File.read(File.expand_path(
|
28
|
+
File.open(file_name, 'w') { |f| f.write ERB.new(File.read(File.expand_path('../../../templates/monitrc.erb', __FILE__))).result(binding) }
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -60,13 +64,21 @@ module ForemanMonit
|
|
60
64
|
|
61
65
|
private
|
62
66
|
|
67
|
+
def which_su
|
68
|
+
`which su`.chomp
|
69
|
+
end
|
70
|
+
|
71
|
+
def which_bash
|
72
|
+
`which bash`.chomp
|
73
|
+
end
|
74
|
+
|
63
75
|
def load_env
|
64
|
-
default_env = File.join(@engine.root,
|
76
|
+
default_env = File.join(@engine.root, '.env')
|
65
77
|
@engine.load_env default_env if File.exists?(default_env)
|
66
78
|
end
|
67
79
|
|
68
80
|
def load_procfile
|
69
|
-
@engine.load_procfile(
|
81
|
+
@engine.load_procfile(@procfile)
|
70
82
|
end
|
71
83
|
end
|
72
84
|
end
|
data/spec/Procfile
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../spec_helper')
|
2
|
+
|
3
|
+
describe ForemanMonit::Exporter do
|
4
|
+
let(:app) { 'FM' }
|
5
|
+
let(:env) { 'production' }
|
6
|
+
let(:user) { 'foreman-user' }
|
7
|
+
let(:target) { '../../tmp' }
|
8
|
+
let(:chruby) {}
|
9
|
+
let(:procfile) { File.join(File.dirname(__FILE__), '../../Procfile') }
|
10
|
+
|
11
|
+
let(:exporter) do
|
12
|
+
ForemanMonit::Exporter.new(app: app, env: env, user: user, target: target, chruby: chruby, procfile: procfile)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
describe '#run!' do
|
17
|
+
before(:each) { exporter.run! }
|
18
|
+
|
19
|
+
it 'creates the target directory' do
|
20
|
+
expect(Dir.exists?('../../tmp')).to be == true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'exports the control file for Procfile#web' do
|
24
|
+
expect(File.exists?('../../tmp/FM-web.conf'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'exports the control file for Procfile#worker' do
|
28
|
+
expect(File.exists?('../../tmp/FM-worker.conf'))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#info' do
|
33
|
+
it 'shows the Procfiles entries' do
|
34
|
+
pending 'Either stub out Kernel.puts or make STDOUT go to a local string for comparison'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#port' do
|
40
|
+
it 'returns an incrementing port number' do
|
41
|
+
expect(exporter.port).to be == 5000
|
42
|
+
expect(exporter.port).to be == 5001
|
43
|
+
expect(exporter.port).to be == 5002
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#chruby_init' do #
|
49
|
+
context 'without @chruby defined' do
|
50
|
+
it 'returns an empty string' do
|
51
|
+
expect(exporter.chruby_init).to be == ''
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with @chruby defined' do
|
56
|
+
let(:chruby) { '2.0.0-p247' }
|
57
|
+
|
58
|
+
it 'returns a chruby prefix' do
|
59
|
+
expect(exporter.chruby_init).to be == 'chruby 2.0.0-p247 &&'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#base_dir' do
|
66
|
+
it 'returns the current base directory' do
|
67
|
+
expect(exporter.base_dir).to be == Dir.getwd
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#log_file' do
|
72
|
+
it 'returns the log file for a given Procfile entry' do
|
73
|
+
name = 'my_test_app'
|
74
|
+
expect(exporter.log_file(name)).to be == File.expand_path(File.join(target, "#{app}-#{name}.log"))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#pid_file' do
|
79
|
+
it 'returns the pid file for a given Procfile entry' do
|
80
|
+
name = 'my_test_app'
|
81
|
+
expect(exporter.pid_file(name)).to be == File.expand_path(File.join(target, "#{app}-#{name}.pid"))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#rails_env' do
|
86
|
+
it 'returns the given env' do
|
87
|
+
expect(exporter.rails_env).to be == 'production'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '##which_su' do
|
92
|
+
it 'returns the path to the su binary' do
|
93
|
+
expect(exporter.send(:which_su)).to be == `which su`.chomp
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '##which_bash' do
|
98
|
+
it 'returns the path to the bash binary' do
|
99
|
+
expect(exporter.send(:which_bash)).to be == `which bash`.chomp
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'foreman-monit'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
|
20
|
+
config.before(:suite) do
|
21
|
+
FileUtils.rm_rf(File.join(File.dirname(__FILE__), 'tmp'))
|
22
|
+
end
|
23
|
+
end
|
data/templates/monitrc.erb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
check process <%= @app %>-<%= name %> with pidfile <%= pid_file(name) %>
|
2
|
-
start program "
|
3
|
-
stop program = "
|
2
|
+
start program "<%= @su %> <%= @user %> -l -c '<%= chruby_init %> cd <%= base_dir %>; export PORT=<%= port %>; export PID_FILE=<%= pid_file(name) %>; export RAILS_ENV=<%= rails_env %>; <%= process.command %> >> <%= log_file(name) %> 2>&1 &'" with timeout 180 seconds
|
3
|
+
stop program = "<%= @bash %> -c 'kill -SIGKILL `cat <%= pid_file(name) %>` && rm <%= pid_file(name) %>'"
|
4
4
|
group <%= @app %>
|
5
5
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-monit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Georgi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '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: '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'
|
41
55
|
description: Outputs bash-wrapped launchers and control files for monit
|
42
56
|
email:
|
43
57
|
- sgeorgi@capita.de
|
@@ -47,6 +61,8 @@ extensions: []
|
|
47
61
|
extra_rdoc_files: []
|
48
62
|
files:
|
49
63
|
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- .ruby-version
|
50
66
|
- Gemfile
|
51
67
|
- LICENSE.txt
|
52
68
|
- README.md
|
@@ -57,6 +73,9 @@ files:
|
|
57
73
|
- lib/foreman-monit/cli.rb
|
58
74
|
- lib/foreman-monit/exporter.rb
|
59
75
|
- lib/foreman-monit/version.rb
|
76
|
+
- spec/Procfile
|
77
|
+
- spec/lib/foreman-monit/exporter_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
60
79
|
- templates/monitrc.erb
|
61
80
|
homepage: ''
|
62
81
|
licenses: []
|
@@ -81,5 +100,8 @@ rubygems_version: 2.0.3
|
|
81
100
|
signing_key:
|
82
101
|
specification_version: 4
|
83
102
|
summary: '...'
|
84
|
-
test_files:
|
103
|
+
test_files:
|
104
|
+
- spec/Procfile
|
105
|
+
- spec/lib/foreman-monit/exporter_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
85
107
|
has_rdoc:
|