pazuzu 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +2 -0
- data/Pazuzu.gemspec +29 -0
- data/README.md +171 -0
- data/Rakefile +21 -0
- data/bin/pazuzu +6 -0
- data/bin/pazuzud +6 -0
- data/lib/pazuzu.rb +37 -0
- data/lib/pazuzu/application.rb +114 -0
- data/lib/pazuzu/cgroup.rb +73 -0
- data/lib/pazuzu/command_line/controller.rb +152 -0
- data/lib/pazuzu/control/protocol.rb +304 -0
- data/lib/pazuzu/control/socket_client.rb +30 -0
- data/lib/pazuzu/control/socket_server.rb +75 -0
- data/lib/pazuzu/instance.rb +218 -0
- data/lib/pazuzu/procfiles.rb +16 -0
- data/lib/pazuzu/supervisor.rb +201 -0
- data/lib/pazuzu/supervisor_runner.rb +95 -0
- data/lib/pazuzu/utility/annotated_logger.rb +46 -0
- data/lib/pazuzu/utility/output_tailer.rb +60 -0
- data/lib/pazuzu/utility/process_spawning.rb +40 -0
- data/lib/pazuzu/utility/rate_limiter.rb +68 -0
- data/lib/pazuzu/utility/runnable.rb +120 -0
- data/lib/pazuzu/utility/runnable_pool.rb +62 -0
- data/lib/pazuzu/version.rb +3 -0
- data/lib/pazuzu/worker.rb +173 -0
- metadata +193 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
module Pazuzu
|
2
|
+
|
3
|
+
class Worker
|
4
|
+
|
5
|
+
include Utility::Runnable
|
6
|
+
|
7
|
+
def initialize(application, name)
|
8
|
+
@application = application
|
9
|
+
@name = name
|
10
|
+
@instances = Utility::RunnablePool.new
|
11
|
+
@target_instance_count = 1
|
12
|
+
@dynamic_instance_count = nil
|
13
|
+
@logger = Utility::AnnotatedLogger.new(
|
14
|
+
@application.supervisor.logger, qname)
|
15
|
+
super()
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure!(root_path, command_line, configuration)
|
19
|
+
restart_required = false
|
20
|
+
|
21
|
+
if [:starting, :running].include?(run_state) and root_path != @root_path
|
22
|
+
restart_required = true
|
23
|
+
end
|
24
|
+
@root_path = root_path
|
25
|
+
|
26
|
+
new_command_line = configuration['command_line']
|
27
|
+
new_command_line ||= command_line
|
28
|
+
new_command_line ||= @command_line
|
29
|
+
if new_command_line != @command_line
|
30
|
+
if [:starting, :running].include?(run_state)
|
31
|
+
restart_required = true
|
32
|
+
end
|
33
|
+
@command_line = new_command_line
|
34
|
+
end
|
35
|
+
|
36
|
+
if restart_required
|
37
|
+
@logger.warn "Root path or command line has changed, instances must be restarted/added manually"
|
38
|
+
end
|
39
|
+
|
40
|
+
new_target_instance_count = configuration['num_instances'].try(:to_i) || 1
|
41
|
+
if new_target_instance_count != @target_instance_count
|
42
|
+
@target_instance_count = new_target_instance_count
|
43
|
+
end
|
44
|
+
|
45
|
+
if [:starting, :running].include?(run_state)
|
46
|
+
adjust_instances!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def qname
|
51
|
+
[@application.name, @name].join('.')
|
52
|
+
end
|
53
|
+
|
54
|
+
def revert_dynamic_instance_count!
|
55
|
+
@dynamic_instance_count = nil
|
56
|
+
adjust_instances!
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_instance_count!(value)
|
60
|
+
@dynamic_instance_count = [0, value].max
|
61
|
+
adjust_instances!
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_instance_count!(value)
|
65
|
+
@dynamic_instance_count ||= @target_instance_count
|
66
|
+
@dynamic_instance_count = [0, @dynamic_instance_count + value].max
|
67
|
+
adjust_instances!
|
68
|
+
end
|
69
|
+
|
70
|
+
def adjust_instances!
|
71
|
+
target_count = @dynamic_instance_count
|
72
|
+
target_count ||= @target_instance_count
|
73
|
+
if @instances.length != target_count
|
74
|
+
if run_state == :running
|
75
|
+
@logger.info "Adjusting from #{@instances.length} to #{target_count} instances"
|
76
|
+
end
|
77
|
+
while @instances.length < target_count
|
78
|
+
instance = Instance.new(self, @instances.length + 1, @root_path, @command_line)
|
79
|
+
@instances.register(instance)
|
80
|
+
end
|
81
|
+
if @instances.length > target_count
|
82
|
+
children_by_index = @instances.children.sort_by { |c| c.index }
|
83
|
+
(children_by_index[target_count..-1] || []).each do |instance|
|
84
|
+
@instances.unregister(instance)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Go through available cgroups and find instances that are orphaned.
|
91
|
+
def recover_orphaned_instances!
|
92
|
+
index = @instances.length + 1
|
93
|
+
loop do
|
94
|
+
instance = Instance.new(self, index, @root_path, @command_line)
|
95
|
+
cgroup = @application.supervisor.cgroup_for_instance(instance)
|
96
|
+
if cgroup.mounted?
|
97
|
+
if instance.attachable?
|
98
|
+
@logger.info "Discovered orphaned instance #{index}, attaching it"
|
99
|
+
@instances.register(instance)
|
100
|
+
end
|
101
|
+
index += 1
|
102
|
+
else
|
103
|
+
break
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Call to set up a forked process according to the application's
|
109
|
+
# configuration.
|
110
|
+
def setup_spawned_process!
|
111
|
+
@application.setup_spawned_process!
|
112
|
+
end
|
113
|
+
|
114
|
+
def instances
|
115
|
+
@instances.children
|
116
|
+
end
|
117
|
+
|
118
|
+
def log_entries
|
119
|
+
entries = @instances.children.map(&:log_entries)
|
120
|
+
entries.flatten!(1)
|
121
|
+
entries.sort_by! { |(source, time, message)| time }
|
122
|
+
entries
|
123
|
+
end
|
124
|
+
|
125
|
+
attr_reader :name
|
126
|
+
attr_reader :command_line
|
127
|
+
attr_reader :application
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def on_starting
|
132
|
+
@logger.info "Starting"
|
133
|
+
@monitor_thread ||= Thread.start { monitor_instances }
|
134
|
+
adjust_instances!
|
135
|
+
recover_orphaned_instances!
|
136
|
+
@instances.start!
|
137
|
+
runnable_state.started!
|
138
|
+
end
|
139
|
+
|
140
|
+
def on_started
|
141
|
+
@logger.info "Started"
|
142
|
+
end
|
143
|
+
|
144
|
+
def on_stopping
|
145
|
+
@logger.info "Stopping"
|
146
|
+
@instances.stop!
|
147
|
+
end
|
148
|
+
|
149
|
+
def on_stopped
|
150
|
+
@logger.info "Stopped"
|
151
|
+
end
|
152
|
+
|
153
|
+
def on_failed
|
154
|
+
end
|
155
|
+
|
156
|
+
def monitor_instances
|
157
|
+
while [:starting, :running, :stopping].include?(run_state)
|
158
|
+
if runnable_state.state == :stopping
|
159
|
+
unless @instances.children.any? { |w| w.run_state == :running }
|
160
|
+
runnable_state.stopped!
|
161
|
+
end
|
162
|
+
end
|
163
|
+
sleep(1)
|
164
|
+
end
|
165
|
+
rescue Exception => e
|
166
|
+
@logger.error(e.message)
|
167
|
+
ensure
|
168
|
+
@monitor_thread = nil
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pazuzu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Staubo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: statemachine
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.0.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yajl-ruby
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: i18n
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: scashin133-syslog_logger
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.7.3
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.7.3
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Pazuzu is a supervisor daemon that manages pools of application processes
|
127
|
+
as daemons.
|
128
|
+
email:
|
129
|
+
- alex@origo.no
|
130
|
+
executables:
|
131
|
+
- pazuzu
|
132
|
+
- pazuzud
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- .gitignore
|
137
|
+
- Gemfile
|
138
|
+
- Pazuzu.gemspec
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/pazuzu
|
142
|
+
- bin/pazuzud
|
143
|
+
- lib/pazuzu.rb
|
144
|
+
- lib/pazuzu/application.rb
|
145
|
+
- lib/pazuzu/cgroup.rb
|
146
|
+
- lib/pazuzu/command_line/controller.rb
|
147
|
+
- lib/pazuzu/control/protocol.rb
|
148
|
+
- lib/pazuzu/control/socket_client.rb
|
149
|
+
- lib/pazuzu/control/socket_server.rb
|
150
|
+
- lib/pazuzu/instance.rb
|
151
|
+
- lib/pazuzu/procfiles.rb
|
152
|
+
- lib/pazuzu/supervisor.rb
|
153
|
+
- lib/pazuzu/supervisor_runner.rb
|
154
|
+
- lib/pazuzu/utility/annotated_logger.rb
|
155
|
+
- lib/pazuzu/utility/output_tailer.rb
|
156
|
+
- lib/pazuzu/utility/process_spawning.rb
|
157
|
+
- lib/pazuzu/utility/rate_limiter.rb
|
158
|
+
- lib/pazuzu/utility/runnable.rb
|
159
|
+
- lib/pazuzu/utility/runnable_pool.rb
|
160
|
+
- lib/pazuzu/version.rb
|
161
|
+
- lib/pazuzu/worker.rb
|
162
|
+
homepage: http://github.com/origo/pazuzu
|
163
|
+
licenses: []
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
segments:
|
175
|
+
- 0
|
176
|
+
hash: 261249866598060842
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
hash: 261249866598060842
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project: pazuzu
|
188
|
+
rubygems_version: 1.8.22
|
189
|
+
signing_key:
|
190
|
+
specification_version: 3
|
191
|
+
summary: Pazuzu is a supervisor daemon that manages pools of application processes
|
192
|
+
as daemons.
|
193
|
+
test_files: []
|