daemonizer 0.4.13 → 0.4.14
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/README.md +44 -34
- data/VERSION +1 -1
- data/daemonizer.gemspec +2 -2
- data/lib/daemonizer.rb +1 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,39 +1,42 @@
|
|
1
1
|
Daemonizer: Simple framework for creating daemons with Ruby
|
2
2
|
====================================
|
3
3
|
|
4
|
-
**Homepage**: [http://daemonizer.org](http://daemonizer.org)
|
5
|
-
**Git**: [http://github.com/glebpom/daemonizer](http://github.com/glebpom/daemonizer)
|
6
|
-
**Author**: Gleb Pomykalov
|
7
|
-
**Copyright**: 2010
|
8
|
-
**License**: MIT License
|
9
|
-
**Status**: alpha
|
4
|
+
**Homepage**: [http://daemonizer.org](http://daemonizer.org)
|
5
|
+
**Git**: [http://github.com/glebpom/daemonizer](http://github.com/glebpom/daemonizer)
|
6
|
+
**Author**: Gleb Pomykalov
|
7
|
+
**Copyright**: 2010
|
8
|
+
**License**: MIT License
|
9
|
+
**Status**: alpha
|
10
10
|
|
11
11
|
Synopsis
|
12
12
|
--------
|
13
13
|
|
14
|
-
Daemonizer is a simple ruby framework to create custom daemons. It is fully
|
14
|
+
Daemonizer is a simple ruby framework to create custom daemons. It is fully
|
15
15
|
compatible with EventMachine, Rails and any other Ruby frameworks.
|
16
16
|
|
17
17
|
|
18
18
|
Feature List
|
19
19
|
------------
|
20
|
-
|
21
|
-
**1. Daemonfile (similar to Gemfile, Rakefile)** as a configuration file. It is
|
22
|
-
possible to describe different
|
23
|
-
|
24
|
-
**2. Monitoring**: If child is found dead it will be immediately
|
20
|
+
|
21
|
+
**1. Daemonfile (similar to Gemfile, Rakefile)** as a configuration file. It is
|
22
|
+
possible to describe different worker pools there.
|
23
|
+
|
24
|
+
**2. Monitoring**: If child is found dead it will be immediately
|
25
25
|
restored
|
26
|
-
|
26
|
+
|
27
27
|
**3. Logging**
|
28
28
|
|
29
|
+
**4. Statistics**: Daemonizer collects worker statistics and let you kill workers if
|
30
|
+
some statistics exceeds regular values.
|
31
|
+
|
29
32
|
Installing
|
30
33
|
----------
|
31
34
|
|
32
35
|
To install Daemonizer, use the following command:
|
33
36
|
|
34
37
|
$ gem install daemonizer
|
35
|
-
|
36
|
-
(Add `sudo` if you're installing under a POSIX system as root)
|
38
|
+
|
39
|
+
(Add `sudo` if you're installing under a POSIX system as root)
|
37
40
|
|
38
41
|
Usage
|
39
42
|
-----
|
@@ -46,16 +49,16 @@ Usage
|
|
46
49
|
pool :daemonizer do
|
47
50
|
workers 4
|
48
51
|
log_file "log/daemonizer.log" #relative to Demfile
|
49
|
-
|
52
|
+
|
50
53
|
prepare do |block|
|
51
54
|
block.call
|
52
55
|
end
|
53
|
-
|
56
|
+
|
54
57
|
start do |worker_id, workers_count|
|
55
58
|
logger.info "Started #{worker_id} from #{workers_count}"
|
56
|
-
|
59
|
+
|
57
60
|
exit = false
|
58
|
-
|
61
|
+
|
59
62
|
stop = proc {
|
60
63
|
exit = true
|
61
64
|
}
|
@@ -63,18 +66,18 @@ Usage
|
|
63
66
|
trap('TERM', stop)
|
64
67
|
trap('INT', stop)
|
65
68
|
trap('EXIT', stop)
|
66
|
-
|
69
|
+
|
67
70
|
loop do
|
68
71
|
break if exit
|
69
72
|
logger.info "Ping #{worker_id}"
|
70
73
|
sleep 10
|
71
74
|
end
|
72
|
-
|
75
|
+
|
73
76
|
true
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
|
-
settings_group do
|
80
|
+
settings_group do
|
78
81
|
before_start do |worker_id, workers_count|
|
79
82
|
#reconnect to db, etc.
|
80
83
|
end
|
@@ -83,18 +86,25 @@ Usage
|
|
83
86
|
set_option :author, "Gleb Pomykalov"
|
84
87
|
|
85
88
|
pool :new_daemonizer do
|
89
|
+
on_poll do |pool|
|
90
|
+
pool.stats.where(:private_dirty_rss).last_probes_by_count(8).mean.is_higher_then(150_000) do |stat|
|
91
|
+
Daemonizer.logger.info "Memory limit exceeded for #{stat}. Gracefully stopping"
|
92
|
+
worker = pool.find_worker_by_name(stat)
|
93
|
+
worker.stop if worker
|
94
|
+
end
|
95
|
+
end
|
86
96
|
workers 4
|
87
97
|
log_file "log/daemonizer.log" #relative to Demfile
|
88
98
|
|
89
99
|
handler MyBackgroundSolution::DaemonizerHandler
|
90
|
-
|
100
|
+
|
91
101
|
not_cow_friendly #disable Copy-On-Write friendly (enabled by default)
|
92
102
|
|
93
103
|
#automatically-parsed option by daemonizer
|
94
|
-
set_option :queue do |worker_id, worker_count|
|
104
|
+
set_option :queue do |worker_id, worker_count|
|
95
105
|
"queue_#{worker_id}"
|
96
106
|
end
|
97
|
-
|
107
|
+
|
98
108
|
#lambda-option (transparent for daemonizer, fully processed by handler)
|
99
109
|
set_option :on_error, lambda { |object| object.logger.fatal "epic fail"}
|
100
110
|
end
|
@@ -105,18 +115,18 @@ Usage
|
|
105
115
|
log_file "log/daemonizer2.log" #relative to Demfile
|
106
116
|
|
107
117
|
handler MyBackgroundSolution::DaemonizerHandler
|
108
|
-
|
118
|
+
|
109
119
|
not_cow_friendly #disable Copy-On-Write friendly (enabled by default)
|
110
120
|
|
111
121
|
#automatically-parsed option by daemonizer
|
112
|
-
set_option :queue do |worker_id, worker_count|
|
122
|
+
set_option :queue do |worker_id, worker_count|
|
113
123
|
"another_queue_#{worker_id}"
|
114
124
|
end
|
115
|
-
|
125
|
+
|
116
126
|
after_prepare do |logger|
|
117
127
|
require 'something'
|
118
128
|
end
|
119
|
-
|
129
|
+
|
120
130
|
#lambda-option (transparent for daemonizer, fully processed by handler)
|
121
131
|
set_option :on_error, lambda { |object| object.logger.fatal "epic fail"}
|
122
132
|
end
|
@@ -126,13 +136,13 @@ Usage
|
|
126
136
|
|
127
137
|
module MyBackgroundSolution
|
128
138
|
class DaemonizerHandler < Daemonizer::Handler
|
129
|
-
def
|
139
|
+
def preparee(starter, &block)
|
130
140
|
require File.join(Daemonizer.root, '/config/environment') #Require rails
|
131
141
|
require 'my_background_solution/worker' #Require our code
|
132
142
|
super #now we are ready to fork
|
133
143
|
end
|
134
144
|
|
135
|
-
def start
|
145
|
+
def start
|
136
146
|
#we are in worker process
|
137
147
|
logger.info "Starting cycle. We are number #{worker_id} from #{workers_count}"
|
138
148
|
logger.info "Options - #{option(:queue)}" #We can get option :queue, which is set with set_option in pool configuration
|
@@ -142,12 +152,12 @@ Usage
|
|
142
152
|
end
|
143
153
|
end
|
144
154
|
end
|
145
|
-
|
155
|
+
|
146
156
|
Who are the authors
|
147
157
|
-------------------
|
148
158
|
|
149
|
-
This gem has been created in qik.com for our internal use and then
|
150
|
-
the sources were opened for other people to use. All the code in this package
|
159
|
+
This gem has been created in qik.com for our internal use and then
|
160
|
+
the sources were opened for other people to use. All the code in this package
|
151
161
|
has been developed by Gleb Pomykalov. As for the first versions, it was mostly based
|
152
162
|
on [http://github.com/kovyrin/loops](loops) code written by Alexey Kovyrin. Now
|
153
163
|
most of it is heavily refactored. MemoryStats is taken from Phusion Passenger.The gem
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.14
|
data/daemonizer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{daemonizer}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.14"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gleb Pomykalov"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-26}
|
13
13
|
s.default_executable = %q{daemonizer}
|
14
14
|
s.description = %q{Inspired by bundler and rack. Mostly built on top of Alexey Kovyrin's loops code. http://github.com/kovyrin/loops}
|
15
15
|
s.email = %q{glebpom@gmail.com}
|
data/lib/daemonizer.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daemonizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 14
|
10
|
+
version: 0.4.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gleb Pomykalov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-26 00:00:00 +04:00
|
19
19
|
default_executable: daemonizer
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|