foreman-export-monit 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in foreman-export-monit.gemspec
4
+ gemspec
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ foreman-export-monit (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ foreman (0.41.0)
10
+ thor (>= 0.13.6)
11
+ thor (0.14.6)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ foreman
18
+ foreman-export-monit!
@@ -0,0 +1,17 @@
1
+ * Introduction
2
+ This is an export for [[https://github.com/ddollar/foreman/][foreman]]. It creates monit config and wrappers for the commands so
3
+ monit could start and stop them.
4
+
5
+ * Getting started
6
+
7
+ Add the monit gem to your project
8
+
9
+ #+BEGIN_SRC: ruby
10
+ gem "foreman-export-monit"
11
+ #+END_SRC
12
+
13
+ * Usage
14
+
15
+ #+BEGIN_SRC: sh
16
+ bundle exec foreman export monit
17
+ #+END_SRC
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "foreman-export-monit/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "foreman-export-monit"
7
+ s.version = ForemanExportMonit::VERSION
8
+ s.authors = ["Max Horbul", "Brad Gessler"]
9
+ s.email = ["max.horbul@livingsocial.com", "brad@bradgessler.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Export monit scripts from Foreman}
12
+ s.description = %q{Exports monit scripts fromm Foreman}
13
+
14
+ s.rubyforge_project = "foreman-export-monit"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_development_dependency "foreman"
24
+ end
@@ -0,0 +1,5 @@
1
+ require "foreman-export-monit/version"
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ require 'foreman/export/monit'
@@ -0,0 +1,3 @@
1
+ module ForemanExportMonit
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,15 @@
1
+ <% engine.procfile.entries.each do |process| -%>
2
+ <% 1.upto(concurrency[process.name]) do |num| -%>
3
+ <% port = engine.port_for(process, num, self.port) -%>
4
+ check process <%= app %>-<%= process.name %>-<%= num %> with pidfile <%= pid_file_for(process, num) %>
5
+ depends on <%= File.basename(check_file_for(process)) %>
6
+ group <%= app %>-<%= process.name %>
7
+ start program "/bin/sh -c 'PORT=<%= port %> PID_FILE=<%= pid_file_for(process, num) %> LOG_FILE=<%= log_file_for(process, num) %> <%= wrapper_path_for(process) %> start'" as uid <%= user %>
8
+ stop program "/bin/sh -c 'PID_FILE=<%= pid_file_for(process, num) %> <%= wrapper_path_for(process) %> stop'" as uid <%= user %>
9
+
10
+ <% end -%>
11
+ check file <%= File.basename(check_file_for(process)) %> with path <%= check_file_for(process) %>
12
+ if changed timestamp then restart
13
+
14
+
15
+ <% end -%>
@@ -0,0 +1,75 @@
1
+ #!/bin/bash
2
+
3
+ PID_FILE=${PID_FILE:-/var/run/<%= app %>/<%= process.name %>.pid}
4
+ LOG_FILE=${LOG_FILE:-<%= log %>/<%= process.name %>.log}
5
+
6
+ STATUS_RUNNING=0
7
+ STATUS_DEAD_WITH_PID=1
8
+ STATUS_UNKNOWN=4
9
+
10
+ function checkpid() {
11
+ [ -z $1 ] && return 1
12
+ [ -d /proc/$1 ] && return 0
13
+ return 1
14
+ }
15
+
16
+ function start() {
17
+ echo -n "Starting process $0 ..."
18
+ if [ -s $PID_FILE ]
19
+ then
20
+ read pid < $PID_FILE
21
+ if checkpid $pid 2>&1; then
22
+ echo "[FAIL] process with PID ${pid} is running."
23
+ exit $STATUS_UNKNOWN
24
+ fi
25
+ fi
26
+
27
+ <%= process.command %> >> $LOG_FILE 2>&1 &
28
+
29
+ if [ $? -eq 0 ]; then
30
+ echo $! > $PID_FILE
31
+ echo "[OK]"
32
+ else
33
+ echo "[FAIL]"
34
+ exit $STATUS_UNKNOWN
35
+ fi
36
+ }
37
+
38
+ function stop() {
39
+ echo -n "Terminating process $0 ..."
40
+ if [ -s $PID_FILE ]
41
+ then
42
+ read pid < $PID_FILE
43
+ if checkpid $pid 2>&1; then
44
+ kill -SIGTERM $pid
45
+ if [ $? -eq 0 ]; then
46
+ echo $! > $PID_FILE
47
+ echo "[OK]"
48
+ rm -rf $PID_FILE
49
+ else
50
+ echo "[FAIL]"
51
+ exit $STATUS_UNKNOWN
52
+ fi
53
+ else
54
+ echo "[FAIL] process with PID ${pid} does not exist"
55
+ exit $STATUS_DEAD_WITH_PID
56
+ fi
57
+ else
58
+ echo "[FAIL] pid file $PID_FILE is not found"
59
+ exit $STATUS_UNKOWN
60
+ fi
61
+ }
62
+
63
+ case "$1" in
64
+ start)
65
+ start
66
+ ;;
67
+ stop)
68
+ stop
69
+ ;;
70
+ *)
71
+ echo "Usage: $0 {start|stop}"
72
+ exit 0
73
+ esac
74
+
75
+ exit $STATUS_RUNNING
@@ -0,0 +1,60 @@
1
+ require 'foreman/export'
2
+ require 'foreman/cli'
3
+
4
+ module Foreman
5
+ module Export
6
+ class Monit < Foreman::Export::Base
7
+ attr_reader :pid, :check
8
+
9
+ def self.template_root
10
+ @template_root ||= File.expand_path('../../data/templates', __FILE__)
11
+ end
12
+
13
+ def initialize(location, engine, options={})
14
+ super
15
+ @pid = options[:pid]
16
+ @check = options[:check]
17
+ end
18
+
19
+ def export
20
+ error("Must specify a location") unless location
21
+
22
+ FileUtils.mkdir_p location
23
+
24
+ @app ||= File.basename(engine.directory)
25
+ @user ||= app
26
+ @log = File.expand_path(@log || "/var/log/#{app}")
27
+ @pid = File.expand_path(@pid || "/var/run/#{app}")
28
+ @check = File.expand_path(@check || "/var/lock/subsys/#{app}")
29
+ @location = File.expand_path(@location)
30
+
31
+ engine.procfile.entries.each do |process|
32
+ wrapper_template = export_template("monit", "wrapper.sh.erb", self.class.template_root)
33
+ wrapper_config = ERB.new(wrapper_template, 0, "-").result(binding)
34
+ write_file wrapper_path_for(process), wrapper_config
35
+ FileUtils.chmod 0755, wrapper_path_for(process)
36
+ end
37
+
38
+ monitrc_template = export_template("monit", "monitrc.erb", self.class.template_root)
39
+ monitrc_config = ERB.new(monitrc_template, 0, "-").result(binding)
40
+ write_file "#{location}/#{app}.monitrc", monitrc_config
41
+ end
42
+
43
+ def wrapper_path_for(process)
44
+ File.join(location, "#{app}-#{process.name}.sh")
45
+ end
46
+
47
+ def pid_file_for(process, num)
48
+ File.join(pid, "#{process.name}-#{num}.pid")
49
+ end
50
+
51
+ def log_file_for(process, num)
52
+ File.join(log, "#{process.name}-#{num}.log")
53
+ end
54
+
55
+ def check_file_for(process)
56
+ File.join(check, "#{process.name}.restart")
57
+ end
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman-export-monit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Max Horbul
9
+ - Brad Gessler
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-03-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: foreman
17
+ requirement: &70324735965980 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70324735965980
26
+ description: Exports monit scripts fromm Foreman
27
+ email:
28
+ - max.horbul@livingsocial.com
29
+ - brad@bradgessler.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - README.org
38
+ - Rakefile
39
+ - foreman-export-monit.gemspec
40
+ - lib/foreman-export-monit.rb
41
+ - lib/foreman-export-monit/version.rb
42
+ - lib/foreman/data/templates/monitrc.erb
43
+ - lib/foreman/data/templates/wrapper.sh.erb
44
+ - lib/foreman/export/monit.rb
45
+ homepage: ''
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project: foreman-export-monit
65
+ rubygems_version: 1.8.11
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Export monit scripts from Foreman
69
+ test_files: []
70
+ has_rdoc: