light-daemon 0.9.5 → 0.9.6
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 +57 -0
- metadata +7 -6
data/README
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
light-daemon is a ruby gem. It could help developers quickly build a daemon which prefok worker processes and monitor them.
|
2
|
+
The usage is very simple:
|
3
|
+
|
4
|
+
#---------------------------------------------------------------------------------------------
|
5
|
+
require 'rubygems'
|
6
|
+
require 'light_daemon'
|
7
|
+
|
8
|
+
class Client
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
`echo "process: #{Process.pid}" >> /tmp/light-daemon.txt`
|
14
|
+
sleep 3
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
LightDaemon::Daemon.start(Client.new, :children=> 2, :pid_file => "/tmp/light-daemon.pid" )
|
20
|
+
#---------------------------------------------------------------------------------------------
|
21
|
+
|
22
|
+
What you need to do is:
|
23
|
+
1. Create your worker class. Define a method "call" and put the real work into it.
|
24
|
+
2. The method "call" needs to return true for the daemon to continuously call it.
|
25
|
+
3. You need to tell the daemon how many worker processes you want and a filename for daemon to store
|
26
|
+
the PID of the daemon process.
|
27
|
+
4. If the method "call" returns false, the daemon will kill this work process and create a new one.
|
28
|
+
This would be very helpful if your code might have memory leaking and you want it to restart after
|
29
|
+
certain criteria is met. An example is as following:
|
30
|
+
|
31
|
+
#---------------------------------------------------------------------------------------------
|
32
|
+
require 'rubygems'
|
33
|
+
require 'light_daemon'
|
34
|
+
|
35
|
+
class Client
|
36
|
+
def initialize
|
37
|
+
@count = 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def call
|
41
|
+
`echo "process: #{Process.pid}" >> /tmp/light-daemon.txt`
|
42
|
+
sleep 3
|
43
|
+
@count +=1
|
44
|
+
(@count < 100)? true : false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
LightDaemon::Daemon.start(Client.new, :children=> 2, :pid_file => "/tmp/light-daemon.pid" )
|
49
|
+
#---------------------------------------------------------------------------------------------
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
Yi Zhang
|
55
|
+
yzhang[dot]wa[at]gmail[dot]com
|
56
|
+
3/11/2012
|
57
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 6
|
10
|
+
version: 0.9.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yi Zhang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-11 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,9 +28,10 @@ extensions: []
|
|
28
28
|
extra_rdoc_files: []
|
29
29
|
|
30
30
|
files:
|
31
|
+
- README
|
31
32
|
- lib/light_daemon.rb
|
32
33
|
has_rdoc: true
|
33
|
-
homepage: http://rubygems.org/gems/light_daemon
|
34
|
+
homepage: http://rubygems.org/gems/light_daemon://github.com/yzhanginwa/light-daemon
|
34
35
|
licenses: []
|
35
36
|
|
36
37
|
post_install_message:
|
@@ -62,6 +63,6 @@ rubyforge_project:
|
|
62
63
|
rubygems_version: 1.6.2
|
63
64
|
signing_key:
|
64
65
|
specification_version: 3
|
65
|
-
summary: Light Daemon!
|
66
|
+
summary: Light Daemon is awesome!
|
66
67
|
test_files: []
|
67
68
|
|