mlanett-daemons 1.0.13 → 1.1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +12 -2
- data/LICENSE +1 -8
- data/README-mlanett.rdoc +8 -0
- data/{README → README.rdoc} +6 -15
- data/Releases +84 -9
- data/TODO +1 -5
- data/daemons.gemspec +1 -0
- data/examples/call/call.rb +1 -0
- data/examples/daemonize/daemonize.rb +10 -3
- data/examples/run/ctrl_hanging.rb +19 -0
- data/examples/run/ctrl_monitor_multiple.rb +18 -0
- data/examples/run/ctrl_normal.rb +0 -1
- data/examples/run/ctrl_proc.rb.output +20 -0
- data/examples/run/ctrl_proc_rand.rb +23 -0
- data/examples/run/ctrl_slowstop.rb +16 -0
- data/examples/run/myserver_crashing.rb +2 -2
- data/examples/run/myserver_hanging.rb +21 -0
- data/examples/run/myserver_slowstop.rb +21 -0
- data/lib/daemons.rb +38 -10
- data/lib/daemons/application.rb +131 -26
- data/lib/daemons/application_group.rb +58 -10
- data/lib/daemons/change_privilege.rb +19 -0
- data/lib/daemons/cmdline.rb +10 -6
- data/lib/daemons/controller.rb +5 -2
- data/lib/daemons/daemonize.rb +64 -150
- data/lib/daemons/etc_extension.rb +12 -0
- data/lib/daemons/exceptions.rb +3 -0
- data/lib/daemons/monitor.rb +27 -19
- data/lib/daemons/pid.rb +13 -14
- data/lib/daemons/pidfile.rb +14 -7
- data/lib/daemons/pidmem.rb +9 -0
- data/lib/daemons/version.rb +1 -1
- data/spec/pidfile_spec.rb +12 -0
- data/spec/spec_helper.rb +1 -0
- metadata +31 -47
- data/daemons.tmproj +0 -56
- data/examples/run/myserver_crashing.rb.output +0 -30
- data/html/classes/Daemonize.html +0 -497
- data/html/classes/Daemons.html +0 -683
- data/html/classes/Daemons/Application.html +0 -836
- data/html/classes/Daemons/ApplicationGroup.html +0 -508
- data/html/classes/Daemons/CmdException.html +0 -113
- data/html/classes/Daemons/Controller.html +0 -429
- data/html/classes/Daemons/Error.html +0 -113
- data/html/classes/Daemons/Exception.html +0 -111
- data/html/classes/Daemons/Monitor.html +0 -263
- data/html/classes/Daemons/Optparse.html +0 -244
- data/html/classes/Daemons/Pid.html +0 -339
- data/html/classes/Daemons/PidFile.html +0 -441
- data/html/classes/Daemons/PidMem.html +0 -126
- data/html/classes/Daemons/RuntimeException.html +0 -113
- data/html/classes/Daemons/SystemError.html +0 -163
- data/html/created.rid +0 -1
- data/html/files/README.html +0 -377
- data/html/files/Releases.html +0 -342
- data/html/files/TODO.html +0 -121
- data/html/files/lib/daemons/application_group_rb.html +0 -101
- data/html/files/lib/daemons/application_rb.html +0 -110
- data/html/files/lib/daemons/cmdline_rb.html +0 -101
- data/html/files/lib/daemons/controller_rb.html +0 -101
- data/html/files/lib/daemons/daemonize_rb.html +0 -207
- data/html/files/lib/daemons/exceptions_rb.html +0 -101
- data/html/files/lib/daemons/monitor_rb.html +0 -108
- data/html/files/lib/daemons/pid_rb.html +0 -108
- data/html/files/lib/daemons/pidfile_rb.html +0 -108
- data/html/files/lib/daemons/pidmem_rb.html +0 -108
- data/html/files/lib/daemons_rb.html +0 -117
- data/html/fr_class_index.html +0 -41
- data/html/fr_file_index.html +0 -40
- data/html/fr_method_index.html +0 -91
- data/html/index.html +0 -24
- data/html/rdoc-style.css +0 -208
- data/test/call_as_daemon.rb +0 -12
- data/test/tc_main.rb +0 -24
- data/test/test1.rb +0 -19
- data/test/testapp.rb +0 -11
@@ -1,113 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
-
<head>
|
8
|
-
<title>Class: Daemons::RuntimeException</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
-
<script type="text/javascript">
|
13
|
-
// <![CDATA[
|
14
|
-
|
15
|
-
function popupCode( url ) {
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
-
}
|
18
|
-
|
19
|
-
function toggleCode( id ) {
|
20
|
-
if ( document.getElementById )
|
21
|
-
elem = document.getElementById( id );
|
22
|
-
else if ( document.all )
|
23
|
-
elem = eval( "document.all." + id );
|
24
|
-
else
|
25
|
-
return false;
|
26
|
-
|
27
|
-
elemStyle = elem.style;
|
28
|
-
|
29
|
-
if ( elemStyle.display != "block" ) {
|
30
|
-
elemStyle.display = "block"
|
31
|
-
} else {
|
32
|
-
elemStyle.display = "none"
|
33
|
-
}
|
34
|
-
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
|
38
|
-
// Make codeblocks hidden by default
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
-
|
41
|
-
// ]]>
|
42
|
-
</script>
|
43
|
-
|
44
|
-
</head>
|
45
|
-
<body>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<div id="classHeader">
|
50
|
-
<table class="header-table">
|
51
|
-
<tr class="top-aligned-row">
|
52
|
-
<td><strong>Class</strong></td>
|
53
|
-
<td class="class-name-in-header">Daemons::RuntimeException</td>
|
54
|
-
</tr>
|
55
|
-
<tr class="top-aligned-row">
|
56
|
-
<td><strong>In:</strong></td>
|
57
|
-
<td>
|
58
|
-
<a href="../../files/lib/daemons/exceptions_rb.html">
|
59
|
-
lib/daemons/exceptions.rb
|
60
|
-
</a>
|
61
|
-
<br />
|
62
|
-
</td>
|
63
|
-
</tr>
|
64
|
-
|
65
|
-
<tr class="top-aligned-row">
|
66
|
-
<td><strong>Parent:</strong></td>
|
67
|
-
<td>
|
68
|
-
<a href="Exception.html">
|
69
|
-
Exception
|
70
|
-
</a>
|
71
|
-
</td>
|
72
|
-
</tr>
|
73
|
-
</table>
|
74
|
-
</div>
|
75
|
-
<!-- banner header -->
|
76
|
-
|
77
|
-
<div id="bodyContent">
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
<div id="contextContent">
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
</div>
|
86
|
-
|
87
|
-
|
88
|
-
</div>
|
89
|
-
|
90
|
-
|
91
|
-
<!-- if includes -->
|
92
|
-
|
93
|
-
<div id="section">
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
<!-- if method_list -->
|
103
|
-
|
104
|
-
|
105
|
-
</div>
|
106
|
-
|
107
|
-
|
108
|
-
<div id="validator-badges">
|
109
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
110
|
-
</div>
|
111
|
-
|
112
|
-
</body>
|
113
|
-
</html>
|
@@ -1,163 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
-
<head>
|
8
|
-
<title>Class: Daemons::SystemError</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
-
<script type="text/javascript">
|
13
|
-
// <![CDATA[
|
14
|
-
|
15
|
-
function popupCode( url ) {
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
-
}
|
18
|
-
|
19
|
-
function toggleCode( id ) {
|
20
|
-
if ( document.getElementById )
|
21
|
-
elem = document.getElementById( id );
|
22
|
-
else if ( document.all )
|
23
|
-
elem = eval( "document.all." + id );
|
24
|
-
else
|
25
|
-
return false;
|
26
|
-
|
27
|
-
elemStyle = elem.style;
|
28
|
-
|
29
|
-
if ( elemStyle.display != "block" ) {
|
30
|
-
elemStyle.display = "block"
|
31
|
-
} else {
|
32
|
-
elemStyle.display = "none"
|
33
|
-
}
|
34
|
-
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
|
38
|
-
// Make codeblocks hidden by default
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
-
|
41
|
-
// ]]>
|
42
|
-
</script>
|
43
|
-
|
44
|
-
</head>
|
45
|
-
<body>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<div id="classHeader">
|
50
|
-
<table class="header-table">
|
51
|
-
<tr class="top-aligned-row">
|
52
|
-
<td><strong>Class</strong></td>
|
53
|
-
<td class="class-name-in-header">Daemons::SystemError</td>
|
54
|
-
</tr>
|
55
|
-
<tr class="top-aligned-row">
|
56
|
-
<td><strong>In:</strong></td>
|
57
|
-
<td>
|
58
|
-
<a href="../../files/lib/daemons/exceptions_rb.html">
|
59
|
-
lib/daemons/exceptions.rb
|
60
|
-
</a>
|
61
|
-
<br />
|
62
|
-
</td>
|
63
|
-
</tr>
|
64
|
-
|
65
|
-
<tr class="top-aligned-row">
|
66
|
-
<td><strong>Parent:</strong></td>
|
67
|
-
<td>
|
68
|
-
<a href="Error.html">
|
69
|
-
Error
|
70
|
-
</a>
|
71
|
-
</td>
|
72
|
-
</tr>
|
73
|
-
</table>
|
74
|
-
</div>
|
75
|
-
<!-- banner header -->
|
76
|
-
|
77
|
-
<div id="bodyContent">
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
<div id="contextContent">
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
</div>
|
86
|
-
|
87
|
-
<div id="method-list">
|
88
|
-
<h3 class="section-bar">Methods</h3>
|
89
|
-
|
90
|
-
<div class="name-list">
|
91
|
-
<a href="#M000046">new</a>
|
92
|
-
</div>
|
93
|
-
</div>
|
94
|
-
|
95
|
-
</div>
|
96
|
-
|
97
|
-
|
98
|
-
<!-- if includes -->
|
99
|
-
|
100
|
-
<div id="section">
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
<div id="attribute-list">
|
107
|
-
<h3 class="section-bar">Attributes</h3>
|
108
|
-
|
109
|
-
<div class="name-list">
|
110
|
-
<table>
|
111
|
-
<tr class="top-aligned-row context-row">
|
112
|
-
<td class="context-item-name">system_error</td>
|
113
|
-
<td class="context-item-value"> [R] </td>
|
114
|
-
<td class="context-item-desc"></td>
|
115
|
-
</tr>
|
116
|
-
</table>
|
117
|
-
</div>
|
118
|
-
</div>
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
<!-- if method_list -->
|
123
|
-
<div id="methods">
|
124
|
-
<h3 class="section-bar">Public Class methods</h3>
|
125
|
-
|
126
|
-
<div id="method-M000046" class="method-detail">
|
127
|
-
<a name="M000046"></a>
|
128
|
-
|
129
|
-
<div class="method-heading">
|
130
|
-
<a href="#M000046" class="method-signature">
|
131
|
-
<span class="method-name">new</span><span class="method-args">(msg, system_error)</span>
|
132
|
-
</a>
|
133
|
-
</div>
|
134
|
-
|
135
|
-
<div class="method-description">
|
136
|
-
<p><a class="source-toggle" href="#"
|
137
|
-
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
138
|
-
<div class="method-source-code" id="M000046-source">
|
139
|
-
<pre>
|
140
|
-
<span class="ruby-comment cmt"># File lib/daemons/exceptions.rb, line 20</span>
|
141
|
-
20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">msg</span>, <span class="ruby-identifier">system_error</span>)
|
142
|
-
21: <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">msg</span>)
|
143
|
-
22:
|
144
|
-
23: <span class="ruby-ivar">@system_error</span> = <span class="ruby-identifier">system_error</span>
|
145
|
-
24: <span class="ruby-keyword kw">end</span>
|
146
|
-
</pre>
|
147
|
-
</div>
|
148
|
-
</div>
|
149
|
-
</div>
|
150
|
-
|
151
|
-
|
152
|
-
</div>
|
153
|
-
|
154
|
-
|
155
|
-
</div>
|
156
|
-
|
157
|
-
|
158
|
-
<div id="validator-badges">
|
159
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
160
|
-
</div>
|
161
|
-
|
162
|
-
</body>
|
163
|
-
</html>
|
data/html/created.rid
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Wed, 26 Aug 2009 15:13:46 -0700
|
data/html/files/README.html
DELETED
@@ -1,377 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
-
<head>
|
8
|
-
<title>File: README</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
-
<script type="text/javascript">
|
13
|
-
// <![CDATA[
|
14
|
-
|
15
|
-
function popupCode( url ) {
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
-
}
|
18
|
-
|
19
|
-
function toggleCode( id ) {
|
20
|
-
if ( document.getElementById )
|
21
|
-
elem = document.getElementById( id );
|
22
|
-
else if ( document.all )
|
23
|
-
elem = eval( "document.all." + id );
|
24
|
-
else
|
25
|
-
return false;
|
26
|
-
|
27
|
-
elemStyle = elem.style;
|
28
|
-
|
29
|
-
if ( elemStyle.display != "block" ) {
|
30
|
-
elemStyle.display = "block"
|
31
|
-
} else {
|
32
|
-
elemStyle.display = "none"
|
33
|
-
}
|
34
|
-
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
|
38
|
-
// Make codeblocks hidden by default
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
-
|
41
|
-
// ]]>
|
42
|
-
</script>
|
43
|
-
|
44
|
-
</head>
|
45
|
-
<body>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<div id="fileHeader">
|
50
|
-
<h1>README</h1>
|
51
|
-
<table class="header-table">
|
52
|
-
<tr class="top-aligned-row">
|
53
|
-
<td><strong>Path:</strong></td>
|
54
|
-
<td>README
|
55
|
-
</td>
|
56
|
-
</tr>
|
57
|
-
<tr class="top-aligned-row">
|
58
|
-
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>Wed Aug 26 15:13:40 -0700 2009</td>
|
60
|
-
</tr>
|
61
|
-
</table>
|
62
|
-
</div>
|
63
|
-
<!-- banner header -->
|
64
|
-
|
65
|
-
<div id="bodyContent">
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
<div id="contextContent">
|
70
|
-
|
71
|
-
<div id="description">
|
72
|
-
<h1><a href="../classes/Daemons.html">Daemons</a> Version 1.0.11</h1>
|
73
|
-
<p>
|
74
|
-
(See Releases for release-specific information)
|
75
|
-
</p>
|
76
|
-
<h2>What is <a href="../classes/Daemons.html">Daemons</a>?</h2>
|
77
|
-
<p>
|
78
|
-
<a href="../classes/Daemons.html">Daemons</a> provides an easy way to wrap
|
79
|
-
existing ruby scripts (for example a self-written server) to be <em>run as
|
80
|
-
a daemon</em> and to be <em>controlled by simple start/stop/restart
|
81
|
-
commands</em>.
|
82
|
-
</p>
|
83
|
-
<p>
|
84
|
-
If you want, you can also use daemons to <em>run blocks of ruby code in a
|
85
|
-
daemon process</em> and to control these processes from the main
|
86
|
-
application.
|
87
|
-
</p>
|
88
|
-
<p>
|
89
|
-
Besides this basic functionality, daemons offers many advanced features
|
90
|
-
like <em>exception backtracing</em> and logging (in case your ruby script
|
91
|
-
crashes) and <em>monitoring</em> and automatic restarting of your processes
|
92
|
-
if they crash.
|
93
|
-
</p>
|
94
|
-
<p>
|
95
|
-
<a href="../classes/Daemons.html">Daemons</a> includes the
|
96
|
-
<tt>daemonize.rb</tt> script written by <em>Travis Whitton</em> to do the
|
97
|
-
daemonization process.
|
98
|
-
</p>
|
99
|
-
<h2>Basic Usage</h2>
|
100
|
-
<p>
|
101
|
-
You can use <a href="../classes/Daemons.html">Daemons</a> in four differet
|
102
|
-
ways:
|
103
|
-
</p>
|
104
|
-
<h3>1. Create wrapper scripts for your server scripts or applications</h3>
|
105
|
-
<p>
|
106
|
-
Layout: suppose you have your self-written server <tt>myserver.rb</tt>:
|
107
|
-
</p>
|
108
|
-
<pre>
|
109
|
-
# this is myserver.rb
|
110
|
-
# it does nothing really useful at the moment
|
111
|
-
|
112
|
-
loop do
|
113
|
-
sleep(5)
|
114
|
-
end
|
115
|
-
</pre>
|
116
|
-
<p>
|
117
|
-
To use <tt>myserver.rb</tt> in a production environment, you need to be
|
118
|
-
able to run <tt>myserver.rb</tt> in the <em>background</em> (this means
|
119
|
-
detach it from the console, fork it in the background, release all
|
120
|
-
directories and file descriptors).
|
121
|
-
</p>
|
122
|
-
<p>
|
123
|
-
Just create <tt>myserver_control.rb</tt> like this:
|
124
|
-
</p>
|
125
|
-
<pre>
|
126
|
-
# this is myserver_control.rb
|
127
|
-
|
128
|
-
require 'rubygems' # if you use RubyGems
|
129
|
-
require 'daemons'
|
130
|
-
|
131
|
-
Daemons.run('myserver.rb')
|
132
|
-
</pre>
|
133
|
-
<p>
|
134
|
-
And use it like this from the console:
|
135
|
-
</p>
|
136
|
-
<pre>
|
137
|
-
$ ruby myserver_control.rb start
|
138
|
-
(myserver.rb is now running in the background)
|
139
|
-
$ ruby myserver_control.rb restart
|
140
|
-
(...)
|
141
|
-
$ ruby myserver_control.rb stop
|
142
|
-
</pre>
|
143
|
-
<p>
|
144
|
-
For testing purposes you can even run <tt>myserver.rb</tt> <em>without
|
145
|
-
forking</em> in the background:
|
146
|
-
</p>
|
147
|
-
<pre>
|
148
|
-
$ ruby myserver_control.rb run
|
149
|
-
</pre>
|
150
|
-
<p>
|
151
|
-
An additional nice feature of <a href="../classes/Daemons.html">Daemons</a>
|
152
|
-
is that you can pass <em>additional arguments</em> to the script that
|
153
|
-
should be daemonized by seperating them by two <em>hyphens</em>:
|
154
|
-
</p>
|
155
|
-
<pre>
|
156
|
-
$ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
|
157
|
-
</pre>
|
158
|
-
<h3>2. Create wrapper scripts that include your server procs</h3>
|
159
|
-
<p>
|
160
|
-
Layout: suppose you have some code you want to run in the background and
|
161
|
-
control that background process from a script:
|
162
|
-
</p>
|
163
|
-
<pre>
|
164
|
-
# this is your code
|
165
|
-
# it does nothing really useful at the moment
|
166
|
-
|
167
|
-
loop do
|
168
|
-
sleep(5)
|
169
|
-
end
|
170
|
-
</pre>
|
171
|
-
<p>
|
172
|
-
To run this code as a daemon create <tt>myproc_control.rb</tt> like this
|
173
|
-
and include your code:
|
174
|
-
</p>
|
175
|
-
<pre>
|
176
|
-
# this is myproc_control.rb
|
177
|
-
|
178
|
-
require 'rubygems' # if you use RubyGems
|
179
|
-
require 'daemons'
|
180
|
-
|
181
|
-
Daemons.run_proc('myproc.rb') do
|
182
|
-
loop do
|
183
|
-
sleep(5)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
</pre>
|
187
|
-
<p>
|
188
|
-
And use it like this from the console:
|
189
|
-
</p>
|
190
|
-
<pre>
|
191
|
-
$ ruby myproc_control.rb start
|
192
|
-
(myproc.rb is now running in the background)
|
193
|
-
$ ruby myproc_control.rb restart
|
194
|
-
(...)
|
195
|
-
$ ruby myproc_control.rb stop
|
196
|
-
</pre>
|
197
|
-
<p>
|
198
|
-
For testing purposes you can even run <tt>myproc.rb</tt> <em>without
|
199
|
-
forking</em> in the background:
|
200
|
-
</p>
|
201
|
-
<pre>
|
202
|
-
$ ruby myproc_control.rb run
|
203
|
-
</pre>
|
204
|
-
<h3>3. Control a bunch of daemons from another application</h3>
|
205
|
-
<p>
|
206
|
-
Layout: you have an application <tt>my_app.rb</tt> that wants to run a
|
207
|
-
bunch of server tasks as daemon processes.
|
208
|
-
</p>
|
209
|
-
<pre>
|
210
|
-
# this is my_app.rb
|
211
|
-
|
212
|
-
require 'rubygems' # if you use RubyGems
|
213
|
-
require 'daemons'
|
214
|
-
|
215
|
-
task1 = Daemons.call(:multiple => true) do
|
216
|
-
# first server task
|
217
|
-
|
218
|
-
loop {
|
219
|
-
conn = accept_conn()
|
220
|
-
serve(conn)
|
221
|
-
}
|
222
|
-
end
|
223
|
-
|
224
|
-
task2 = Daemons.call do
|
225
|
-
# second server task
|
226
|
-
|
227
|
-
loop {
|
228
|
-
something_different()
|
229
|
-
}
|
230
|
-
end
|
231
|
-
|
232
|
-
# the parent process continues to run
|
233
|
-
|
234
|
-
# we can even control our tasks, for example stop them
|
235
|
-
task1.stop
|
236
|
-
task2.stop
|
237
|
-
|
238
|
-
exit
|
239
|
-
</pre>
|
240
|
-
<h3>4. <a href="../classes/Daemonize.html">Daemonize</a> the currently running process</h3>
|
241
|
-
<p>
|
242
|
-
Layout: you have an application <tt>my_daemon.rb</tt> that wants to run as
|
243
|
-
a daemon (but without the ability to be controlled by daemons via
|
244
|
-
start/stop commands)
|
245
|
-
</p>
|
246
|
-
<pre>
|
247
|
-
# this is my_daemons.rb
|
248
|
-
|
249
|
-
require 'rubygems' # if you use RubyGems
|
250
|
-
require 'daemons'
|
251
|
-
|
252
|
-
# Initialize the app while we're not a daemon
|
253
|
-
init()
|
254
|
-
|
255
|
-
# Become a daemon
|
256
|
-
Daemons.daemonize
|
257
|
-
|
258
|
-
# The server loop
|
259
|
-
loop {
|
260
|
-
conn = accept_conn()
|
261
|
-
serve(conn)
|
262
|
-
}
|
263
|
-
</pre>
|
264
|
-
<p>
|
265
|
-
<b>For further documentation, refer to the module documentation of <a
|
266
|
-
href="../classes/Daemons.html">Daemons</a>.</b>
|
267
|
-
</p>
|
268
|
-
<h2>Download and Installation</h2>
|
269
|
-
<p>
|
270
|
-
<b>Download</b>: just go to <a
|
271
|
-
href="http://rubyforge.org/projects/daemons">rubyforge.org/projects/daemons</a>/
|
272
|
-
</p>
|
273
|
-
<p>
|
274
|
-
Installation <b>with</b> RubyGems:
|
275
|
-
</p>
|
276
|
-
<pre>
|
277
|
-
$ su
|
278
|
-
# gem install daemons
|
279
|
-
</pre>
|
280
|
-
<p>
|
281
|
-
Installation <b>without</b> RubyGems:
|
282
|
-
</p>
|
283
|
-
<pre>
|
284
|
-
$ tar xfz daemons-x.x.x.tar.gz
|
285
|
-
$ cd daemons-x.x.x
|
286
|
-
$ su
|
287
|
-
# ruby setup.rb
|
288
|
-
</pre>
|
289
|
-
<h2>Documentation</h2>
|
290
|
-
<p>
|
291
|
-
For further documentation, refer to the module documentation of <a
|
292
|
-
href="../classes/Daemons.html">Daemons</a> (click on <a
|
293
|
-
href="../classes/Daemons.html">Daemons</a>).
|
294
|
-
</p>
|
295
|
-
<p>
|
296
|
-
The RDoc documentation is also online at <a
|
297
|
-
href="http://daemons.rubyforge.org">daemons.rubyforge.org</a>
|
298
|
-
</p>
|
299
|
-
<h2>Author</h2>
|
300
|
-
<p>
|
301
|
-
Written in 2005-2008 by Thomas Uehlinger <<a
|
302
|
-
href="mailto:th.uehlinger@gmx.ch">th.uehlinger@gmx.ch</a>>.
|
303
|
-
</p>
|
304
|
-
<h2>License</h2>
|
305
|
-
<p>
|
306
|
-
Copyright (c) 2005-2008 Thomas Uehlinger
|
307
|
-
</p>
|
308
|
-
<p>
|
309
|
-
Permission is hereby granted, free of charge, to any person obtaining a
|
310
|
-
copy of this software and associated documentation files (the
|
311
|
-
"Software"), to deal in the Software without restriction,
|
312
|
-
including without limitation the rights to use, copy, modify, merge,
|
313
|
-
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
314
|
-
permit persons to whom the Software is furnished to do so, subject to the
|
315
|
-
following conditions:
|
316
|
-
</p>
|
317
|
-
<p>
|
318
|
-
The above copyright notice and this permission notice shall be included in
|
319
|
-
all copies or substantial portions of the Software.
|
320
|
-
</p>
|
321
|
-
<p>
|
322
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
323
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
324
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
325
|
-
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
326
|
-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
327
|
-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
328
|
-
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
329
|
-
</p>
|
330
|
-
<p>
|
331
|
-
This license does not apply to daemonize.rb, which is was written by Travis
|
332
|
-
Whitton und published under the following license:
|
333
|
-
</p>
|
334
|
-
<p>
|
335
|
-
The <a href="../classes/Daemonize.html">Daemonize</a> extension module is
|
336
|
-
copywrited free software by Travis Whitton <whitton@atlantic.net>.
|
337
|
-
You can redistribute it under the terms specified in the COPYING file of
|
338
|
-
the Ruby distribution.
|
339
|
-
</p>
|
340
|
-
<h2>Feedback and other resources</h2>
|
341
|
-
<p>
|
342
|
-
At <a
|
343
|
-
href="http://rubyforge.org/projects/daemons">rubyforge.org/projects/daemons</a>.
|
344
|
-
</p>
|
345
|
-
|
346
|
-
</div>
|
347
|
-
|
348
|
-
|
349
|
-
</div>
|
350
|
-
|
351
|
-
|
352
|
-
</div>
|
353
|
-
|
354
|
-
|
355
|
-
<!-- if includes -->
|
356
|
-
|
357
|
-
<div id="section">
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
<!-- if method_list -->
|
367
|
-
|
368
|
-
|
369
|
-
</div>
|
370
|
-
|
371
|
-
|
372
|
-
<div id="validator-badges">
|
373
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
374
|
-
</div>
|
375
|
-
|
376
|
-
</body>
|
377
|
-
</html>
|