foreman-monit 1.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a95b4eeaf37f24b3bb61e14806dfd0103e352c07
4
- data.tar.gz: 7567d088c18b44c5b0ba13b1c75031da1c04615d
3
+ metadata.gz: dae214da7d53772a0aa9d75be46ff2a6d5d8e37f
4
+ data.tar.gz: 2966aa3eaa93c4e9a07c18502fc055639cc86219
5
5
  SHA512:
6
- metadata.gz: 5821a7ee7e2b0b8933b6605e535be2cd44c2aa1d527d492f63e97818d7f0f8f9dfbadc4631ed17549dc5370d97efc9f5a82351da6f0922044fd2aa78e3ef448a
7
- data.tar.gz: 7ffafa7c9f79bb280fa0f944220272000380f7f3f4dc21bde7f3883d4bd64f86f5375cf2978e6dc06fd82bbd0abb90c7067efed031eed3e2784793653b99ab8f
6
+ metadata.gz: 36dae762cbd692eb4c5f3bb79f8b8a29791c6c29d7d759480e366a44ef8181f8e46617c936748593b142d86bdc1728f5ddc7612e4e05fa532913e2c7e969ffb1
7
+ data.tar.gz: 2ebbae052262822fe76e4e74e7a3162bba133c8636d73d66e147b6b03eaaa993e3ed7abcace722554115ab3773f63bebf69c882be8391258174833faf6067da7
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -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, [--chruby] and --app to specify the user that will be running the processes, the RAILS_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
- Just include the directory ./monit/*.conf (or whatever you chose as a target) in your global monitrc and do a 'monit reload'
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
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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 = "foreman-monit"
7
+ gem.name = 'foreman-monit'
8
8
  gem.version = Foreman::Monit::VERSION
9
- gem.authors = ["Sebastian Georgi"]
10
- gem.email = ["sgeorgi@capita.de"]
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 = ["lib"]
21
+ gem.require_paths = %w(lib)
21
22
  end
@@ -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 "foreman/engine"
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("../../../templates/monitrc.erb", __FILE__))).result(binding) }
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, ".env")
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('Procfile')
81
+ @engine.load_procfile(@procfile)
70
82
  end
71
83
  end
72
84
  end
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
  module Monit
3
- VERSION = "1.0"
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ # THIS IS ONLY USED FOR RSPEC!!!
2
+ web: bin/puma -p $PORT --pidfile $PID_FILE -t 4:32
3
+ worker: bin/rake resque:work PIDFILE=$PID_FILE
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  check process <%= @app %>-<%= name %> with pidfile <%= pid_file(name) %>
2
- start program "`which 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 = "`which bash` -c 'kill -SIGKILL `cat <%= pid_file(name) %>` && rm <%= pid_file(name) %>'"
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: '1.0'
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-22 00:00:00.000000000 Z
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: