capistrano-runit-tasks 0.2.4 → 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/{ChangeLog → CHANGELOG} +4 -9
- data/{README.txt → README} +8 -14
- data/lib/capistrano-runit-tasks.rb +39 -72
- data/lib/runit_command_helper.rb +2 -2
- data/lib/runit_helper.rb +3 -3
- data/lib/runit_runner_helper.rb +9 -4
- data/lib/runit_service_helper.rb +5 -7
- metadata +9 -8
data/{ChangeLog → CHANGELOG}
RENAMED
@@ -1,19 +1,14 @@
|
|
1
|
-
*
|
2
|
-
--------------------------------------------------
|
3
|
-
|
4
|
-
* Backport service_root patch
|
5
|
-
|
6
|
-
*0.2.3* (November 20th 2006)
|
1
|
+
*HEAD*
|
7
2
|
--------------------------------------------------
|
3
|
+
* Add service_root variable, to allow the service dir to live outside the deployment tree. [jon@zomo.co.uk]
|
8
4
|
|
9
5
|
* Add runit_sudo_tasks variable, array of symbols indicating tasks names to be
|
10
|
-
run using
|
6
|
+
run using try_sudo.
|
11
7
|
|
12
8
|
* Added support for mongrel, and basic mongrel runner template
|
13
9
|
|
14
10
|
* Changed fcgi_port and fcgi_listener_base_port to listener_port and
|
15
|
-
listener_base_port. Old variable names
|
16
|
-
deprecated.
|
11
|
+
listener_base_port. Old variable names not supported
|
17
12
|
|
18
13
|
*0.2.0* (March 23rd 2006)
|
19
14
|
--------------------------------------------------
|
data/{README.txt → README}
RENAMED
@@ -5,21 +5,13 @@ 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 has support fcgi and
|
8
|
+
it with run scripts. It has support fcgi, mongrel and merb 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.
|
14
|
-
release of the library. It
|
15
|
-
uses runit. It supports both the sv and runsvctrl/runsvstat versions of runit.
|
16
|
-
Support for daemontools svc command will be added at a later date.
|
17
|
-
|
18
|
-
The current version is based around a runit setup similar to the one created
|
19
|
-
in http://www.defendem.com/read/chapter/5#page6, i.e. a supervised directory
|
20
|
-
where links can be created to get tasks monitored. If your runit setup is
|
21
|
-
different, read below for the variables you can set in your deploy.rb to
|
22
|
-
handle this and let me know if there is something these can't handle.
|
13
|
+
capistrano-runit-tests 0.3.0 (known as cappy-runit from now on) is the third
|
14
|
+
release of the library. It supports both the sv and runsvctrl/runsvstat versions of runit.
|
23
15
|
|
24
16
|
== Quick Start
|
25
17
|
|
@@ -64,6 +56,10 @@ Then adds the following tasks, helpers and variables:
|
|
64
56
|
of the service directory in the app on the server(s).
|
65
57
|
(Default: service)
|
66
58
|
|
59
|
+
[service_root] Change this if you want to change the location
|
60
|
+
of the service directory.
|
61
|
+
(Default: Same as your deploy_to)
|
62
|
+
|
67
63
|
[master_service_dir] Supervised directory where cappy-runit will link the
|
68
64
|
service directories to to start the service.
|
69
65
|
(Default: ~/services)
|
@@ -83,9 +79,7 @@ Then adds the following tasks, helpers and variables:
|
|
83
79
|
[runit_sudo_tasks] Array of tasks names to run using sudo
|
84
80
|
(default: [])
|
85
81
|
|
86
|
-
cappy-runit creates a directory for each listener you ask for.
|
87
|
-
the directories are created by setup_service_dirs. Later versions should allow
|
88
|
-
for dynamic creation / deletion.
|
82
|
+
cappy-runit creates a service directory for each listener you ask for.
|
89
83
|
|
90
84
|
The directories are named after the port number the listener will run on. If
|
91
85
|
you specified 8500 for the base port and 3 for the listener_count then
|
@@ -4,94 +4,61 @@ require 'runit_runner_helper'
|
|
4
4
|
require 'runit_command_helper'
|
5
5
|
require 'runit_service_helper'
|
6
6
|
|
7
|
-
Capistrano.
|
7
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
8
8
|
set :service_dir, 'service'
|
9
9
|
set :listener_count, 1
|
10
10
|
set :listener_type, :mongrel
|
11
11
|
set :master_service_dir, '~/service'
|
12
|
-
set :service_root,
|
12
|
+
set :service_root, variables[:deploy_to]
|
13
13
|
set :listener_base_port, 9000
|
14
14
|
set :sv_command, :sv # can be :sv or :runsvctrl
|
15
15
|
set :runner_template_path, File.join('templates', 'runit')
|
16
16
|
set :runit_sudo_tasks, []
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
namespace :deploy do
|
19
|
+
desc "Sets up services directories for supervising listeners using runit"
|
20
|
+
task :setup_service_dirs do
|
21
|
+
handle_deprecated_vars
|
22
|
+
application_service_dir = "#{service_root}/#{service_dir}"
|
23
|
+
runit_helper.run_or_sudo "mkdir -p #{application_service_dir}"
|
24
|
+
|
25
|
+
each_listener do |listener_port|
|
26
|
+
# DEPRECATION: Need to pass port and fcgi_port to handle old templates, fcgi_port is considered deprecated
|
27
|
+
service.add listener_port, :template => listener_type, :listener_port => listener_port, :fcgi_port => listener_port
|
28
|
+
end
|
28
29
|
end
|
29
|
-
spinner
|
30
|
-
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# DEPRECATION: Need to pass port and fcgi_port to handle old templates, fcgi_port is considered deprecated
|
40
|
-
service.add listener_port, :template => listener_type, :listener_port => listener_port, :fcgi_port => listener_port
|
31
|
+
desc "Links created service dir into master service dir so runit starts the listeners"
|
32
|
+
task :start, :roles => :app do
|
33
|
+
handle_deprecated_vars
|
34
|
+
each_listener do |listener_port|
|
35
|
+
service_dir = "#{service_root}/#{service_dir}/#{listener_port}"
|
36
|
+
runit_helper.run_or_sudo "ln -nsf #{service_dir} #{master_service_dir}/#{application}-#{listener_port}"
|
37
|
+
end
|
41
38
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
each_listener do |listener_port|
|
48
|
-
service_dir = "#{service_root}/#{service_dir}/#{fcgi_listener_port}"
|
49
|
-
runit_helper.run_or_sudo "ln -sf #{service_dir} #{master_service_dir}/#{application}-#{listener_port}"
|
39
|
+
|
40
|
+
desc "restart task for runit supervised listeners"
|
41
|
+
task :restart, :roles => :app do
|
42
|
+
handle_deprecated_vars
|
43
|
+
sv.usr2 listener_dirs
|
50
44
|
end
|
51
|
-
end
|
52
|
-
|
53
|
-
desc "restart task for runit supervised listeners"
|
54
|
-
task :restart, :roles => :app do
|
55
|
-
handle_deprecated_vars
|
56
|
-
sv.usr2 listener_dirs
|
57
|
-
end
|
58
|
-
|
59
|
-
desc "Hook into after setup to create the runit service directory"
|
60
|
-
task :after_setup do
|
61
|
-
handle_deprecated_vars
|
62
|
-
setup_service_dirs
|
63
|
-
end
|
64
45
|
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
desc "Hook into after setup to create the runit service directory"
|
47
|
+
task :after_setup do
|
48
|
+
handle_deprecated_vars
|
49
|
+
setup_service_dirs
|
68
50
|
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def listener_dirs
|
72
|
-
dirs = []
|
73
|
-
each_listener { |port| dirs << "#{service_root}/#{service_dir}/#{port}" }
|
74
|
-
dirs
|
75
|
-
end
|
76
|
-
|
77
|
-
## DEPRECATED - and alias_method won't work inside the instance_eval this is run in
|
78
|
-
def each_fcgi_listener
|
79
|
-
each_listener { |listener_port| yield listener_port }
|
80
|
-
end
|
81
51
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if @variables.has_key?(old_var)
|
93
|
-
set new_var, @variables[old_var]
|
52
|
+
def each_listener
|
53
|
+
listener_base_port.upto(listener_base_port + listener_count - 1) do |listener_port|
|
54
|
+
yield listener_port
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def listener_dirs
|
59
|
+
dirs = []
|
60
|
+
each_listener { |port| dirs << "#{service_root}/#{service_dir}/#{port}" }
|
61
|
+
dirs
|
94
62
|
end
|
95
|
-
set old_var, @variables[new_var]
|
96
63
|
end
|
97
64
|
end
|
data/lib/runit_command_helper.rb
CHANGED
@@ -38,13 +38,13 @@ module RunitCommandHelper
|
|
38
38
|
|
39
39
|
protected
|
40
40
|
def get_command(signal, cmd)
|
41
|
-
case
|
41
|
+
case self.sv_command
|
42
42
|
when :sv
|
43
43
|
"sv #{cmd}"
|
44
44
|
when :runsvctrl
|
45
45
|
signal == 'status' ? 'runsvstat' : "runsvctrl #{cmd}"
|
46
46
|
else
|
47
|
-
raise "Error: sv_command setting of #{
|
47
|
+
raise "Error: sv_command setting of #{self.sv_command} is unsupported"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/runit_helper.rb
CHANGED
@@ -9,8 +9,8 @@ end
|
|
9
9
|
# use before running a command
|
10
10
|
module RunitHelper
|
11
11
|
def run_or_sudo(command)
|
12
|
-
if
|
13
|
-
|
12
|
+
if self.current_task && self.runit_sudo_tasks.include?(self.current_task.name)
|
13
|
+
try_sudo command
|
14
14
|
else
|
15
15
|
run command
|
16
16
|
end
|
@@ -29,4 +29,4 @@ module RunitHelper
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
Capistrano.plugin :runit_helper, RunitHelper
|
32
|
+
Capistrano.plugin :runit_helper, RunitHelper
|
data/lib/runit_runner_helper.rb
CHANGED
@@ -4,6 +4,7 @@ rescue LoadError
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'capistrano'
|
6
6
|
end
|
7
|
+
require 'erb'
|
7
8
|
|
8
9
|
# This module provides methods to ease creating run scripts in service directories.
|
9
10
|
#
|
@@ -37,8 +38,12 @@ module RunitRunnerHelper
|
|
37
38
|
options.delete(:log_runner)
|
38
39
|
|
39
40
|
options = add_default_options(options)
|
40
|
-
|
41
|
-
|
41
|
+
b = Proc.new { binding }.call
|
42
|
+
options.each do |key, value|
|
43
|
+
next if key == :template
|
44
|
+
eval "#{key} = options[:#{key}]", b
|
45
|
+
end
|
46
|
+
runner = ERB.new(get_template(template)).result(b)
|
42
47
|
|
43
48
|
put runner, path, :mode => 0700
|
44
49
|
end
|
@@ -58,7 +63,7 @@ module RunitRunnerHelper
|
|
58
63
|
template
|
59
64
|
else
|
60
65
|
[ ".",
|
61
|
-
|
66
|
+
self.runner_template_path,
|
62
67
|
File.join(File.dirname(__FILE__), 'capistrano-runit-tasks-templates')
|
63
68
|
].each do |dir|
|
64
69
|
if File.file?(File.join(dir, template))
|
@@ -74,7 +79,7 @@ module RunitRunnerHelper
|
|
74
79
|
|
75
80
|
protected
|
76
81
|
def add_default_options(options)
|
77
|
-
{:deploy_to =>
|
82
|
+
{:deploy_to => self.deploy_to}.merge(options)
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
data/lib/runit_service_helper.rb
CHANGED
@@ -31,16 +31,14 @@ module RunitServiceHelper
|
|
31
31
|
|
32
32
|
# Returns the full path to the service directory given a service name.
|
33
33
|
# Doesn't check the service name is valid.
|
34
|
-
def
|
35
|
-
"#{
|
34
|
+
def service_path(service_name)
|
35
|
+
"#{self.service_root}/#{self.service_dir}/#{service_name}"
|
36
36
|
end
|
37
37
|
|
38
38
|
protected
|
39
39
|
def create_service(service_name, options)
|
40
|
-
template_base = options[:common_template] ? options[:common_template] : service_name.to_s
|
41
|
-
options.delete(:shared_template)
|
42
40
|
if options[:template].nil?
|
43
|
-
runner_template_path = options[:log_runner] ? "#{
|
41
|
+
runner_template_path = options[:log_runner] ? "#{service_name.to_s}_log_runner" : "#{service_name.to_s}_runner"
|
44
42
|
runner_template = runner.get_template(runner_template_path)
|
45
43
|
if runner_template == runner_template_path # didn't find a template
|
46
44
|
if options[:log_runner]
|
@@ -54,11 +52,11 @@ module RunitServiceHelper
|
|
54
52
|
runner_template = options[:template]
|
55
53
|
end
|
56
54
|
options.delete(:template)
|
57
|
-
runner.create
|
55
|
+
runner.create service_path(service_name), runner_template, options
|
58
56
|
end
|
59
57
|
|
60
58
|
def make_service_dir(service_name)
|
61
|
-
runit_helper.run_or_sudo "mkdir -p #{
|
59
|
+
runit_helper.run_or_sudo "mkdir -p #{service_path(service_name)}/log/main"
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-runit-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: -1876988176
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
9
|
+
- 0
|
10
|
+
- pre1
|
11
|
+
version: 1.0.0.pre1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Chris McGrath
|
@@ -23,7 +24,7 @@ dependencies: []
|
|
23
24
|
description: This library extends Capistrano to allow processes to be supervised using the runit package. It replaces some of the standard tasks with runit versions and includes tasks and helpers to create the service directory layout and populate it with run scripts. It has support fcgi, mongrel and merb listeners, and tries to make it easy to add other services in your deploy.rb.
|
24
25
|
email:
|
25
26
|
- chris@octopod.info
|
26
|
-
-
|
27
|
+
- ""
|
27
28
|
executables: []
|
28
29
|
|
29
30
|
extensions: []
|
@@ -39,8 +40,8 @@ files:
|
|
39
40
|
- lib/runit_helper.rb
|
40
41
|
- lib/runit_runner_helper.rb
|
41
42
|
- lib/runit_service_helper.rb
|
42
|
-
- README
|
43
|
-
-
|
43
|
+
- README
|
44
|
+
- CHANGELOG
|
44
45
|
has_rdoc: true
|
45
46
|
homepage: http://github.com/chrismcg/cappy-runit
|
46
47
|
licenses: []
|