capistrano-runit-tasks 0.2.0 → 0.2.3
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.
- data/ChangeLog +14 -1
- data/Manifest.txt +28 -0
- data/README +29 -17
- data/Rakefile +78 -0
- data/lib/capistrano-runit-tasks-templates/default_fcgi_runner.rhtml +1 -1
- data/lib/capistrano-runit-tasks-templates/default_mongrel_runner.rhtml +2 -0
- data/lib/capistrano-runit-tasks.rb +49 -18
- data/lib/runit_command_helper.rb +2 -2
- data/lib/runit_helper.rb +32 -0
- data/lib/runit_runner_helper.rb +4 -2
- data/lib/runit_service_helper.rb +1 -3
- data/setup.rb +1585 -0
- data/test/capistrano-runit-tasks_test.rb +38 -0
- data/test/fixtures/log_runner +2 -0
- data/test/fixtures/runit_config.rb +9 -0
- data/test/fixtures/standard_fcgi_runner +3 -0
- data/test/fixtures/standard_mongrel_runner +2 -0
- data/test/runit_command_helper_test.rb +61 -0
- data/test/runit_helper_test.rb +25 -0
- data/test/runit_runner_helper_test.rb +53 -0
- data/test/runit_service_helper_test.rb +45 -0
- data/test/templates/custom_runner_service_runner +2 -0
- data/test/templates/test_log_runner +2 -0
- data/test/templates/test_runner.rhtml +3 -0
- data/test/templates/test_service_log_runner +2 -0
- data/test/templates/test_service_runner +2 -0
- data/test/test_helper.rb +123 -0
- metadata +63 -40
data/ChangeLog
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
+
*SVN*
|
2
|
+
--------------------------------------------------
|
3
|
+
|
4
|
+
* Add runit_sudo_tasks variable, array of symbols indicating tasks names to be
|
5
|
+
run using sudo.
|
6
|
+
|
7
|
+
* Added support for mongrel, and basic mongrel runner template
|
8
|
+
|
9
|
+
* Changed fcgi_port and fcgi_listener_base_port to listener_port and
|
10
|
+
listener_base_port. Old variable names still supported but considered
|
11
|
+
deprecated.
|
12
|
+
|
1
13
|
*0.2.0* (March 23rd 2006)
|
14
|
+
--------------------------------------------------
|
2
15
|
|
3
16
|
* Added RunitServiceHelper which adds service.add to allow easy creation of
|
4
17
|
services. Refactored other code to use new functionality.
|
@@ -14,4 +27,4 @@
|
|
14
27
|
|
15
28
|
* Changed default fcgi_listener_base_port to 9000
|
16
29
|
|
17
|
-
* Added tests for 0.1.0
|
30
|
+
* Added tests for 0.1.0
|
data/Manifest.txt
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ChangeLog
|
2
|
+
Manifest.txt
|
3
|
+
README
|
4
|
+
Rakefile
|
5
|
+
lib/capistrano-runit-tasks-templates/default_fcgi_runner.rhtml
|
6
|
+
lib/capistrano-runit-tasks-templates/default_log_runner.rhtml
|
7
|
+
lib/capistrano-runit-tasks-templates/default_mongrel_runner.rhtml
|
8
|
+
lib/capistrano-runit-tasks.rb
|
9
|
+
lib/runit_command_helper.rb
|
10
|
+
lib/runit_helper.rb
|
11
|
+
lib/runit_runner_helper.rb
|
12
|
+
lib/runit_service_helper.rb
|
13
|
+
setup.rb
|
14
|
+
test/capistrano-runit-tasks_test.rb
|
15
|
+
test/fixtures/log_runner
|
16
|
+
test/fixtures/runit_config.rb
|
17
|
+
test/fixtures/standard_fcgi_runner
|
18
|
+
test/fixtures/standard_mongrel_runner
|
19
|
+
test/runit_command_helper_test.rb
|
20
|
+
test/runit_helper_test.rb
|
21
|
+
test/runit_runner_helper_test.rb
|
22
|
+
test/runit_service_helper_test.rb
|
23
|
+
test/templates/custom_runner_service_runner
|
24
|
+
test/templates/test_log_runner
|
25
|
+
test/templates/test_runner.rhtml
|
26
|
+
test/templates/test_service_log_runner
|
27
|
+
test/templates/test_service_runner
|
28
|
+
test/test_helper.rb
|
data/README
CHANGED
@@ -5,12 +5,12 @@ Adds tasks to Capistrano for use with the runit supervision scheme.
|
|
5
5
|
This library extends Capistrano to allow processes to be supervised using the
|
6
6
|
runit package. It replaces some of the standard tasks with runit versions and
|
7
7
|
includes tasks and helpers to create the service directory layout and populate
|
8
|
-
it with run scripts. It
|
8
|
+
it with run scripts. It has support fcgi and mongrel listeners, and tries to
|
9
9
|
make it easy to add other services in your deploy.rb.
|
10
10
|
|
11
11
|
== Status
|
12
12
|
|
13
|
-
capistrano-runit-tests 0.2.
|
13
|
+
capistrano-runit-tests 0.2.2 (known as cap-runit from now on) is the third
|
14
14
|
release of the library. It will need more work to be useful to everybody who
|
15
15
|
uses runit. It supports both the sv and runsvctrl/runsvstat versions of runit.
|
16
16
|
Support for daemontools svc command will be added at a later date.
|
@@ -35,7 +35,7 @@ Then run:
|
|
35
35
|
* cap setup
|
36
36
|
* cap cold_deploy
|
37
37
|
|
38
|
-
This sets up one
|
38
|
+
This sets up one mongrel listener on port 8000. Make sure your database is setup
|
39
39
|
and point your webserver at the new listener.
|
40
40
|
|
41
41
|
== Usage
|
@@ -66,38 +66,49 @@ Then adds the following tasks, helpers and variables:
|
|
66
66
|
service directories to to start the service.
|
67
67
|
(Default: ~/services)
|
68
68
|
|
69
|
-
[
|
70
|
-
(Default: 1)
|
69
|
+
[listener_count] Number of listener service dirs to create.
|
70
|
+
(Default: 1) (old name: fcgi_count)
|
71
71
|
|
72
|
-
[
|
73
|
-
(Default: 9000)
|
72
|
+
[listener_base_port] The base port number to use for the listeners.
|
73
|
+
(Default: 9000) (old name: fcgi_listener_base_port)
|
74
74
|
|
75
75
|
[sv_command] Either :sv or :runsvctrl
|
76
76
|
(Default: sv)
|
77
77
|
|
78
78
|
[runner_template_path] The path to search for custom templates.
|
79
79
|
(Default: templates/runit)
|
80
|
+
|
81
|
+
[runit_sudo_tasks] Array of tasks names to run using sudo
|
82
|
+
(default: [])
|
80
83
|
|
81
84
|
cap-runit creates a directory for each listener you ask for. At the moment the
|
82
85
|
directories are created by setup_service_dirs. Later versions should allow for
|
83
86
|
dynamic creation / deletion.
|
84
87
|
|
85
|
-
The directories are named after the port number the
|
86
|
-
|
88
|
+
The directories are named after the port number the listener will run on. If
|
89
|
+
you specified 8500 for the base port and 3 for the listener_count then
|
87
90
|
service/8500, service/8501 and service/8502 directories will be created and
|
88
|
-
populated with run scripts that launch the
|
91
|
+
populated with run scripts that launch the listeners on the corresponding
|
92
|
+
port.
|
89
93
|
|
90
94
|
When the service directories are linked into the master service dir to run,
|
91
95
|
they are named <application>-<port number>. So if :application is set to "foo"
|
92
96
|
in deploy.rb you'll get foo-8500, foo-8501 etc.
|
93
97
|
|
98
|
+
=== Sudo
|
99
|
+
|
100
|
+
When a runit task executes, it will check to see if it's name is included in
|
101
|
+
the runit_sudo_tasks array. If so, it will use sudo rather than run when
|
102
|
+
executing its commands. Note, only tasks defined within capistrano-runit-tasks
|
103
|
+
will do this, none of the standard tasks are changed.
|
104
|
+
|
94
105
|
=== Helpers
|
95
106
|
|
96
|
-
[
|
97
|
-
|
98
|
-
|
107
|
+
[each_listener] Uses the values for listener_base_port and listener_count
|
108
|
+
to yield each of the listener port numbers back to the
|
109
|
+
calling block
|
99
110
|
|
100
|
-
[
|
111
|
+
[listener_dirs] Returns an array containing the path to each of the
|
101
112
|
listener dirs. This is useful when sending commands using
|
102
113
|
sv as it accepts an array of directories as an argument
|
103
114
|
|
@@ -120,8 +131,9 @@ different.
|
|
120
131
|
|
121
132
|
The directory pointed to by the runner_template_path variable is searched
|
122
133
|
before the directory containing the default templates. If you want to override
|
123
|
-
the default templates, create
|
124
|
-
default_log_runner.rhtml and cap-runit will
|
134
|
+
the default templates, create default_mongrel_runner.rhtml or
|
135
|
+
default_fcgi_runner.rhtml and/or default_log_runner.rhtml and cap-runit will
|
136
|
+
pick your custom versions first.
|
125
137
|
|
126
138
|
== Adding your own services
|
127
139
|
|
@@ -168,7 +180,7 @@ This again should be automated, the manual steps I used were:
|
|
168
180
|
* Revert deploy.rb
|
169
181
|
* cap setup_service_dirs to create the structure (Won't touch what's running)
|
170
182
|
* Kill the spinner process
|
171
|
-
* use script/process/reaper to kill the running
|
183
|
+
* use script/process/reaper to kill the running listeners
|
172
184
|
* cap cold_deploy to start the service
|
173
185
|
* Check everything is running OK
|
174
186
|
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
4
|
+
|
5
|
+
Hoe.new("capistrano-runit-tasks", "0.2.3") do |p|
|
6
|
+
p.rubyforge_name = 'cappy-runit'
|
7
|
+
p.author = "Chris McGrath"
|
8
|
+
p.changes = p.paragraphs_of('ChangeLog', 1..3).join("\n")
|
9
|
+
p.summary = p.paragraphs_of('README', 1)[0]
|
10
|
+
p.description = p.paragraphs_of('README', 2)[0]
|
11
|
+
p.email = 'chris@octopod.info'
|
12
|
+
p.url = 'http://cappy-runit.rubyforge.org'
|
13
|
+
p.test_globs = ['test/*_test.rb']
|
14
|
+
end
|
15
|
+
# Gem::manage_gems
|
16
|
+
#
|
17
|
+
# require 'rake/packagetask'
|
18
|
+
# require 'rake/gempackagetask'
|
19
|
+
# require 'rake/rdoctask'
|
20
|
+
# require 'rake/contrib/rubyforgepublisher'
|
21
|
+
# require 'rake/testtask'
|
22
|
+
#
|
23
|
+
# PACKAGE_NAME = "capistrano-runit-tasks"
|
24
|
+
# PACKAGE_VERSION = "0.2.2"
|
25
|
+
# RELEASE_NAME = "REL #{PACKAGE_VERSION}"
|
26
|
+
# PKG_FILE_NAME = "#{PACKAGE_NAME}-#{PACKAGE_VERSION}"
|
27
|
+
# RUBY_FORGE_PROJECT = "cappy-runit"
|
28
|
+
# RUBY_FORGE_USER = "octopod"
|
29
|
+
#
|
30
|
+
# files = FileList["{lib}/**/*"].exclude("rdoc")
|
31
|
+
#
|
32
|
+
# spec = Gem::Specification.new do |s|
|
33
|
+
# s.name = PACKAGE_NAME
|
34
|
+
# s.version = PACKAGE_VERSION
|
35
|
+
# s.rubyforge_project = 'cappy-runit'
|
36
|
+
# s.author = "Chris McGrath"
|
37
|
+
# s.email = "chris@octopod.info"
|
38
|
+
# s.files = files.dup
|
39
|
+
# s.homepage = "http://cappy-runit.rubyforge.org"
|
40
|
+
# s.platform = Gem::Platform::RUBY
|
41
|
+
# s.summary = "Adds tasks to capistrano for use with the runit supervision scheme."
|
42
|
+
# s.require_path = "lib"
|
43
|
+
# s.autorequire = "capistrano-runit-tasks"
|
44
|
+
# s.has_rdoc = true
|
45
|
+
# s.extra_rdoc_files = ["README", "ChangeLog"]
|
46
|
+
# s.rdoc_options << '--title' << 'Capistrano runit tasks documentation' <<
|
47
|
+
# '--main' << 'README'
|
48
|
+
# s.add_dependency("capistrano", ">= 1.1.0")
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# Rake::GemPackageTask.new(spec) do |pkg|
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# Rake::PackageTask.new(PACKAGE_NAME, PACKAGE_VERSION) do |pkg|
|
55
|
+
# pkg.package_files = files.dup << 'setup.rb'
|
56
|
+
# pkg.need_tar_gz = true
|
57
|
+
# pkg.need_zip = true
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# Rake::RDocTask.new do |rd|
|
61
|
+
# rd.main = "README"
|
62
|
+
# rd.rdoc_files.include("README", 'ChangeLog', "lib/**/*.rb")
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# desc "Publish the docs"
|
66
|
+
# task :publish_docs => :rdoc do
|
67
|
+
# Rake::RubyForgePublisher.new(RUBY_FORGE_PROJECT, RUBY_FORGE_USER).upload
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# desc "Run the tests"
|
71
|
+
# Rake::TestTask.new do |t|
|
72
|
+
# t.test_files = FileList['test/*_test.rb']
|
73
|
+
# t.verbose = true
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# task :default => :test do
|
77
|
+
#
|
78
|
+
# end
|
@@ -1,14 +1,18 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'runit_helper'
|
1
3
|
require 'runit_runner_helper'
|
2
4
|
require 'runit_command_helper'
|
3
5
|
require 'runit_service_helper'
|
4
6
|
|
5
7
|
Capistrano.configuration(:must_exist).load do
|
6
8
|
set :service_dir, 'service'
|
7
|
-
set :
|
9
|
+
set :listener_count, 1
|
10
|
+
set :listener_type, :mongrel
|
8
11
|
set :master_service_dir, '~/service'
|
9
|
-
set :
|
12
|
+
set :listener_base_port, 9000
|
10
13
|
set :sv_command, :sv # can be :sv or :runsvctrl
|
11
14
|
set :runner_template_path, File.join('templates', 'runit')
|
15
|
+
set :runit_sudo_tasks, []
|
12
16
|
|
13
17
|
# We need our own task for this as the default cold_deploy
|
14
18
|
# calls restart, which won't work until we've setup the
|
@@ -16,6 +20,7 @@ Capistrano.configuration(:must_exist).load do
|
|
16
20
|
# link exists, but that's beyond my current (very bad) shell-foo
|
17
21
|
desc "Used only for deploying when the services haven't been setup"
|
18
22
|
task :cold_deploy do
|
23
|
+
handle_deprecated_vars
|
19
24
|
transaction do
|
20
25
|
update_code
|
21
26
|
symlink
|
@@ -23,43 +28,69 @@ Capistrano.configuration(:must_exist).load do
|
|
23
28
|
spinner
|
24
29
|
end
|
25
30
|
|
26
|
-
desc "Sets up services directories for supervising
|
31
|
+
desc "Sets up services directories for supervising listeners using runit"
|
27
32
|
task :setup_service_dirs do
|
33
|
+
handle_deprecated_vars
|
28
34
|
application_service_dir = "#{deploy_to}/#{service_dir}"
|
29
|
-
|
35
|
+
runit_helper.run_or_sudo "mkdir -p #{application_service_dir}"
|
30
36
|
|
31
|
-
|
32
|
-
|
37
|
+
each_listener do |listener_port|
|
38
|
+
# DEPRECATION: Need to pass port and fcgi_port to handle old templates, fcgi_port is considered deprecated
|
39
|
+
service.add listener_port, :template => listener_type, :listener_port => listener_port, :fcgi_port => listener_port
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
36
|
-
desc "Links created service dir into master service dir so runit starts the
|
43
|
+
desc "Links created service dir into master service dir so runit starts the listeners"
|
37
44
|
task :spinner do
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
handle_deprecated_vars
|
46
|
+
each_listener do |listener_port|
|
47
|
+
service_dir = "#{deploy_to}/#{service_dir}/#{listener_port}"
|
48
|
+
runit_helper.run_or_sudo "ln -sf #{service_dir} #{master_service_dir}/#{application}-#{listener_port}"
|
41
49
|
end
|
42
50
|
end
|
43
51
|
|
44
|
-
desc "restart task for runit supervised
|
45
|
-
task :restart do
|
46
|
-
|
52
|
+
desc "restart task for runit supervised listeners"
|
53
|
+
task :restart, :roles => :app do
|
54
|
+
handle_deprecated_vars
|
55
|
+
sv.usr2 listener_dirs
|
47
56
|
end
|
48
57
|
|
49
58
|
desc "Hook into after setup to create the runit service directory"
|
50
59
|
task :after_setup do
|
60
|
+
handle_deprecated_vars
|
51
61
|
setup_service_dirs
|
52
62
|
end
|
53
63
|
|
54
|
-
def
|
55
|
-
|
56
|
-
yield
|
64
|
+
def each_listener
|
65
|
+
listener_base_port.upto(listener_base_port + listener_count - 1) do |listener_port|
|
66
|
+
yield listener_port
|
57
67
|
end
|
58
68
|
end
|
59
69
|
|
60
|
-
def
|
70
|
+
def listener_dirs
|
61
71
|
dirs = []
|
62
|
-
|
72
|
+
each_listener { |port| dirs << "#{deploy_to}/#{service_dir}/#{port}" }
|
63
73
|
dirs
|
64
74
|
end
|
75
|
+
|
76
|
+
## DEPRECATED - and alias_method won't work inside the instance_eval this is run in
|
77
|
+
def each_fcgi_listener
|
78
|
+
each_listener { |listener_port| yield listener_port }
|
79
|
+
end
|
80
|
+
|
81
|
+
def fcgi_listener_dirs
|
82
|
+
listener_dirs
|
83
|
+
end
|
84
|
+
|
85
|
+
def handle_deprecated_vars
|
86
|
+
handle_deprecated_var :fcgi_listener_base_port, :listener_base_port
|
87
|
+
handle_deprecated_var :fcgi_count, :listener_count
|
88
|
+
end
|
89
|
+
|
90
|
+
def handle_deprecated_var(old_var, new_var)
|
91
|
+
if @variables.has_key?(old_var)
|
92
|
+
set new_var, @variables[old_var]
|
93
|
+
end
|
94
|
+
set old_var, @variables[new_var]
|
95
|
+
end
|
65
96
|
end
|
data/lib/runit_command_helper.rb
CHANGED
@@ -21,7 +21,7 @@ end
|
|
21
21
|
#
|
22
22
|
# The methods are available through sv.<method name> in your deploy.rb
|
23
23
|
module RunitCommandHelper
|
24
|
-
SIGNALS = %w(up down once pause cont hup alarm interrupt quit usr1 usr2 term kill status)
|
24
|
+
SIGNALS = %w(up down once pause cont hup alarm interrupt quit usr1 usr2 term kill status) unless defined? SIGNALS
|
25
25
|
|
26
26
|
SIGNALS.each do |signal|
|
27
27
|
if signal =~ /usr([1|2])/ then
|
@@ -32,7 +32,7 @@ module RunitCommandHelper
|
|
32
32
|
|
33
33
|
define_method(signal) do |service_dirs|
|
34
34
|
service_dirs = service_dirs.join(" ") if service_dirs.is_a? Array
|
35
|
-
|
35
|
+
runit_helper.run_or_sudo "#{get_command(signal, cmd)} #{service_dirs}"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
data/lib/runit_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'capistrano'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'capistrano'
|
6
|
+
end
|
7
|
+
|
8
|
+
# This module provides a run_or_sudo helper method that checks what is should
|
9
|
+
# use before running a command
|
10
|
+
module RunitHelper
|
11
|
+
def run_or_sudo(command)
|
12
|
+
if configuration.runit_sudo_tasks.include? configuration.actor.current_task.name
|
13
|
+
sudo command
|
14
|
+
else
|
15
|
+
run command
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def find_caller
|
21
|
+
Kernel.caller.each do |caller_details|
|
22
|
+
if caller_details =~ /`(.*?)'$/
|
23
|
+
unless $1.nil? || %(run_or_sudo instance_eval initialize).include?($1)
|
24
|
+
break $1.intern
|
25
|
+
end
|
26
|
+
end
|
27
|
+
next
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Capistrano.plugin :runit_helper, RunitHelper
|
data/lib/runit_runner_helper.rb
CHANGED
@@ -14,8 +14,8 @@ module RunitRunnerHelper
|
|
14
14
|
#
|
15
15
|
# * service_dir should be the path to your service directory, it should not
|
16
16
|
# include run or log/run, these are added by create.
|
17
|
-
# * template can be :log, :fcgi, the name of a file or a string.
|
18
|
-
# :log and :fcgi create the standard
|
17
|
+
# * template can be :log, :mongrel, :fcgi, the name of a file or a string.
|
18
|
+
# :log, :mongrel and :fcgi create the standard templates,
|
19
19
|
# see get_template below for a list of places searched for template files.
|
20
20
|
# * If you're making a custom log runner, include :log_runner => true in the
|
21
21
|
# options so create knows to put the contents in service_dir/log/run, you
|
@@ -29,6 +29,8 @@ module RunitRunnerHelper
|
|
29
29
|
options.merge!(:log_runner => true)
|
30
30
|
when :fcgi
|
31
31
|
template = 'default_fcgi_runner'
|
32
|
+
when :mongrel
|
33
|
+
template = 'default_mongrel_runner'
|
32
34
|
end
|
33
35
|
|
34
36
|
path = "#{service_dir}/#{options[:log_runner] ? 'log/run' : 'run'}"
|
data/lib/runit_service_helper.rb
CHANGED
@@ -5,8 +5,6 @@ rescue LoadError
|
|
5
5
|
require 'capistrano'
|
6
6
|
end
|
7
7
|
|
8
|
-
require 'runit_runner_helper'
|
9
|
-
|
10
8
|
# This module provides an easy method to create service directories in your application and have them
|
11
9
|
# populated with runner scripts.
|
12
10
|
#
|
@@ -58,7 +56,7 @@ module RunitServiceHelper
|
|
58
56
|
end
|
59
57
|
|
60
58
|
def make_service_dir(service_name)
|
61
|
-
|
59
|
+
runit_helper.run_or_sudo "mkdir -p #{service_dir(service_name)}/log/main"
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|