daemons-rails 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/README +23 -1
- data/daemons-rails.gemspec +1 -0
- data/lib/daemons/rails/controller.rb +28 -0
- data/lib/daemons/rails/monitoring.rb +14 -21
- data/lib/daemons/rails/version.rb +1 -1
- data/lib/generators/templates/script.rb +1 -1
- data/spec/fixtures/config/daemons.yml +6 -0
- data/spec/fixtures/lib/daemons/test.rb +1 -0
- data/spec/fixtures/lib/daemons/test_ctl +1 -0
- data/spec/lib/daemons/rails/monitoring_spec.rb +37 -0
- data/spec/spec_helper.rb +11 -0
- metadata +30 -12
data/.rspec
ADDED
data/README
CHANGED
@@ -11,6 +11,7 @@ Then insert your code in the lib/daemons/<name>.rb stub. All pids and logs will
|
|
11
11
|
|
12
12
|
== CHANGES ==
|
13
13
|
|
14
|
+
1.0.0 - changed api for Daemons::Rails::Monitoring, fixed path in template for script, improved documentation, added RSpec
|
14
15
|
0.0.3 - added rake for running script without daemonization (rake daemon:<name>)
|
15
16
|
|
16
17
|
== CONTROL ==
|
@@ -19,6 +20,27 @@ Individual control script:
|
|
19
20
|
> ./lib/daemons/<name>_ctl [start|stop|restart|status]
|
20
21
|
> rake daemon:<name>[:(start|stop|status)]
|
21
22
|
|
23
|
+
Examples:
|
24
|
+
rake daemon:test - runs lib/daemons/test.rb not daemonized
|
25
|
+
rake daemon:test:start - start daemon using lib/daemons/test_ctl start
|
26
|
+
rake daemon:test:stop - stop daemon using lib/daemons/test_ctl stop
|
27
|
+
rake daemon:test:status - show running status for daemon using lib/daemons/test_ctl status
|
28
|
+
|
22
29
|
App-wide control script:
|
23
30
|
> ./script/daemons [start|stop|restart]
|
24
|
-
> rake daemons:(start|stop|status)
|
31
|
+
> rake daemons:(start|stop|status)
|
32
|
+
|
33
|
+
== MONITORING API ==
|
34
|
+
|
35
|
+
Daemons::Rails::Monitoring.statuses - hash with all daemons and corresponding statuses
|
36
|
+
Daemons::Rails::Monitoring.start("test.rb") - start daemon using lib/daemons/test_ctl start
|
37
|
+
Daemons::Rails::Monitoring.stop("test.rb") - start daemon using lib/daemons/test_ctl stop
|
38
|
+
Daemons::Rails::Monitoring.controllers - list of controllers
|
39
|
+
Daemons::Rails::Monitoring.controller("test.rb") - controller for test.rb application
|
40
|
+
|
41
|
+
controller = Daemons::Rails::Monitoring.controller("test.rb")
|
42
|
+
controller.path # => lib/daemons/test_ctl
|
43
|
+
controller.app_name # => test.rb
|
44
|
+
controller.start # => starts daemon
|
45
|
+
controller.stop # => stops daemon
|
46
|
+
controller.status # => :not_exists or :running
|
data/daemons-rails.gemspec
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Daemons
|
2
|
+
module Rails
|
3
|
+
class Controller
|
4
|
+
attr_reader :path, :app_name
|
5
|
+
|
6
|
+
def initialize(controller_path)
|
7
|
+
@path = controller_path
|
8
|
+
@app_name = "#{controller_path.basename.to_s[0..-'_ctrl'.length]}.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(command)
|
12
|
+
`#{path} #{command}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
run('start')
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop
|
20
|
+
run('stop')
|
21
|
+
end
|
22
|
+
|
23
|
+
def status
|
24
|
+
run('status').to_s.split("\n").last =~ /: running \[pid \d+\]$/ ? :running : :not_exists
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require "daemons"
|
2
|
+
require "daemons/rails/config"
|
3
|
+
require "daemons/rails/controller"
|
2
4
|
|
3
5
|
module Daemons
|
4
6
|
module Rails
|
@@ -11,33 +13,24 @@ module Daemons
|
|
11
13
|
@daemons_directory ||= ::Rails.root.join('lib', 'daemons')
|
12
14
|
end
|
13
15
|
|
14
|
-
def self.
|
15
|
-
|
16
|
+
def self.controller(app_name)
|
17
|
+
controllers.find { |controller| controller.app_name == app_name }
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
app_config = Daemons::Rails::Config.new(app_name, ::Rails.root)
|
21
|
-
group = Daemons::ApplicationGroup.new("#{app_name}.rb", app_config.to_hash)
|
22
|
-
group.setup
|
23
|
-
group
|
20
|
+
def self.controllers
|
21
|
+
Pathname.glob(daemons_directory.join('*_ctl')).map { |path| Daemons::Rails::Controller.new(path) }
|
24
22
|
end
|
25
23
|
|
26
|
-
def self.
|
27
|
-
|
28
|
-
daemons_directory.each_entry do |file|
|
29
|
-
if !file.directory? && file.basename.to_s =~ /(\w+)_ctl/
|
30
|
-
groups << group($1)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
groups
|
24
|
+
def self.statuses
|
25
|
+
controllers.each_with_object({}) { |controller, statuses| statuses[controller.app_name] = controller.status }
|
34
26
|
end
|
35
27
|
|
36
|
-
def self.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
def self.start(app_name)
|
29
|
+
controller(app_name).start
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.stop(app_name)
|
33
|
+
controller(app_name).stop
|
41
34
|
end
|
42
35
|
end
|
43
36
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# You might want to change this
|
4
4
|
ENV["RAILS_ENV"] ||= "production"
|
5
5
|
|
6
|
-
require File.dirname(__FILE__)
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "environment"))
|
7
7
|
|
8
8
|
$running = true
|
9
9
|
Signal.trap("TERM") do
|
@@ -0,0 +1 @@
|
|
1
|
+
#Test script
|
@@ -0,0 +1 @@
|
|
1
|
+
# Test controller
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "daemons/rails/monitoring"
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
describe Daemons::Rails::Monitoring do
|
6
|
+
subject { Daemons::Rails::Monitoring }
|
7
|
+
|
8
|
+
it "should get list of controllers" do
|
9
|
+
controllers = subject.controllers
|
10
|
+
controllers.should have(1).item
|
11
|
+
controller = controllers[0]
|
12
|
+
controller.path.should == Rails.root.join('lib', 'daemons', 'test_ctl')
|
13
|
+
controller.app_name.should == 'test.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "using controllers" do
|
17
|
+
before :each do
|
18
|
+
@controller = Daemons::Rails::Controller.new(Rails.root.join('lib', 'daemons', 'test_ctl'))
|
19
|
+
subject.stub(:controllers).and_return([@controller])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return status for all controllers" do
|
23
|
+
@controller.should_receive(:run).with('status').and_return('test.rb: running [pid 10880]')
|
24
|
+
subject.statuses.should == {'test.rb' => :running}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should start controller by name" do
|
28
|
+
@controller.should_receive(:run).with('start')
|
29
|
+
subject.start('test.rb')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should stop controller by name" do
|
33
|
+
@controller.should_receive(:run).with('stop')
|
34
|
+
subject.stop('test.rb')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class Rails
|
2
|
+
def Rails.root
|
3
|
+
@root ||= Pathname.new(File.absolute_path(File.dirname(__FILE__))).join('fixtures')
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daemons-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &14263920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14263920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: daemons
|
27
|
-
requirement: &
|
27
|
+
requirement: &14260740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14260740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: multi_json
|
38
|
-
requirement: &
|
38
|
+
requirement: &14257180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *14257180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &14233540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,18 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *14233540
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: &14228840 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.7.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *14228840
|
58
69
|
description: daemons gem support for Rails 3
|
59
70
|
email: []
|
60
71
|
executables: []
|
@@ -62,6 +73,7 @@ extensions: []
|
|
62
73
|
extra_rdoc_files: []
|
63
74
|
files:
|
64
75
|
- .gitignore
|
76
|
+
- .rspec
|
65
77
|
- Gemfile
|
66
78
|
- README
|
67
79
|
- Rakefile
|
@@ -69,6 +81,7 @@ files:
|
|
69
81
|
- install.rb
|
70
82
|
- lib/daemons-rails.rb
|
71
83
|
- lib/daemons/rails/config.rb
|
84
|
+
- lib/daemons/rails/controller.rb
|
72
85
|
- lib/daemons/rails/monitoring.rb
|
73
86
|
- lib/daemons/rails/version.rb
|
74
87
|
- lib/generators/USAGE
|
@@ -78,6 +91,11 @@ files:
|
|
78
91
|
- lib/generators/templates/script.rb
|
79
92
|
- lib/generators/templates/script_ctl
|
80
93
|
- lib/tasks/daemons.rake
|
94
|
+
- spec/fixtures/config/daemons.yml
|
95
|
+
- spec/fixtures/lib/daemons/test.rb
|
96
|
+
- spec/fixtures/lib/daemons/test_ctl
|
97
|
+
- spec/lib/daemons/rails/monitoring_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
81
99
|
homepage: ''
|
82
100
|
licenses: []
|
83
101
|
post_install_message:
|
@@ -92,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
110
|
version: '0'
|
93
111
|
segments:
|
94
112
|
- 0
|
95
|
-
hash:
|
113
|
+
hash: -1263531604415930102
|
96
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
115
|
none: false
|
98
116
|
requirements:
|
@@ -101,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
119
|
version: '0'
|
102
120
|
segments:
|
103
121
|
- 0
|
104
|
-
hash:
|
122
|
+
hash: -1263531604415930102
|
105
123
|
requirements: []
|
106
124
|
rubyforge_project:
|
107
125
|
rubygems_version: 1.8.10
|