daemonizer 0.0.7 → 0.0.8
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 +111 -0
- data/VERSION +1 -1
- data/daemonizer.gemspec +3 -3
- metadata +5 -5
- data/README +0 -44
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
Daemonizer: Simple framework for creating daemons with Ruby
|
2
|
+
====================================
|
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
|
10
|
+
|
11
|
+
Synopsis
|
12
|
+
--------
|
13
|
+
|
14
|
+
Daemonizer is a simple ruby framework to create custom daemons. It is fully
|
15
|
+
compatible with EventMachine, Rails and any other Ruby frameworks. Two workers
|
16
|
+
type supported - forked and threaded.
|
17
|
+
|
18
|
+
|
19
|
+
Feature List
|
20
|
+
------------
|
21
|
+
|
22
|
+
**1. Demfile (similar to Gemfile, Rakefile)** as a configuration file. It is
|
23
|
+
possible to describe different background pools there.
|
24
|
+
|
25
|
+
**2. Two engines**: :thread and :fork. (thread is currently broken)
|
26
|
+
|
27
|
+
**3. Monitoring**: If child is found dead it will be immediately
|
28
|
+
restored
|
29
|
+
|
30
|
+
**4. Logging** (via [http://log4r.rubyforge.org/]log4r)
|
31
|
+
|
32
|
+
Installing
|
33
|
+
----------
|
34
|
+
|
35
|
+
To install Daemonizer, use the following command:
|
36
|
+
|
37
|
+
$ gem install daemonizer
|
38
|
+
|
39
|
+
(Add `sudo` if you're installing under a POSIX system as root)
|
40
|
+
|
41
|
+
Usage
|
42
|
+
-----
|
43
|
+
|
44
|
+
**Demfile example:**
|
45
|
+
|
46
|
+
engine :fork
|
47
|
+
workers 2
|
48
|
+
|
49
|
+
pool :daemonizer do
|
50
|
+
workers 4
|
51
|
+
poll_period 5
|
52
|
+
log_file "log/daemonizer.log" #relative to Demfile
|
53
|
+
|
54
|
+
before_init do |logger, block|
|
55
|
+
block.call
|
56
|
+
end
|
57
|
+
|
58
|
+
after_init do |logger, worker_id, workers_count|
|
59
|
+
logger.info "Started #{worker_id} from #{workers_count}"
|
60
|
+
|
61
|
+
exit = false
|
62
|
+
|
63
|
+
stop = proc {
|
64
|
+
exit = true
|
65
|
+
}
|
66
|
+
|
67
|
+
trap('TERM', stop)
|
68
|
+
trap('INT', stop)
|
69
|
+
trap('EXIT', stop)
|
70
|
+
|
71
|
+
loop do
|
72
|
+
break if exit
|
73
|
+
logger.info "Ping #{worker_id}"
|
74
|
+
sleep 10
|
75
|
+
end
|
76
|
+
|
77
|
+
true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
pool :new_daemonizer do
|
82
|
+
workers 4
|
83
|
+
poll_period 5
|
84
|
+
log_file "log/daemonizer.log" #relative to Demfile
|
85
|
+
|
86
|
+
handler ::MyBackgroundSolution::DaemonizerHandler
|
87
|
+
|
88
|
+
set_option :queue, lambda { |worker_id, worker_count| "queue_#{worker_id}"}
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
**Handler example**
|
93
|
+
|
94
|
+
module MyBackgroundSolution
|
95
|
+
class DaemonizerHandler < Daemonizer::Handler
|
96
|
+
def before_init(block)
|
97
|
+
require File.join(Daemonizer.root, '/config/environment') #Require rails
|
98
|
+
require 'my_background_solution/worker' #Require our code
|
99
|
+
super #now we are ready to fork
|
100
|
+
end
|
101
|
+
|
102
|
+
def after_init
|
103
|
+
#we are in worker process
|
104
|
+
logger.info "Starting cycle. We are number #{worker_id} from #{workers_count}"
|
105
|
+
logger.info "Options - #{option(:queue)}" #We can get option :queue, which is set with set_option in pool configuration
|
106
|
+
worker = Worker.new
|
107
|
+
worker.run
|
108
|
+
logger.info "Ending cycle"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/daemonizer.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{daemonizer}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
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"]
|
@@ -15,10 +15,10 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.email = %q{glebpom@gmail.com}
|
16
16
|
s.executables = ["daemonizer"]
|
17
17
|
s.extra_rdoc_files = [
|
18
|
-
"README"
|
18
|
+
"README.md"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
|
-
"README",
|
21
|
+
"README.md",
|
22
22
|
"Rakefile",
|
23
23
|
"VERSION",
|
24
24
|
"bin/daemonizer",
|
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: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gleb Pomykalov
|
@@ -57,9 +57,9 @@ executables:
|
|
57
57
|
extensions: []
|
58
58
|
|
59
59
|
extra_rdoc_files:
|
60
|
-
- README
|
60
|
+
- README.md
|
61
61
|
files:
|
62
|
-
- README
|
62
|
+
- README.md
|
63
63
|
- Rakefile
|
64
64
|
- VERSION
|
65
65
|
- bin/daemonizer
|
data/README
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
engine :fork
|
2
|
-
workers 2
|
3
|
-
|
4
|
-
pool :daemonizer do
|
5
|
-
workers 4
|
6
|
-
poll_period 5
|
7
|
-
log_file "log/daemonizer.log" #relative to Demfile
|
8
|
-
|
9
|
-
before_init do |logger, block|
|
10
|
-
block.call
|
11
|
-
end
|
12
|
-
|
13
|
-
after_init do |logger, worker_id, workers_count|
|
14
|
-
logger.info "Started #{worker_id} from #{workers_count}"
|
15
|
-
|
16
|
-
exit = false
|
17
|
-
|
18
|
-
stop = proc {
|
19
|
-
exit = true
|
20
|
-
}
|
21
|
-
|
22
|
-
trap('TERM', stop)
|
23
|
-
trap('INT', stop)
|
24
|
-
trap('EXIT', stop)
|
25
|
-
|
26
|
-
loop do
|
27
|
-
break if exit
|
28
|
-
logger.info "Ping #{worker_id}"
|
29
|
-
sleep 10
|
30
|
-
end
|
31
|
-
|
32
|
-
true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
pool :new_daemonizer do
|
37
|
-
workers 4
|
38
|
-
poll_period 5
|
39
|
-
log_file "log/daemonizer.log" #relative to Demfile
|
40
|
-
|
41
|
-
handler ::AsyncObserver::DaemonizerHandler
|
42
|
-
|
43
|
-
set_option :queue, lambda { |worker_id, worker_count| "queue_#{worker_id}"}
|
44
|
-
end
|