foreman-capistrano 0.51.5 → 0.52.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.
@@ -0,0 +1,19 @@
1
+ <% engine.each_process do |name, process| %>
2
+ <% 1.upto(engine.formation[name]) do |num| %>
3
+ <% port = engine.port_for(process, num) %>
4
+ check process <%= app %>-<%= name %>-<%= num %> with pidfile <%= pid_file_for(name, num) %>
5
+ depends on <%= File.basename(check_file_for(name)) %>
6
+ depends on <%= File.basename(app_check_file) %>
7
+ group <%= app %>-<%= name %>
8
+ group <%= app %>
9
+ start program "/usr/local/rvm/bin/rvm-shell -c 'RAILS_ENV=production PORT=<%= port %> PID_FILE=<%= pid_file_for(name, num) %> LOG_FILE=<%= log_file_for(name, num) %> <%= wrapper_path_for(name) %> start'"
10
+ stop program "/usr/local/rvm/bin/rvm-shell -c 'PID_FILE=<%= pid_file_for(name, num) %> <%= wrapper_path_for(name) %> stop'"
11
+
12
+ <% end %>
13
+ check file <%= File.basename(check_file_for(name)) %> with path <%= check_file_for(name) %>
14
+ if changed timestamp then restart
15
+
16
+ <% end %>
17
+
18
+ check file <%= File.basename(app_check_file) %> with path <%= app_check_file %>
19
+ if changed timestamp then restart
@@ -0,0 +1,75 @@
1
+ #!/bin/sh
2
+
3
+ PID_FILE=${PID_FILE:-<%= pid %>/<%= name %>.pid}
4
+ LOG_FILE=${LOG_FILE:-<%= log %>/<%= 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
+ cd <%= engine.root %>; <%= 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 -TERM $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
@@ -33,24 +33,35 @@ if defined?(Capistrano)
33
33
  args << "-l #{foreman_log}"
34
34
  args << "-p #{foreman_port}"
35
35
  args << "-c #{foreman_concurrency}" if foreman_concurrency
36
- run "cd #{release_path} && #{bundle_cmd} exec foreman export #{args.join(' ')}"
36
+ run "cd #{current_path} && #{bundle_cmd} exec foreman export #{args.join(' ')}"
37
37
  end
38
38
 
39
39
  desc "Start the application services"
40
40
  task :start, :roles => :app do
41
- run "#{sudo} start #{application}"
41
+ if foreman_format == 'upstart'
42
+ run "#{sudo} start #{application}"
43
+ elsif foreman_format == 'monit'
44
+ run "monit start -g #{application}"
45
+ end
42
46
  end
43
47
 
44
48
  desc "Stop the application services"
45
49
  task :stop, :roles => :app do
46
- run "#{sudo} stop #{application}"
50
+ if foreman_format == 'upstart'
51
+ run "#{sudo} stop #{application}"
52
+ elsif foreman_format == 'monit'
53
+ run "monit stop -g #{application}"
54
+ end
47
55
  end
48
56
 
49
57
  desc "Restart the application services"
50
58
  task :restart, :roles => :app do
51
- run "#{sudo} start #{application} || #{sudo} restart #{application}"
59
+ if foreman_format == 'upstart'
60
+ run "#{sudo} start #{application} || #{sudo} restart #{application}"
61
+ elsif foreman_format == 'monit'
62
+ run "monit restart -g #{application}"
63
+ end
52
64
  end
53
-
54
65
  end
55
66
  end
56
67
  end
@@ -0,0 +1,47 @@
1
+ require 'foreman/export'
2
+ require 'foreman/cli'
3
+
4
+ class Foreman::Export::Monit < Foreman::Export::Base
5
+ attr_reader :pid, :check
6
+
7
+ def export
8
+ super
9
+
10
+ @user ||= app
11
+ @log = File.expand_path("#{@location}/log")
12
+ @pid = File.expand_path("#{@location}/pids")
13
+ @check = File.expand_path("#{@location}/lock")
14
+ @location = File.expand_path(@location)
15
+ FileUtils.mkdir_p(@pid)
16
+ FileUtils.mkdir_p(@check)
17
+
18
+ engine.each_process do |name, process|
19
+ write_template "monit/wrapper.sh.erb", "#{app}-#{name}.sh", binding
20
+ chmod 0755, "#{app}-#{name}.sh"
21
+ `touch #{check_file_for(name)}`
22
+ end
23
+
24
+ `touch #{app_check_file}`
25
+ write_template "monit/monitrc.erb", "#{app}.monitrc", binding
26
+ end
27
+
28
+ def wrapper_path_for(name)
29
+ File.join(location, "#{app}-#{name}.sh")
30
+ end
31
+
32
+ def pid_file_for(name, num)
33
+ File.join(pid, "#{app}-#{name}-#{num}.pid")
34
+ end
35
+
36
+ def log_file_for(name, num)
37
+ File.join(log, "#{app}-#{name}-#{num}.log")
38
+ end
39
+
40
+ def check_file_for(name)
41
+ File.join(check, "#{app}-#{name}.restart")
42
+ end
43
+
44
+ def app_check_file
45
+ File.join(check, "#{app}.restart")
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.51.5"
3
+ VERSION = "0.52.0"
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.5
4
+ version: 0.52.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-29 00:00:00.000000000 Z
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -42,6 +42,7 @@ files:
42
42
  - lib/foreman/procfile.rb
43
43
  - lib/foreman/distribution.rb
44
44
  - lib/foreman/export/bluepill.rb
45
+ - lib/foreman/export/monit.rb
45
46
  - lib/foreman/export/supervisord.rb
46
47
  - lib/foreman/export/runit.rb
47
48
  - lib/foreman/export/inittab.rb
@@ -107,6 +108,8 @@ files:
107
108
  - data/export/bluepill/master.pill.erb
108
109
  - data/export/launchd/launchd.plist.erb
109
110
  - data/export/supervisord/app.conf.erb
111
+ - data/export/monit/wrapper.sh.erb
112
+ - data/export/monit/monitrc.erb
110
113
  - data/example/ticker
111
114
  - data/example/Procfile
112
115
  - data/example/utf8