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
@@ -0,0 +1,38 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
begin
|
5
|
+
require 'capistrano'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'capistrano'
|
9
|
+
end
|
10
|
+
|
11
|
+
class CappyRunitTasksConfigurationTest < Test::Unit::TestCase
|
12
|
+
class MockActor
|
13
|
+
attr_reader :tasks
|
14
|
+
|
15
|
+
def initialize(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def define_task(*args, &block)
|
19
|
+
(@tasks ||= []).push [args, block].flatten
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup
|
24
|
+
@config = Capistrano::Configuration.new(MockActor)
|
25
|
+
file = File.dirname(__FILE__) + "/fixtures/runit_config.rb"
|
26
|
+
@config.load file
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_include_capistrano_runit_tasks
|
30
|
+
assert task_names(@config.actor.tasks).include?(:setup_service_dirs)
|
31
|
+
end
|
32
|
+
|
33
|
+
def task_names(tasks)
|
34
|
+
tasks.map { |task| task[0] }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RunitCommandHelperTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
SIGNALS = %w(up down once pause cont hup alarm interrupt quit usr1 usr2 term kill)
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@actor = TestActor.new(MockConfiguration.new)
|
10
|
+
@actor.configuration.set :runit_sudo_tasks, []
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_load_runit_runner_helper
|
14
|
+
assert Capistrano.const_get(:EXTENSIONS).include?(:sv)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_raise_error_if_sv_command_set_to_invalid_value
|
18
|
+
@actor.configuration.set :sv_command, :foo_bar
|
19
|
+
assert_raises(RuntimeError) { @actor.sv.down "foo" }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_generate_correct_commands_for_sv
|
23
|
+
@actor.configuration.set :sv_command, :sv
|
24
|
+
|
25
|
+
SIGNALS.each_with_index do |signal, i|
|
26
|
+
@actor.sv.send(signal, "foo")
|
27
|
+
if signal =~ /usr([1|2])/
|
28
|
+
assert_equal "sv #{$1} foo", @actor.run_data[i]
|
29
|
+
else
|
30
|
+
assert_equal "sv #{signal} foo", @actor.run_data[i]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@actor.reset!
|
35
|
+
@actor.sv.status "foo"
|
36
|
+
assert_equal "sv status foo", @actor.run_data[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_generate_correct_commands_for_runsvctrl
|
40
|
+
@actor.configuration.set :sv_command, :runsvctrl
|
41
|
+
|
42
|
+
SIGNALS.each_with_index do |signal, i|
|
43
|
+
@actor.sv.send(signal, "foo")
|
44
|
+
if signal =~ /usr([1|2])/
|
45
|
+
assert_equal "runsvctrl #{$1} foo", @actor.run_data[i]
|
46
|
+
else
|
47
|
+
assert_equal "runsvctrl #{signal} foo", @actor.run_data[i]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
@actor.reset!
|
52
|
+
@actor.sv.status "foo"
|
53
|
+
assert_equal "runsvstat foo", @actor.run_data[0]
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_accept_array_of_service_directions
|
57
|
+
@actor.configuration.set :sv_command, :sv
|
58
|
+
@actor.sv.down %w(foo bar)
|
59
|
+
assert_equal "sv down foo bar", @actor.run_data[0]
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RunitHelperTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@actor = MockConfiguration.new.actor
|
8
|
+
@actor.configuration.set :runner_template_path, File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
@actor.configuration.set :deploy_to, 'app_dir'
|
10
|
+
@actor.configuration.set :service_dir, 'service'
|
11
|
+
@actor.configuration.set :runit_sudo_tasks, [:sudo_task]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_run_command
|
15
|
+
@actor.send :run_task
|
16
|
+
assert_equal "run", @actor.run_data[0]
|
17
|
+
assert_nil @actor.sudo_data
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_sudo_command
|
21
|
+
@actor.send :sudo_task
|
22
|
+
assert_equal "sudo", @actor.sudo_data[0]
|
23
|
+
assert_nil @actor.run_data
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RunitRunnerHelperTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@actor = TestActor.new(MockConfiguration.new)
|
8
|
+
@actor.configuration.set :runner_template_path, File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
@actor.configuration.set :deploy_to, 'app_dir'
|
10
|
+
@actor.configuration.set :runit_sudo_tasks, []
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_load_runit_runner_helper
|
14
|
+
assert Capistrano.const_get(:EXTENSIONS).include?(:runner)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_create_default_fcgi_runner
|
18
|
+
@actor.runner.create 'test/output', :fcgi, :listener_port => 8000
|
19
|
+
assert_equal File.read("#{File.dirname(__FILE__)}/fixtures/standard_fcgi_runner"), @actor.put_data['test/output/run']
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_create_default_mongrel_runner
|
23
|
+
@actor.runner.create 'test/output', :mongrel, :listener_port => 8000
|
24
|
+
assert_equal File.read("#{File.dirname(__FILE__)}/fixtures/standard_mongrel_runner"), @actor.put_data['test/output/run']
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_create_custom_runner
|
28
|
+
custom_runner = "<%= foo %>"
|
29
|
+
@actor.runner.create 'test/output', custom_runner, :foo => 'bar'
|
30
|
+
assert_equal 'bar', @actor.put_data['test/output/run']
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_create_log_runner
|
34
|
+
@actor.runner.create 'test/output', :log
|
35
|
+
assert_equal File.read("#{File.dirname(__FILE__)}/fixtures/log_runner"), @actor.put_data['test/output/log/run']
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_create_custom_log_runnner
|
39
|
+
custom_runner = "<%= foo %>"
|
40
|
+
@actor.runner.create 'test/output', custom_runner, :log_runner => true, :foo => 'bar'
|
41
|
+
assert_equal 'bar', @actor.put_data['test/output/log/run']
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_create_runner_from_file_template
|
45
|
+
@actor.runner.create 'test/output', 'test_runner', :listener_port => 8000
|
46
|
+
assert_equal File.read("#{File.dirname(__FILE__)}/fixtures/standard_fcgi_runner"), @actor.put_data['test/output/run']
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_create_log_runner_from_log_file_template
|
50
|
+
@actor.runner.create 'test/output', 'test_log_runner', :log_runner => true
|
51
|
+
assert_equal File.read("#{File.dirname(__FILE__)}/fixtures/log_runner"), @actor.put_data['test/output/log/run']
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RunitRunnerServiceTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@actor = TestActor.new(MockConfiguration.new)
|
8
|
+
@actor.configuration.set :runner_template_path, File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
@actor.configuration.set :deploy_to, 'app_dir'
|
10
|
+
@actor.configuration.set :service_dir, 'service'
|
11
|
+
@actor.configuration.set :runit_sudo_tasks, []
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_create_new_service_using_standard_files
|
15
|
+
@actor.service.add 'test_service'
|
16
|
+
assert_equal 'mkdir -p app_dir/service/test_service/log/main', @actor.run_data[0]
|
17
|
+
assert_equal "#!/bin/sh\nrun me", @actor.put_data['app_dir/service/test_service/run'], @actor.put_data.inspect
|
18
|
+
assert_equal "#!/bin/sh\nlog me", @actor.put_data['app_dir/service/test_service/log/run'], @actor.put_data.inspect
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_raise_exception_if_no_runner_template_exists
|
22
|
+
assert_raises(RuntimeError) { @actor.service.add 'foo' }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_create_new_service_with_standard_logger_if_logger_template_does_not_exist
|
26
|
+
@actor.service.add 'custom_runner_service'
|
27
|
+
assert_equal 'mkdir -p app_dir/service/custom_runner_service/log/main', @actor.run_data[0]
|
28
|
+
assert_equal "#!/bin/sh\nrun me", @actor.put_data['app_dir/service/custom_runner_service/run'], @actor.put_data.inspect
|
29
|
+
assert_equal "#!/bin/sh -e\nexec svlogd -t ./main\n", @actor.put_data['app_dir/service/custom_runner_service/log/run'], @actor.put_data.inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_create_new_service_with_custom_runner_template
|
33
|
+
@actor.service.add 'custom_runner_service', :template => "custom runner\n"
|
34
|
+
assert_equal 'mkdir -p app_dir/service/custom_runner_service/log/main', @actor.run_data[0]
|
35
|
+
assert_equal "custom runner\n", @actor.put_data['app_dir/service/custom_runner_service/run'], @actor.put_data.inspect
|
36
|
+
assert_equal "#!/bin/sh -e\nexec svlogd -t ./main\n", @actor.put_data['app_dir/service/custom_runner_service/log/run'], @actor.put_data.inspect
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_create_new_service_with_custom_logger_template
|
40
|
+
@actor.service.add 'custom_logger_service', { :template => "custom runner\n" }, { :template => "custom logger\n" }
|
41
|
+
assert_equal 'mkdir -p app_dir/service/custom_logger_service/log/main', @actor.run_data[0]
|
42
|
+
assert_equal "custom runner\n", @actor.put_data['app_dir/service/custom_logger_service/run'], @actor.put_data.inspect
|
43
|
+
assert_equal "custom logger\n", @actor.put_data['app_dir/service/custom_logger_service/log/run'], @actor.put_data.inspect
|
44
|
+
end
|
45
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
begin
|
2
|
+
require 'capistrano'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'capistrano'
|
6
|
+
end
|
7
|
+
require 'test/unit'
|
8
|
+
$:.unshift File.dirname(__FILE__) + "/../lib", File.dirname(__FILE__)
|
9
|
+
require 'runit_helper'
|
10
|
+
|
11
|
+
module TestHelper
|
12
|
+
class TestingConnectionFactory
|
13
|
+
def initialize(config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect_to(server)
|
17
|
+
server
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestActor < Capistrano::Actor
|
22
|
+
class TestTask
|
23
|
+
attr_reader :name
|
24
|
+
|
25
|
+
def initialize(name)
|
26
|
+
@name = name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :put_data, :run_data, :sudo_data
|
31
|
+
|
32
|
+
def initialize(*args)
|
33
|
+
super
|
34
|
+
@current_task = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def run(cmd, options={}, &block)
|
38
|
+
(@run_data ||= []) << cmd
|
39
|
+
end
|
40
|
+
|
41
|
+
def sudo(cmd, options={}, &block)
|
42
|
+
(@sudo_data ||= []) << cmd
|
43
|
+
end
|
44
|
+
|
45
|
+
def put(data, path, options={})
|
46
|
+
(@put_data ||= {})[path] = data
|
47
|
+
end
|
48
|
+
|
49
|
+
def metaclass
|
50
|
+
class << self; self; end
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_task
|
54
|
+
@current_task || TestTask.new("")
|
55
|
+
end
|
56
|
+
|
57
|
+
def define_method(name, &block)
|
58
|
+
metaclass.send(:define_method, name, &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def define_task(name, options={}, &block)
|
62
|
+
@tasks[name] = (options[:task_class] || Task).new(name, self, options)
|
63
|
+
define_method(name) do
|
64
|
+
@current_task = TestTask.new(name)
|
65
|
+
instance_eval(&block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
self.connection_factory = TestingConnectionFactory
|
70
|
+
|
71
|
+
def reset!
|
72
|
+
@put_data = {}
|
73
|
+
@run_data = []
|
74
|
+
@sudo_data = []
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class MockConfiguration
|
79
|
+
attr_reader :actor
|
80
|
+
|
81
|
+
def initialize(actor_class=TestActor)
|
82
|
+
@variables = {}
|
83
|
+
@actor = actor_class.new(self)
|
84
|
+
instance_eval <<-TASKS
|
85
|
+
task :run_task do
|
86
|
+
runit_helper.run_or_sudo("run")
|
87
|
+
end
|
88
|
+
|
89
|
+
task :sudo_task do
|
90
|
+
runit_helper.run_or_sudo("sudo")
|
91
|
+
end
|
92
|
+
TASKS
|
93
|
+
end
|
94
|
+
|
95
|
+
def set(variable, value = nil)
|
96
|
+
@variables[variable] = value
|
97
|
+
end
|
98
|
+
|
99
|
+
def task(name, options={}, &block)
|
100
|
+
actor.define_task(name, options, &block)
|
101
|
+
end
|
102
|
+
|
103
|
+
Role = Struct.new(:host, :options)
|
104
|
+
|
105
|
+
ROLES = {
|
106
|
+
:db => [ Role.new("01.example.com", :primary => true)],
|
107
|
+
:web => [ Role.new("01.example.com", {})],
|
108
|
+
:app => [ Role.new("01.example.com", {})]
|
109
|
+
}
|
110
|
+
|
111
|
+
def roles
|
112
|
+
ROLES
|
113
|
+
end
|
114
|
+
|
115
|
+
def method_missing(sym, *args, &block)
|
116
|
+
if @variables.has_key?(sym)
|
117
|
+
@variables[sym]
|
118
|
+
else
|
119
|
+
super
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: capistrano-runit-tasks
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2006-
|
8
|
-
summary: Adds tasks to
|
6
|
+
version: 0.2.3
|
7
|
+
date: 2006-11-20 00:00:00 +00:00
|
8
|
+
summary: Adds tasks to Capistrano for use with the runit supervision scheme.
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: chris@octopod.info
|
12
12
|
homepage: http://cappy-runit.rubyforge.org
|
13
13
|
rubyforge_project: cappy-runit
|
14
|
-
description:
|
15
|
-
autorequire:
|
14
|
+
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 and mongrel listeners, and tries to make it easy to add other services in your deploy.rb.
|
15
|
+
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
27
26
|
signing_key:
|
28
27
|
cert_chain:
|
28
|
+
post_install_message:
|
29
29
|
authors:
|
30
|
-
|
30
|
+
- Chris McGrath
|
31
31
|
files:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
32
|
+
- ChangeLog
|
33
|
+
- Manifest.txt
|
34
|
+
- README
|
35
|
+
- Rakefile
|
36
|
+
- lib/capistrano-runit-tasks-templates/default_fcgi_runner.rhtml
|
37
|
+
- lib/capistrano-runit-tasks-templates/default_log_runner.rhtml
|
38
|
+
- lib/capistrano-runit-tasks-templates/default_mongrel_runner.rhtml
|
39
|
+
- lib/capistrano-runit-tasks.rb
|
40
|
+
- lib/runit_command_helper.rb
|
41
|
+
- lib/runit_helper.rb
|
42
|
+
- lib/runit_runner_helper.rb
|
43
|
+
- lib/runit_service_helper.rb
|
44
|
+
- setup.rb
|
45
|
+
- test/capistrano-runit-tasks_test.rb
|
46
|
+
- test/fixtures/log_runner
|
47
|
+
- test/fixtures/runit_config.rb
|
48
|
+
- test/fixtures/standard_fcgi_runner
|
49
|
+
- test/fixtures/standard_mongrel_runner
|
50
|
+
- test/runit_command_helper_test.rb
|
51
|
+
- test/runit_helper_test.rb
|
52
|
+
- test/runit_runner_helper_test.rb
|
53
|
+
- test/runit_service_helper_test.rb
|
54
|
+
- test/templates/custom_runner_service_runner
|
55
|
+
- test/templates/test_log_runner
|
56
|
+
- test/templates/test_runner.rhtml
|
57
|
+
- test/templates/test_service_log_runner
|
58
|
+
- test/templates/test_service_runner
|
59
|
+
- test/test_helper.rb
|
60
|
+
test_files:
|
61
|
+
- test/capistrano-runit-tasks_test.rb
|
62
|
+
- test/runit_command_helper_test.rb
|
63
|
+
- test/runit_helper_test.rb
|
64
|
+
- test/runit_runner_helper_test.rb
|
65
|
+
- test/runit_service_helper_test.rb
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
extra_rdoc_files: []
|
69
|
+
|
50
70
|
executables: []
|
71
|
+
|
51
72
|
extensions: []
|
73
|
+
|
52
74
|
requirements: []
|
75
|
+
|
53
76
|
dependencies:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: hoe
|
79
|
+
version_requirement:
|
80
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.1.4
|
85
|
+
version:
|
86
|
+
type: :development
|