foreman-monit 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: a95b4eeaf37f24b3bb61e14806dfd0103e352c07
4
+ data.tar.gz: 7567d088c18b44c5b0ba13b1c75031da1c04615d
5
+ SHA512:
6
+ metadata.gz: 5821a7ee7e2b0b8933b6605e535be2cd44c2aa1d527d492f63e97818d7f0f8f9dfbadc4631ed17549dc5370d97efc9f5a82351da6f0922044fd2aa78e3ef448a
7
+ data.tar.gz: 7ffafa7c9f79bb280fa0f944220272000380f7f3f4dc21bde7f3883d4bd64f86f5375cf2978e6dc06fd82bbd0abb90c7067efed031eed3e2784793653b99ab8f
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ .idea
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foreman-monit.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sebastian Georgi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Foreman::Monit
2
+
3
+ Small command-line too to export from Procfile to monit control files
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'foreman-monit', github: 'capita/foreman-monit'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ 'foreman-monit export' outputs a monit control file for every process listed in the given Procfile. foreman-monit
18
+ has to be called from the projects root directory and outputs to /tmp/foreman-monit per default. It is most useful in deployment
19
+ via Capistrano to automate restarting of processes or changing the processes configuration/definition after or inside
20
+ your deployment routine
21
+
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
+
25
+ Inside your procfile, you can use PORT, PID_FILE and RAILS_ENV in your process command, e.g.
26
+
27
+ web: bundle exec puma -p $PORT --pidfile $PID_FILE
28
+ worker: bundle exec rake resque:work PIDFILE=$PID_FILE
29
+
30
+ Monit will fork the command in a shell for the specified user and will redirect each output to ./<target>/<app>-<process>.log
31
+
32
+ Just include the directory ./monit/*.conf (or whatever you chose as a target) in your global monitrc and do a 'monit reload'
33
+
34
+ You can start or stop the app's jobs by issuing
35
+
36
+ monit -g <app> start
37
+ monit -g <app> stop
38
+
39
+ or
40
+
41
+ monit -g <app> restart
42
+
43
+ which will typically be somewhere in your 'cap:restart' definition in your Capfile ,e.g.
44
+
45
+ monit stop -g <app>
46
+ foreman-monit export --app <app> --user <user> --env production
47
+ monit reload
48
+ monit start -g <app>
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/foreman-monit ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../lib/foreman-monit')
3
+
4
+ begin
5
+ ForemanMonit::CLI.start
6
+ rescue => e
7
+ puts e.inspect
8
+ puts e.backtrace
9
+ exit 1
10
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foreman-monit/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "foreman-monit"
8
+ gem.version = Foreman::Monit::VERSION
9
+ gem.authors = ["Sebastian Georgi"]
10
+ gem.email = ["sgeorgi@capita.de"]
11
+ gem.description = %q{Outputs bash-wrapped launchers and control files for monit}
12
+ gem.summary = %q{...}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.add_dependency('foreman')
17
+ gem.add_dependency('thor')
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require 'thor/actions'
3
+ require 'rubygems/config_file'
4
+
5
+ Gem.configuration
6
+
7
+ module ForemanMonit
8
+ class CLI < Thor
9
+ include Thor::Actions
10
+
11
+ method_option 'app', :type => :string, :required => true
12
+ method_option 'user', :type => :string, :required => true
13
+ method_option 'target', :type => :string, :default => '/tmp/foreman-monit'
14
+ method_option 'env', :type => :string, :required => true
15
+ method_option 'chruby', :type => :string, :required => false
16
+
17
+ desc 'export', 'Exports shell-wrapper in ./bin and outputs a monit control file for each process in Procfile'
18
+ def export
19
+ ForemanMonit.export_to_monitrc(options.dup)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,72 @@
1
+ require "foreman/engine"
2
+ require 'fileutils'
3
+
4
+ module ForemanMonit
5
+ class Exporter
6
+ def initialize(options)
7
+ @app = options[:app]
8
+ @user = options[:user]
9
+ @target = options[:target]
10
+ @env = options[:env]
11
+ @chruby = options[:chruby]
12
+
13
+ @engine = Foreman::Engine.new
14
+ load_procfile
15
+ load_env
16
+ @port = @engine.base_port
17
+ end
18
+
19
+ def run!
20
+ Dir.mkdir(@target) unless File.exist?(@target)
21
+ FileUtils.rm Dir.glob("#{@target}/*.conf")
22
+ @engine.each_process do |name, process|
23
+ 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) }
25
+ end
26
+ end
27
+
28
+ def info
29
+ puts @engine.processes.inspect
30
+ end
31
+
32
+ def port
33
+ @port += 1
34
+ @port-1
35
+ end
36
+
37
+ def chruby_init
38
+ if @chruby
39
+ "chruby #{@chruby} &&"
40
+ else
41
+ ''
42
+ end
43
+ end
44
+
45
+ def base_dir
46
+ Dir.getwd
47
+ end
48
+
49
+ def pid_file(name)
50
+ File.expand_path(File.join(@target, "#{@app}-#{name}.pid"))
51
+ end
52
+
53
+ def log_file(name)
54
+ File.expand_path(File.join(@target, "#{@app}-#{name}.log"))
55
+ end
56
+
57
+ def rails_env
58
+ @env
59
+ end
60
+
61
+ private
62
+
63
+ def load_env
64
+ default_env = File.join(@engine.root, ".env")
65
+ @engine.load_env default_env if File.exists?(default_env)
66
+ end
67
+
68
+ def load_procfile
69
+ @engine.load_procfile('Procfile')
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Foreman
2
+ module Monit
3
+ VERSION = "1.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'foreman-monit/version'
2
+ require 'foreman-monit/exporter'
3
+ require 'foreman-monit/cli'
4
+
5
+ module ForemanMonit
6
+ def self.export_to_monitrc(options)
7
+ exporter = ForemanMonit::Exporter.new(options)
8
+ exporter.run!
9
+ end
10
+ end
@@ -0,0 +1,5 @@
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) %>'"
4
+ group <%= @app %>
5
+
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman-monit
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Georgi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: foreman
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Outputs bash-wrapped launchers and control files for monit
42
+ email:
43
+ - sgeorgi@capita.de
44
+ executables:
45
+ - foreman-monit
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/foreman-monit
55
+ - foreman-monit.gemspec
56
+ - lib/foreman-monit.rb
57
+ - lib/foreman-monit/cli.rb
58
+ - lib/foreman-monit/exporter.rb
59
+ - lib/foreman-monit/version.rb
60
+ - templates/monitrc.erb
61
+ homepage: ''
62
+ licenses: []
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: '...'
84
+ test_files: []
85
+ has_rdoc: