fujin-mongrel_runit 0.2.1

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,153 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "mongrel_runit/config"
4
+ require "mongrel_runit/service"
5
+ require "find"
6
+
7
+ class TestMongrelRunitService < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @config = {
11
+ "port" => "8191",
12
+ "address" => "127.0.0.1",
13
+ "servers" => "2",
14
+ "environment" => "production",
15
+ "cwd" => File.dirname(__FILE__) + '/testapp',
16
+ "num_procs" => "1024",
17
+ #"user" => "www-data",
18
+ #"group" => "www-data",
19
+ "runit_sv_dir" => File.dirname(__FILE__) + "/sv",
20
+ "runit_service_dir" => File.dirname(__FILE__) + "/service",
21
+ "application_name" => "monkey",
22
+ "svlogd_config" => <<EOH
23
+ s100000
24
+ n100
25
+ EOH
26
+ }
27
+ @service = MongrelRunit::Service.new(@config)
28
+ end
29
+
30
+ def teardown
31
+ cleanup
32
+ end
33
+
34
+ def test_service_create
35
+ assert_equal(MongrelRunit::Service, @service.class, "Got the right object")
36
+ end
37
+
38
+ def test_run_testapp
39
+ @service.create
40
+ if ENV["RUNSVTEST"]
41
+ sleep 5
42
+ output, status = @service.start
43
+ assert(status, "Service Start")
44
+ ouput, status = @service.stop
45
+ assert(status, "Service Stop")
46
+ output, status = @service.start
47
+ assert(status, "Service Start")
48
+ end
49
+ end
50
+
51
+ def test_make_service_link
52
+ @service.create
53
+ link = @service.make_service_link
54
+ assert(File.symlink?(link), "Created service symlink")
55
+ end
56
+
57
+ def test_make_sv_dir
58
+ svlogdir = @service.make_sv_dir
59
+ assert(File.directory?(svlogdir), "Created sv directory")
60
+ end
61
+
62
+ def test_check_service_dir
63
+ dir_exists = @service.check_service_dir
64
+ assert(dir_exists, "Has a service directory")
65
+ end
66
+
67
+ def test_make_log
68
+ runlog = @service.make_log
69
+ assert_equal(@service.logrunfile, IO.read(runlog), "log/run file created")
70
+ assert(File.executable?(runlog), "log/run file executable")
71
+ end
72
+
73
+ def test_make_check
74
+ checkfile = @service.make_check
75
+ assert_equal(@service.checkfile, IO.read(checkfile), "check file created")
76
+ assert(File.executable?(checkfile), "check file executable")
77
+ new_config = @config.dup
78
+ new_config["checkfile"] = <<EOH
79
+ foo #{@config['address']} #{@config['port']}
80
+ EOH
81
+ config_service = MongrelRunit::Service.new(new_config)
82
+ checkfile = config_service.make_check
83
+ assert_equal("foo 127.0.0.1 8191\n", config_service.checkfile)
84
+ end
85
+
86
+ def test_make_log_config
87
+ logconfig = @service.make_log_config
88
+ assert_equal(@service.logconfig, IO.read(logconfig)) if logconfig
89
+ end
90
+
91
+ def test_make_run
92
+ no_env_runfile = @service.make_run
93
+ no_env_file = <<EOH
94
+ #!/bin/sh
95
+ exec \\
96
+ mongrel_rails start -e production -p 8191 -a 127.0.0.1 -c #{File.dirname(__FILE__) + '/testapp'} -n 1024 2>&1
97
+ EOH
98
+ env_file = <<EOH
99
+ #!/bin/sh
100
+ exec \\
101
+ env PATH=$PATH:/var/lib/gems/1.8 \\
102
+ mongrel_rails start -e production -p 8191 -a 127.0.0.1 -c #{File.dirname(__FILE__) + '/testapp'} -n 1024 2>&1
103
+ EOH
104
+ command_line_file = <<EOH
105
+ #!/bin/sh
106
+ exec \\
107
+ moofyboogles -p 8191 2>&1
108
+ EOH
109
+ chpst_path = `which chpst`.chomp
110
+ chpst_file = <<EOH
111
+ #!/bin/sh
112
+ exec \\
113
+ #{chpst_path} -o 3365 \\
114
+ mongrel_rails start -e production -p 8191 -a 127.0.0.1 -c #{File.dirname(__FILE__) + '/testapp'} -n 1024 2>&1
115
+ EOH
116
+ assert_equal(no_env_file, @service.runfile)
117
+ assert_equal(@service.runfile, IO.read(no_env_runfile))
118
+
119
+ env_config = @config.dup
120
+ env_config["env_vars"] = { "PATH" => "$PATH:/var/lib/gems/1.8" }
121
+ env_service = MongrelRunit::Service.new(env_config)
122
+ env_service_runfile = env_service.make_run
123
+ assert_equal(env_file, env_service.runfile)
124
+ assert_equal(env_service.runfile, IO.read(env_service_runfile))
125
+ assert(File.executable?(env_service_runfile), "run file executable")
126
+
127
+ chpst_config = @config.dup
128
+ chpst_config["chpst"] = "-o 3365"
129
+ chpst_service = MongrelRunit::Service.new(chpst_config)
130
+ chpst_service_runfile = chpst_service.make_run
131
+ assert_equal(chpst_file, chpst_service.runfile)
132
+ assert_equal(chpst_service.runfile, IO.read(chpst_service_runfile))
133
+ assert(File.executable?(chpst_service_runfile), "run file executable")
134
+
135
+ command_line_config = @config.dup
136
+ command_line_config["command_line"] = 'moofyboogles -p #{@config["port"]}'
137
+ command_line_service = MongrelRunit::Service.new(command_line_config)
138
+ command_line_runfile = command_line_service.make_run
139
+ assert_equal(command_line_file, command_line_service.runfile, "Command line runfile works")
140
+ assert_equal(command_line_service.runfile, IO.read(command_line_runfile), "Command line generated file works")
141
+ end
142
+
143
+ def cleanup
144
+ Find.find(@config["runit_sv_dir"], @config["runit_service_dir"]) do |file|
145
+ if File.directory?(file) || File.symlink?(file)
146
+ if File.basename(file) =~ /(.+)-(\d+)/
147
+ `rm -r #{file}`
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "mongrel_runit/servicerunner"
4
+ require "find"
5
+
6
+ class TestMongrelRunitServiceRunner < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @config = {
10
+ "port" => "8191",
11
+ "address" => "127.0.0.1",
12
+ "servers" => "2",
13
+ "environment" => "production",
14
+ "cwd" => File.dirname(__FILE__) + '/testapp',
15
+ "num_procs" => "1024",
16
+ #"user" => "www-data",
17
+ #"group" => "www-data",
18
+ "runit_sv_dir" => File.dirname(__FILE__) + "/sv",
19
+ "runit_service_dir" => File.dirname(__FILE__) + "/service",
20
+ "application_name" => "monkey",
21
+ "svlogd_config" => <<EOH
22
+ s100000
23
+ n100
24
+ EOH
25
+ }
26
+ @servicerunner = MongrelRunit::ServiceRunner.new(@config)
27
+ end
28
+
29
+ def teardown
30
+ cleanup
31
+ end
32
+
33
+ def test_service_create
34
+ assert_equal(MongrelRunit::ServiceRunner, @servicerunner.class, "Got the right object")
35
+ end
36
+
37
+ def test_create
38
+ result, status = @servicerunner.create
39
+ @servicerunner.each do |service|
40
+ assert(result.has_key?(service.config["port"]), "Created #{service.config['port']}")
41
+ assert(File.directory?(service.svdir), "Created svdir")
42
+ end
43
+ end
44
+
45
+ def test_run_start
46
+ if ENV["RUNSVTEST"]
47
+ result, status = @servicerunner.create
48
+ assert(status, "Created for each service")
49
+ sleep 5
50
+ result, status = @servicerunner.start
51
+ assert(status, "Started each service")
52
+ end
53
+ end
54
+
55
+ def test_run_stop
56
+ if ENV["RUNSVTEST"]
57
+ result, status = @servicerunner.create
58
+ assert(status, "Created each service")
59
+ sleep 5
60
+ result, status = @servicerunner.stop
61
+ assert(status, "Stopped each service")
62
+ end
63
+ end
64
+
65
+ def cleanup
66
+ Find.find(@config["runit_sv_dir"], @config["runit_service_dir"]) do |file|
67
+ if File.directory?(file) || File.symlink?(file)
68
+ if File.basename(file) =~ /mongrel-(.+)-(\d+)/
69
+ `rm -r #{file}`
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ $:.unshift( File.join( File.dirname(__FILE__), "..", "lib" ) )
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestMongrelRunit < Test::Unit::TestCase
4
+
5
+
6
+ def test_truth
7
+ assert true
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fujin-mongrel_runit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Jacob
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-10 00:00:00 -07:00
13
+ default_executable: mongrel_runit
14
+ dependencies: []
15
+
16
+ description: Use runit to manage a mongrel cluster
17
+ email: adam@hjksolutions.com
18
+ executables:
19
+ - mongrel_runit
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGELOG.txt
24
+ - History.txt
25
+ - Manifest.txt
26
+ - README.txt
27
+ files:
28
+ - lib/mongrel_runit/base.rb
29
+ - lib/mongrel_runit/cli.rb
30
+ - lib/mongrel_runit/config.rb
31
+ - lib/mongrel_runit/service.rb
32
+ - lib/mongrel_runit/servicerunner.rb
33
+ - lib/mongrel_runit/version.rb
34
+ - lib/mongrel_runit.rb
35
+ - bin/mongrel_runit
36
+ - CHANGELOG.txt
37
+ - History.txt
38
+ - LICENSE
39
+ - Manifest.txt
40
+ - Rakefile
41
+ - README.txt
42
+ - test/config
43
+ - test/config/mongrel_runit.yml
44
+ - test/config/mongrel_runit_service.yml
45
+ - test/tc_config.rb
46
+ - test/tc_service.rb
47
+ - test/tc_servicerunner.rb
48
+ - test/test_helper.rb
49
+ - test/test_mongrel_runit.rb
50
+ has_rdoc: true
51
+ homepage: https://wiki.hjksolutions.com/display/MR/Home
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --main
55
+ - README.txt
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: mongrel_runit
73
+ rubygems_version: 1.2.0
74
+ signing_key:
75
+ specification_version: 2
76
+ summary: Use runit to manage a mongrel cluster
77
+ test_files: []
78
+