simple-daemon 0.0.2 → 0.0.3
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/History.txt +7 -1
- data/License.txt +1 -1
- data/README.txt +1 -0
- data/lib/simple-daemon.rb +12 -5
- data/lib/simple-daemon/version.rb +1 -1
- data/website/index.html +26 -10
- data/website/index.txt +19 -6
- metadata +2 -2
data/History.txt
CHANGED
data/License.txt
CHANGED
data/README.txt
CHANGED
data/lib/simple-daemon.rb
CHANGED
@@ -2,11 +2,14 @@ require 'simple-daemon/version'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
module SimpleDaemon
|
5
|
-
WorkingDirectory = File.expand_path(File.dirname(__FILE__))
|
6
|
-
|
7
5
|
class Base
|
6
|
+
|
7
|
+
def self.classname
|
8
|
+
name
|
9
|
+
end
|
10
|
+
|
8
11
|
def self.pid_fn
|
9
|
-
File.join(WorkingDirectory, "#{name}.pid")
|
12
|
+
File.join(SimpleDaemon::WorkingDirectory, "#{name}.pid")
|
10
13
|
end
|
11
14
|
|
12
15
|
def self.daemonize
|
@@ -45,14 +48,16 @@ module SimpleDaemon
|
|
45
48
|
Process.setsid
|
46
49
|
exit if fork
|
47
50
|
PidFile.store(daemon, Process.pid)
|
48
|
-
Dir.chdir WorkingDirectory
|
51
|
+
Dir.chdir SimpleDaemon::WorkingDirectory
|
49
52
|
File.umask 0000
|
53
|
+
log = File.new("#{daemon.classname}.log", "a")
|
50
54
|
STDIN.reopen "/dev/null"
|
51
|
-
STDOUT.reopen
|
55
|
+
STDOUT.reopen log
|
52
56
|
STDERR.reopen STDOUT
|
53
57
|
trap("TERM") {daemon.stop; exit}
|
54
58
|
daemon.start
|
55
59
|
end
|
60
|
+
puts "Daemon started."
|
56
61
|
end
|
57
62
|
|
58
63
|
def self.stop(daemon)
|
@@ -63,6 +68,8 @@ module SimpleDaemon
|
|
63
68
|
pid = PidFile.recall(daemon)
|
64
69
|
FileUtils.rm(daemon.pid_fn)
|
65
70
|
pid && Process.kill("TERM", pid)
|
71
|
+
rescue Errno::ESRCH
|
72
|
+
puts "Pid file found, but process was not running. The daemon may have died."
|
66
73
|
end
|
67
74
|
end
|
68
75
|
end
|
data/website/index.html
CHANGED
@@ -33,13 +33,15 @@
|
|
33
33
|
<h1>simple-daemon</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/simple-daemon"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/simple-daemon" class="numbers">0.0.
|
36
|
+
<a href="http://rubyforge.org/projects/simple-daemon" class="numbers">0.0.3</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘simple-daemon’</h1>
|
39
39
|
|
40
40
|
|
41
|
-
<h2>What
|
42
|
-
|
41
|
+
<h2>What</h2>
|
42
|
+
|
43
|
+
|
44
|
+
<p>SimpleDaemon is a lightweight daemon module for Ruby. Use it to add daemon functionality to your Ruby script.</p>
|
43
45
|
|
44
46
|
|
45
47
|
<h2>Installing</h2>
|
@@ -47,19 +49,33 @@ SimpleDaemon is a lightweight daemon module for Ruby. Use it to add daemon funct
|
|
47
49
|
|
48
50
|
<pre syntax="ruby">sudo gem install simple-daemon</pre>
|
49
51
|
|
50
|
-
<h2>
|
52
|
+
<h2>Demonstration of usage</h2>
|
51
53
|
|
52
54
|
|
53
|
-
|
55
|
+
<pre syntax="ruby">
|
54
56
|
|
57
|
+
class Processor < SimpleDaemon::Base
|
58
|
+
SimpleDaemon::WorkingDirectory = "#{RAILS_ROOT}/log"
|
55
59
|
|
56
|
-
|
60
|
+
def self.start
|
61
|
+
loop do
|
62
|
+
# loop through some process
|
63
|
+
end
|
64
|
+
end
|
57
65
|
|
66
|
+
def self.stop
|
67
|
+
puts "Stopping processor "
|
68
|
+
end
|
69
|
+
end
|
58
70
|
|
59
|
-
|
71
|
+
PdfGenerator.daemonize
|
72
|
+
|
73
|
+
</pre>
|
60
74
|
|
75
|
+
<h2>Forum</h2>
|
61
76
|
|
62
|
-
|
77
|
+
|
78
|
+
<p><a href="http://groups.google.com/group/simple-daemon">http://groups.google.com/group/simple-daemon</a></p>
|
63
79
|
|
64
80
|
|
65
81
|
<h2>How to submit patches</h2>
|
@@ -80,9 +96,9 @@ SimpleDaemon is a lightweight daemon module for Ruby. Use it to add daemon funct
|
|
80
96
|
<h2>Contact</h2>
|
81
97
|
|
82
98
|
|
83
|
-
<p>Comments are welcome. Send an email to <a href="mailto:
|
99
|
+
<p>Comments are welcome. Send an email to <a href="mailto:simple-daemon@googlegroups.com">simple-daemon@googlegroups.com</a>.</p>
|
84
100
|
<p class="coda">
|
85
|
-
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>,
|
101
|
+
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 8th July 2007<br>
|
86
102
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
87
103
|
</p>
|
88
104
|
</div>
|
data/website/index.txt
CHANGED
@@ -2,27 +2,40 @@ h1. simple-daemon
|
|
2
2
|
|
3
3
|
h1. → 'simple-daemon'
|
4
4
|
|
5
|
-
|
6
5
|
h2. What
|
6
|
+
|
7
7
|
SimpleDaemon is a lightweight daemon module for Ruby. Use it to add daemon functionality to your Ruby script.
|
8
8
|
|
9
9
|
h2. Installing
|
10
10
|
|
11
11
|
<pre syntax="ruby">sudo gem install simple-daemon</pre>
|
12
12
|
|
13
|
-
h2.
|
13
|
+
h2. Demonstration of usage
|
14
|
+
|
15
|
+
<pre syntax="ruby">
|
14
16
|
|
17
|
+
class Processor < SimpleDaemon::Base
|
18
|
+
SimpleDaemon::WorkingDirectory = "#{RAILS_ROOT}/log"
|
19
|
+
|
20
|
+
def self.start
|
21
|
+
loop do
|
22
|
+
# loop through some process
|
23
|
+
end
|
24
|
+
end
|
15
25
|
|
16
|
-
|
26
|
+
def self.stop
|
27
|
+
puts "Stopping processor "
|
28
|
+
end
|
29
|
+
end
|
17
30
|
|
31
|
+
PdfGenerator.daemonize
|
18
32
|
|
33
|
+
</pre>
|
19
34
|
|
20
35
|
h2. Forum
|
21
36
|
|
22
37
|
"http://groups.google.com/group/simple-daemon":http://groups.google.com/group/simple-daemon
|
23
38
|
|
24
|
-
TODO - create Google Group - simple-daemon
|
25
|
-
|
26
39
|
h2. How to submit patches
|
27
40
|
|
28
41
|
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
@@ -35,4 +48,4 @@ This code is free to use under the terms of the MIT license.
|
|
35
48
|
|
36
49
|
h2. Contact
|
37
50
|
|
38
|
-
Comments are welcome. Send an email to "
|
51
|
+
Comments are welcome. Send an email to "simple-daemon@googlegroups.com":mailto:simple-daemon@googlegroups.com.
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: simple-daemon
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2007-07-08 00:00:00 -05:00
|
8
8
|
summary: Simple module that adds daemon functionality to a Ruby script.
|
9
9
|
require_paths:
|
10
10
|
- lib
|