mlanett-daemons 1.0.13

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.
Files changed (85) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +17 -0
  4. data/LICENSE +29 -0
  5. data/README +223 -0
  6. data/Rakefile +15 -0
  7. data/Releases +126 -0
  8. data/TODO +6 -0
  9. data/daemons.gemspec +27 -0
  10. data/daemons.tmproj +56 -0
  11. data/examples/call/call.rb +56 -0
  12. data/examples/call/call.rb.log +1 -0
  13. data/examples/call/call_monitor.rb +55 -0
  14. data/examples/daemonize/daemonize.rb +20 -0
  15. data/examples/run/ctrl_crash.rb +17 -0
  16. data/examples/run/ctrl_exec.rb +16 -0
  17. data/examples/run/ctrl_exit.rb +15 -0
  18. data/examples/run/ctrl_keep_pid_files.rb +17 -0
  19. data/examples/run/ctrl_monitor.rb +16 -0
  20. data/examples/run/ctrl_multiple.rb +16 -0
  21. data/examples/run/ctrl_normal.rb +12 -0
  22. data/examples/run/ctrl_ontop.rb +16 -0
  23. data/examples/run/ctrl_optionparser.rb +43 -0
  24. data/examples/run/ctrl_proc.rb +25 -0
  25. data/examples/run/ctrl_proc.rb.output +101 -0
  26. data/examples/run/ctrl_proc_multiple.rb +22 -0
  27. data/examples/run/ctrl_proc_multiple.rb.output +2 -0
  28. data/examples/run/ctrl_proc_simple.rb +17 -0
  29. data/examples/run/myserver.rb +12 -0
  30. data/examples/run/myserver_crashing.rb +14 -0
  31. data/examples/run/myserver_crashing.rb.output +30 -0
  32. data/examples/run/myserver_exiting.rb +8 -0
  33. data/html/classes/Daemonize.html +497 -0
  34. data/html/classes/Daemons.html +683 -0
  35. data/html/classes/Daemons/Application.html +836 -0
  36. data/html/classes/Daemons/ApplicationGroup.html +508 -0
  37. data/html/classes/Daemons/CmdException.html +113 -0
  38. data/html/classes/Daemons/Controller.html +429 -0
  39. data/html/classes/Daemons/Error.html +113 -0
  40. data/html/classes/Daemons/Exception.html +111 -0
  41. data/html/classes/Daemons/Monitor.html +263 -0
  42. data/html/classes/Daemons/Optparse.html +244 -0
  43. data/html/classes/Daemons/Pid.html +339 -0
  44. data/html/classes/Daemons/PidFile.html +441 -0
  45. data/html/classes/Daemons/PidMem.html +126 -0
  46. data/html/classes/Daemons/RuntimeException.html +113 -0
  47. data/html/classes/Daemons/SystemError.html +163 -0
  48. data/html/created.rid +1 -0
  49. data/html/files/README.html +377 -0
  50. data/html/files/Releases.html +342 -0
  51. data/html/files/TODO.html +121 -0
  52. data/html/files/lib/daemons/application_group_rb.html +101 -0
  53. data/html/files/lib/daemons/application_rb.html +110 -0
  54. data/html/files/lib/daemons/cmdline_rb.html +101 -0
  55. data/html/files/lib/daemons/controller_rb.html +101 -0
  56. data/html/files/lib/daemons/daemonize_rb.html +207 -0
  57. data/html/files/lib/daemons/exceptions_rb.html +101 -0
  58. data/html/files/lib/daemons/monitor_rb.html +108 -0
  59. data/html/files/lib/daemons/pid_rb.html +108 -0
  60. data/html/files/lib/daemons/pidfile_rb.html +108 -0
  61. data/html/files/lib/daemons/pidmem_rb.html +108 -0
  62. data/html/files/lib/daemons_rb.html +117 -0
  63. data/html/fr_class_index.html +41 -0
  64. data/html/fr_file_index.html +40 -0
  65. data/html/fr_method_index.html +91 -0
  66. data/html/index.html +24 -0
  67. data/html/rdoc-style.css +208 -0
  68. data/lib/daemons.rb +284 -0
  69. data/lib/daemons/application.rb +376 -0
  70. data/lib/daemons/application_group.rb +152 -0
  71. data/lib/daemons/cmdline.rb +117 -0
  72. data/lib/daemons/controller.rb +137 -0
  73. data/lib/daemons/daemonize.rb +263 -0
  74. data/lib/daemons/exceptions.rb +28 -0
  75. data/lib/daemons/monitor.rb +136 -0
  76. data/lib/daemons/pid.rb +115 -0
  77. data/lib/daemons/pidfile.rb +111 -0
  78. data/lib/daemons/pidmem.rb +10 -0
  79. data/lib/daemons/version.rb +3 -0
  80. data/setup.rb +1360 -0
  81. data/test/call_as_daemon.rb +12 -0
  82. data/test/tc_main.rb +24 -0
  83. data/test/test1.rb +19 -0
  84. data/test/testapp.rb +11 -0
  85. metadata +170 -0
@@ -0,0 +1,683 @@
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>Module: Daemons</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>Module</strong></td>
53
+ <td class="class-name-in-header">Daemons</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/daemons/application_rb.html">
59
+ lib/daemons/application.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/daemons/application_group_rb.html">
63
+ lib/daemons/application_group.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/daemons/cmdline_rb.html">
67
+ lib/daemons/cmdline.rb
68
+ </a>
69
+ <br />
70
+ <a href="../files/lib/daemons/controller_rb.html">
71
+ lib/daemons/controller.rb
72
+ </a>
73
+ <br />
74
+ <a href="../files/lib/daemons/exceptions_rb.html">
75
+ lib/daemons/exceptions.rb
76
+ </a>
77
+ <br />
78
+ <a href="../files/lib/daemons/monitor_rb.html">
79
+ lib/daemons/monitor.rb
80
+ </a>
81
+ <br />
82
+ <a href="../files/lib/daemons/pid_rb.html">
83
+ lib/daemons/pid.rb
84
+ </a>
85
+ <br />
86
+ <a href="../files/lib/daemons/pidfile_rb.html">
87
+ lib/daemons/pidfile.rb
88
+ </a>
89
+ <br />
90
+ <a href="../files/lib/daemons/pidmem_rb.html">
91
+ lib/daemons/pidmem.rb
92
+ </a>
93
+ <br />
94
+ <a href="../files/lib/daemons_rb.html">
95
+ lib/daemons.rb
96
+ </a>
97
+ <br />
98
+ </td>
99
+ </tr>
100
+
101
+ </table>
102
+ </div>
103
+ <!-- banner header -->
104
+
105
+ <div id="bodyContent">
106
+
107
+
108
+
109
+ <div id="contextContent">
110
+
111
+ <div id="description">
112
+ <p>
113
+ All functions and classes that <a href="Daemons.html">Daemons</a> provides
114
+ reside in this module.
115
+ </p>
116
+ <p>
117
+ <a href="Daemons.html">Daemons</a> is normally invoked by one of the
118
+ following four ways:
119
+ </p>
120
+ <ol>
121
+ <li><tt><a href="Daemons.html#M000001">Daemons.run</a>(script, options)</tt>:
122
+ This is used in wrapper-scripts that are supposed to control other ruby
123
+ scripts or external applications. Control is completely passed to the
124
+ daemons library. Such wrapper script need to be invoked with command line
125
+ options like &#8216;start&#8217; or &#8216;stop&#8217; to do anything
126
+ useful.
127
+
128
+ </li>
129
+ <li><tt><a href="Daemons.html#M000002">Daemons.run_proc</a>(app_name, options)
130
+ { (&#8230;) }</tt>: This is used in wrapper-scripts that are supposed to
131
+ control a proc. Control is completely passed to the daemons library. Such
132
+ wrapper script need to be invoked with command line options like
133
+ &#8216;start&#8217; or &#8216;stop&#8217; to do anything useful.
134
+
135
+ </li>
136
+ <li><tt><a href="Daemons.html#M000003">Daemons.call(options)</a> { block
137
+ }</tt>: Execute the block in a new daemon. <tt><a
138
+ href="Daemons.html#M000003">Daemons.call</a></tt> will return immediately
139
+ after spawning the daemon with the new <a
140
+ href="Daemons/Application.html">Application</a> object as a return value.
141
+
142
+ </li>
143
+ <li><tt><a href="Daemons.html#M000004">Daemons.daemonize(options)</a></tt>: <a
144
+ href="Daemonize.html">Daemonize</a> the currently runnig process, i.e. the
145
+ calling process will become a daemon.
146
+
147
+ </li>
148
+ </ol>
149
+ <h2>What does daemons internally do with my daemons?</h2>
150
+ <table>
151
+ <tr><td valign="top"><b>or</b>:</td><td>why do my daemons crash when they try to open a file?
152
+
153
+ </td></tr>
154
+ <tr><td valign="top"><b>or</b>:</td><td>why can I not see any output from the daemon on the console (when using for
155
+ example <tt>puts</tt>)?
156
+
157
+ </td></tr>
158
+ </table>
159
+ <p>
160
+ From a technical aspect of view, daemons does the following when creating a
161
+ daemon:
162
+ </p>
163
+ <ol>
164
+ <li>Forks a child (and exits the parent process, if needed)
165
+
166
+ </li>
167
+ <li>Becomes a session leader (which detaches the program from the controlling
168
+ terminal).
169
+
170
+ </li>
171
+ <li>Forks another child process and exits first child. This prevents the
172
+ potential of acquiring a controlling terminal.
173
+
174
+ </li>
175
+ <li>Changes the current working directory to &quot;/&quot;.
176
+
177
+ </li>
178
+ <li>Clears the file creation mask (sets <tt>umask</tt> to 0000).
179
+
180
+ </li>
181
+ <li>Closes file descriptors (reopens <tt>STDOUT</tt> and <tt>STDERR</tt> to
182
+ point to a logfile if possible).
183
+
184
+ </li>
185
+ </ol>
186
+ <p>
187
+ So what does this mean for your daemons:
188
+ </p>
189
+ <ul>
190
+ <li>the current directory is &#8217;/&#8217;
191
+
192
+ </li>
193
+ <li>you cannot receive any input from the console (for example no
194
+ <tt>gets</tt>)
195
+
196
+ </li>
197
+ <li>you cannot output anything from the daemons with
198
+ <tt>puts</tt>/<tt>print</tt> unless a logfile is used
199
+
200
+ </li>
201
+ </ul>
202
+ <h2>How do PidFiles work? Where are they stored?</h2>
203
+ <p>
204
+ Also, you are maybe interested in reading the documentation for the class
205
+ <a href="Daemons/PidFile.html">PidFile</a>. There you can find out about
206
+ how <a href="Daemons.html">Daemons</a> works internally and how and where
207
+ the so called <em>PidFiles</em> are stored.
208
+ </p>
209
+
210
+ </div>
211
+
212
+
213
+ </div>
214
+
215
+ <div id="method-list">
216
+ <h3 class="section-bar">Methods</h3>
217
+
218
+ <div class="name-list">
219
+ <a href="#M000003">call</a>&nbsp;&nbsp;
220
+ <a href="#M000006">controller</a>&nbsp;&nbsp;
221
+ <a href="#M000004">daemonize</a>&nbsp;&nbsp;
222
+ <a href="#M000005">group</a>&nbsp;&nbsp;
223
+ <a href="#M000001">run</a>&nbsp;&nbsp;
224
+ <a href="#M000002">run_proc</a>&nbsp;&nbsp;
225
+ </div>
226
+ </div>
227
+
228
+ </div>
229
+
230
+
231
+ <!-- if includes -->
232
+
233
+ <div id="section">
234
+
235
+ <div id="class-list">
236
+ <h3 class="section-bar">Classes and Modules</h3>
237
+
238
+ Class <a href="Daemons/Application.html" class="link">Daemons::Application</a><br />
239
+ Class <a href="Daemons/ApplicationGroup.html" class="link">Daemons::ApplicationGroup</a><br />
240
+ Class <a href="Daemons/CmdException.html" class="link">Daemons::CmdException</a><br />
241
+ Class <a href="Daemons/Controller.html" class="link">Daemons::Controller</a><br />
242
+ Class <a href="Daemons/Error.html" class="link">Daemons::Error</a><br />
243
+ Class <a href="Daemons/Exception.html" class="link">Daemons::Exception</a><br />
244
+ Class <a href="Daemons/Monitor.html" class="link">Daemons::Monitor</a><br />
245
+ Class <a href="Daemons/Optparse.html" class="link">Daemons::Optparse</a><br />
246
+ Class <a href="Daemons/Pid.html" class="link">Daemons::Pid</a><br />
247
+ Class <a href="Daemons/PidFile.html" class="link">Daemons::PidFile</a><br />
248
+ Class <a href="Daemons/PidMem.html" class="link">Daemons::PidMem</a><br />
249
+ Class <a href="Daemons/RuntimeException.html" class="link">Daemons::RuntimeException</a><br />
250
+ Class <a href="Daemons/SystemError.html" class="link">Daemons::SystemError</a><br />
251
+
252
+ </div>
253
+
254
+ <div id="constants-list">
255
+ <h3 class="section-bar">Constants</h3>
256
+
257
+ <div class="name-list">
258
+ <table summary="Constants">
259
+ <tr class="top-aligned-row context-row">
260
+ <td class="context-item-name">VERSION</td>
261
+ <td>=</td>
262
+ <td class="context-item-value">&quot;1.0.11&quot;</td>
263
+ </tr>
264
+ </table>
265
+ </div>
266
+ </div>
267
+
268
+
269
+
270
+
271
+
272
+
273
+ <!-- if method_list -->
274
+ <div id="methods">
275
+ <h3 class="section-bar">Public Instance methods</h3>
276
+
277
+ <div id="method-M000003" class="method-detail">
278
+ <a name="M000003"></a>
279
+
280
+ <div class="method-heading">
281
+ <a href="#M000003" class="method-signature">
282
+ <span class="method-name">call</span><span class="method-args">(options = {}, &amp;block)</span>
283
+ </a>
284
+ </div>
285
+
286
+ <div class="method-description">
287
+ <p>
288
+ Execute the block in a new daemon. <tt><a
289
+ href="Daemons.html#M000003">Daemons.call</a></tt> will return immediately
290
+ after spawning the daemon with the new <a
291
+ href="Daemons/Application.html">Application</a> object as a return value.
292
+ </p>
293
+ <table>
294
+ <tr><td valign="top"><tt>options</tt>:</td><td>A hash that may contain one or more of the options listed below
295
+
296
+ </td></tr>
297
+ <tr><td valign="top"><tt>block</tt>:</td><td>The block to <a href="Daemons.html#M000003">call</a> in the daemon.
298
+
299
+ </td></tr>
300
+ </table>
301
+ <h3>Options:</h3>
302
+ <table>
303
+ <tr><td valign="top"><tt>:multiple</tt>:</td><td>Specifies whether multiple instances of the same script are allowed to <a
304
+ href="Daemons.html#M000001">run</a> at the same time
305
+
306
+ </td></tr>
307
+ <tr><td valign="top"><tt>:ontop</tt>:</td><td>When given, stay on top, i.e. do not <a
308
+ href="Daemons.html#M000004">daemonize</a> the application
309
+
310
+ </td></tr>
311
+ <tr><td valign="top"><tt>:backtrace</tt>:</td><td>Write a backtrace of the last exceptions to the file
312
+ &#8217;[app_name].log&#8217; in the pid-file directory if the application
313
+ exits due to an uncaught exception
314
+
315
+ </td></tr>
316
+ </table>
317
+ <hr size="3"></hr><h3>Example:</h3>
318
+ <pre>
319
+ options = {
320
+ :backtrace =&gt; true,
321
+ :monitor =&gt; true,
322
+ :ontop =&gt; true
323
+ }
324
+
325
+ Daemons.call(options) begin
326
+ # Server loop:
327
+ loop {
328
+ conn = accept_conn()
329
+ serve(conn)
330
+ }
331
+ end
332
+ </pre>
333
+ <p><a class="source-toggle" href="#"
334
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
335
+ <div class="method-source-code" id="M000003-source">
336
+ <pre>
337
+ <span class="ruby-comment cmt"># File lib/daemons.rb, line 227</span>
338
+ 227: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
339
+ 228: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block_given?</span>
340
+ 229: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Daemons.call: no block given&quot;</span>
341
+ 230: <span class="ruby-keyword kw">end</span>
342
+ 231:
343
+ 232: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:proc</span>] = <span class="ruby-identifier">block</span>
344
+ 233: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:mode</span>] = <span class="ruby-identifier">:proc</span>
345
+ 234:
346
+ 235: <span class="ruby-ivar">@group</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">ApplicationGroup</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'proc'</span>, <span class="ruby-identifier">options</span>)
347
+ 236:
348
+ 237: <span class="ruby-identifier">new_app</span> = <span class="ruby-ivar">@group</span>.<span class="ruby-identifier">new_application</span>(<span class="ruby-identifier">options</span>)
349
+ 238: <span class="ruby-identifier">new_app</span>.<span class="ruby-identifier">start</span>
350
+ 239:
351
+ 240: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">new_app</span>
352
+ 241: <span class="ruby-keyword kw">end</span>
353
+ </pre>
354
+ </div>
355
+ </div>
356
+ </div>
357
+
358
+ <div id="method-M000006" class="method-detail">
359
+ <a name="M000006"></a>
360
+
361
+ <div class="method-heading">
362
+ <a href="#M000006" class="method-signature">
363
+ <span class="method-name">controller</span><span class="method-args">()</span>
364
+ </a>
365
+ </div>
366
+
367
+ <div class="method-description">
368
+ <p>
369
+ Return the internal <a href="Daemons/Controller.html">Controller</a>
370
+ instance.
371
+ </p>
372
+ <p><a class="source-toggle" href="#"
373
+ onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
374
+ <div class="method-source-code" id="M000006-source">
375
+ <pre>
376
+ <span class="ruby-comment cmt"># File lib/daemons.rb, line 281</span>
377
+ 281: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">controller</span>; <span class="ruby-ivar">@controller</span>; <span class="ruby-keyword kw">end</span>
378
+ </pre>
379
+ </div>
380
+ </div>
381
+ </div>
382
+
383
+ <div id="method-M000004" class="method-detail">
384
+ <a name="M000004"></a>
385
+
386
+ <div class="method-heading">
387
+ <a href="#M000004" class="method-signature">
388
+ <span class="method-name">daemonize</span><span class="method-args">(options = {})</span>
389
+ </a>
390
+ </div>
391
+
392
+ <div class="method-description">
393
+ <p>
394
+ <a href="Daemonize.html">Daemonize</a> the currently runnig process, i.e.
395
+ the calling process will become a daemon.
396
+ </p>
397
+ <table>
398
+ <tr><td valign="top"><tt>options</tt>:</td><td>A hash that may contain one or more of the options listed below
399
+
400
+ </td></tr>
401
+ </table>
402
+ <h3>Options:</h3>
403
+ <table>
404
+ <tr><td valign="top"><tt>:ontop</tt>:</td><td>When given, stay on top, i.e. do not <a
405
+ href="Daemons.html#M000004">daemonize</a> the application
406
+
407
+ </td></tr>
408
+ <tr><td valign="top"><tt>:backtrace</tt>:</td><td>Write a backtrace of the last exceptions to the file
409
+ &#8217;[app_name].log&#8217; in the pid-file directory if the application
410
+ exits due to an uncaught exception
411
+
412
+ </td></tr>
413
+ </table>
414
+ <hr size="3"></hr><h3>Example:</h3>
415
+ <pre>
416
+ options = {
417
+ :backtrace =&gt; true,
418
+ :ontop =&gt; true
419
+ }
420
+
421
+ Daemons.daemonize(options)
422
+
423
+ # Server loop:
424
+ loop {
425
+ conn = accept_conn()
426
+ serve(conn)
427
+ }
428
+ </pre>
429
+ <p><a class="source-toggle" href="#"
430
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
431
+ <div class="method-source-code" id="M000004-source">
432
+ <pre>
433
+ <span class="ruby-comment cmt"># File lib/daemons.rb, line 269</span>
434
+ 269: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">daemonize</span>(<span class="ruby-identifier">options</span> = {})
435
+ 270: <span class="ruby-ivar">@group</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">ApplicationGroup</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'self'</span>, <span class="ruby-identifier">options</span>)
436
+ 271:
437
+ 272: <span class="ruby-ivar">@group</span>.<span class="ruby-identifier">new_application</span>(<span class="ruby-identifier">:mode</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:none</span>).<span class="ruby-identifier">start</span>
438
+ 273: <span class="ruby-keyword kw">end</span>
439
+ </pre>
440
+ </div>
441
+ </div>
442
+ </div>
443
+
444
+ <div id="method-M000005" class="method-detail">
445
+ <a name="M000005"></a>
446
+
447
+ <div class="method-heading">
448
+ <a href="#M000005" class="method-signature">
449
+ <span class="method-name">group</span><span class="method-args">()</span>
450
+ </a>
451
+ </div>
452
+
453
+ <div class="method-description">
454
+ <p>
455
+ Return the internal <a
456
+ href="Daemons/ApplicationGroup.html">ApplicationGroup</a> instance.
457
+ </p>
458
+ <p><a class="source-toggle" href="#"
459
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
460
+ <div class="method-source-code" id="M000005-source">
461
+ <pre>
462
+ <span class="ruby-comment cmt"># File lib/daemons.rb, line 277</span>
463
+ 277: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">group</span>; <span class="ruby-ivar">@group</span>; <span class="ruby-keyword kw">end</span>
464
+ </pre>
465
+ </div>
466
+ </div>
467
+ </div>
468
+
469
+ <div id="method-M000001" class="method-detail">
470
+ <a name="M000001"></a>
471
+
472
+ <div class="method-heading">
473
+ <a href="#M000001" class="method-signature">
474
+ <span class="method-name">run</span><span class="method-args">(script, options = {})</span>
475
+ </a>
476
+ </div>
477
+
478
+ <div class="method-description">
479
+ <p>
480
+ Passes control to <a href="Daemons.html">Daemons</a>. This is used in
481
+ wrapper-scripts that are supposed to control other ruby scripts or external
482
+ applications. Control is completely passed to the daemons library. Such
483
+ wrapper script should be invoked with command line options like
484
+ &#8216;start&#8217; or &#8216;stop&#8217; to do anything useful.
485
+ </p>
486
+ <table>
487
+ <tr><td valign="top"><tt>script</tt>:</td><td>This is the path to the script that should be <a
488
+ href="Daemons.html#M000001">run</a> as a daemon. Please note that <a
489
+ href="Daemons.html">Daemons</a> runs this script with <tt>load
490
+ &lt;script&gt;</tt>. Also note that <a href="Daemons.html">Daemons</a>
491
+ cannot detect the directory in which the controlling script resides, so
492
+ this has to be either an absolute path or you have to <a
493
+ href="Daemons.html#M000001">run</a> the controlling script from the
494
+ appropriate directory.
495
+
496
+ </td></tr>
497
+ <tr><td valign="top"><tt>options</tt>:</td><td>A hash that may contain one or more of the options listed below
498
+
499
+ </td></tr>
500
+ </table>
501
+ <h3>Options:</h3>
502
+ <table>
503
+ <tr><td valign="top"><tt>:app_name</tt>:</td><td>The name of the application. This will be used to contruct the name of the
504
+ pid files and log files. Defaults to the basename of the script.
505
+
506
+ </td></tr>
507
+ <tr><td valign="top"><tt>:ARGV</tt>:</td><td>An array of strings containing parameters and switches for <a
508
+ href="Daemons.html">Daemons</a>. This includes both parameters for <a
509
+ href="Daemons.html">Daemons</a> itself and the controlled scripted. These
510
+ are assumed to be separated by an array element &#8217;&#8212;&#8217;,
511
+ .e.g. [&#8216;start&#8217;, &#8216;f&#8217;, &#8217;&#8212;&#8217;,
512
+ &#8216;param1_for_script&#8217;, &#8216;param2_for_script&#8217;]. If not
513
+ given, ARGV (the parameters given to the Ruby process) will be used.
514
+
515
+ </td></tr>
516
+ <tr><td valign="top"><tt>:dir_mode</tt>:</td><td>Either <tt>:script</tt> (the directory for writing the pid files to given
517
+ by <tt>:dir</tt> is interpreted relative to the script location given by
518
+ <tt>script</tt>) or <tt>:normal</tt> (the directory given by <tt>:dir</tt>
519
+ is interpreted as a (absolute or relative) path) or <tt>:system</tt>
520
+ (<tt>/var/run</tt> is used as the pid file directory)
521
+
522
+ </td></tr>
523
+ <tr><td valign="top"><tt>:dir</tt>:</td><td>Used in combination with <tt>:dir_mode</tt> (description above)
524
+
525
+ </td></tr>
526
+ <tr><td valign="top"><tt>:multiple</tt>:</td><td>Specifies whether multiple instances of the same script are allowed to <a
527
+ href="Daemons.html#M000001">run</a> at the same time
528
+
529
+ </td></tr>
530
+ <tr><td valign="top"><tt>:ontop</tt>:</td><td>When given (i.e. set to true), stay on top, i.e. do not <a
531
+ href="Daemons.html#M000004">daemonize</a> the application (but the pid-file
532
+ and other things are written as usual)
533
+
534
+ </td></tr>
535
+ <tr><td valign="top"><tt>:mode</tt>:</td><td><tt>:load</tt> Load the script with <tt>Kernel.load</tt>; <tt>:exec</tt>
536
+ Execute the script file with <tt>Kernel.exec</tt>
537
+
538
+ </td></tr>
539
+ <tr><td valign="top"><tt>:backtrace</tt>:</td><td>Write a backtrace of the last exceptions to the file
540
+ &#8217;[app_name].log&#8217; in the pid-file directory if the application
541
+ exits due to an uncaught exception
542
+
543
+ </td></tr>
544
+ <tr><td valign="top"><tt>:monitor</tt>:</td><td><a href="Daemons/Monitor.html">Monitor</a> the programs and restart crashed
545
+ instances
546
+
547
+ </td></tr>
548
+ <tr><td valign="top"><tt>:log_output</tt>:</td><td>When given (i.e. set to true), redirect both STDOUT and STDERR to a logfile
549
+ named &#8217;[app_name].output&#8217; in the pid-file directory
550
+
551
+ </td></tr>
552
+ <tr><td valign="top"><tt>:keep_pid_files</tt>:</td><td>When given do not delete lingering pid-files (files for which the process
553
+ is no longer running).
554
+
555
+ </td></tr>
556
+ <tr><td valign="top"><tt>:hard_exit</tt>:</td><td>When given use exit! to end a daemons instead of exit (this will for
557
+ example not <a href="Daemons.html#M000003">call</a> at_exit handlers).
558
+
559
+ </td></tr>
560
+ </table>
561
+ <hr size="3"></hr><h3>Example:</h3>
562
+ <pre>
563
+ options = {
564
+ :app_name =&gt; &quot;my_app&quot;,
565
+ :ARGV =&gt; ['start', '-f', '--', 'param_for_myscript']
566
+ :dir_mode =&gt; :script,
567
+ :dir =&gt; 'pids',
568
+ :multiple =&gt; true,
569
+ :ontop =&gt; true,
570
+ :mode =&gt; :exec,
571
+ :backtrace =&gt; true,
572
+ :monitor =&gt; true
573
+ }
574
+
575
+ Daemons.run(File.join(File.dirname(__FILE__), 'myscript.rb'), options)
576
+ </pre>
577
+ <p><a class="source-toggle" href="#"
578
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
579
+ <div class="method-source-code" id="M000001-source">
580
+ <pre>
581
+ <span class="ruby-comment cmt"># File lib/daemons.rb, line 134</span>
582
+ 134: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>(<span class="ruby-identifier">script</span>, <span class="ruby-identifier">options</span> = {})
583
+ 135: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:script</span>] = <span class="ruby-identifier">script</span>
584
+ 136: <span class="ruby-ivar">@controller</span> = <span class="ruby-constant">Controller</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:ARGV</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">ARGV</span>)
585
+ 137:
586
+ 138: <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">catch_exceptions</span> {
587
+ 139: <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">run</span>
588
+ 140: }
589
+ 141:
590
+ 142: <span class="ruby-comment cmt"># I don't think anybody will ever use @group, as this location should not be reached under non-error conditions</span>
591
+ 143: <span class="ruby-ivar">@group</span> = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">group</span>
592
+ 144: <span class="ruby-keyword kw">end</span>
593
+ </pre>
594
+ </div>
595
+ </div>
596
+ </div>
597
+
598
+ <div id="method-M000002" class="method-detail">
599
+ <a name="M000002"></a>
600
+
601
+ <div class="method-heading">
602
+ <a href="#M000002" class="method-signature">
603
+ <span class="method-name">run_proc</span><span class="method-args">(app_name, options = {}, &amp;block)</span>
604
+ </a>
605
+ </div>
606
+
607
+ <div class="method-description">
608
+ <p>
609
+ Passes control to <a href="Daemons.html">Daemons</a>. This function does
610
+ the same as <a href="Daemons.html#M000001">Daemons.run</a> except that not
611
+ a script but a proc will be <a href="Daemons.html#M000001">run</a> as a
612
+ daemon while this script provides command line options like
613
+ &#8216;start&#8217; or &#8216;stop&#8217; and the whole pid-file management
614
+ to control the proc.
615
+ </p>
616
+ <table>
617
+ <tr><td valign="top"><tt>app_name</tt>:</td><td>The name of the application. This will be used to contruct the name of the
618
+ pid files and log files. Defaults to the basename of the script.
619
+
620
+ </td></tr>
621
+ <tr><td valign="top"><tt>options</tt>:</td><td>A hash that may contain one or more of the options listed in the
622
+ documentation for <a href="Daemons.html#M000001">Daemons.run</a>
623
+
624
+ </td></tr>
625
+ </table>
626
+ <p>
627
+ A block must be given to this function. The block will be used as the :proc
628
+ entry in the options hash.
629
+ </p>
630
+ <hr size="3"></hr><h3>Example:</h3>
631
+ <pre>
632
+ Daemons.run_proc('myproc.rb') do
633
+ loop do
634
+ accept_connection()
635
+ read_request()
636
+ send_response()
637
+ close_connection()
638
+ end
639
+ end
640
+ </pre>
641
+ <p><a class="source-toggle" href="#"
642
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
643
+ <div class="method-source-code" id="M000002-source">
644
+ <pre>
645
+ <span class="ruby-comment cmt"># File lib/daemons.rb, line 174</span>
646
+ 174: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run_proc</span>(<span class="ruby-identifier">app_name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
647
+ 175: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:app_name</span>] = <span class="ruby-identifier">app_name</span>
648
+ 176: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:mode</span>] = <span class="ruby-identifier">:proc</span>
649
+ 177: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:proc</span>] = <span class="ruby-identifier">block</span>
650
+ 178:
651
+ 179: <span class="ruby-comment cmt"># we do not have a script location so the the :script :dir_mode cannot be used, change it to :normal</span>
652
+ 180: <span class="ruby-keyword kw">if</span> [<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:script</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:dir_mode</span>]
653
+ 181: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:dir_mode</span>] = <span class="ruby-identifier">:normal</span>
654
+ 182: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:dir</span>] = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-value str">'.'</span>)
655
+ 183: <span class="ruby-keyword kw">end</span>
656
+ 184:
657
+ 185: <span class="ruby-ivar">@controller</span> = <span class="ruby-constant">Controller</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:ARGV</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">ARGV</span>)
658
+ 186:
659
+ 187: <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">catch_exceptions</span> {
660
+ 188: <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">run</span>
661
+ 189: }
662
+ 190:
663
+ 191: <span class="ruby-comment cmt"># I don't think anybody will ever use @group, as this location should not be reached under non-error conditions</span>
664
+ 192: <span class="ruby-ivar">@group</span> = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">group</span>
665
+ 193: <span class="ruby-keyword kw">end</span>
666
+ </pre>
667
+ </div>
668
+ </div>
669
+ </div>
670
+
671
+
672
+ </div>
673
+
674
+
675
+ </div>
676
+
677
+
678
+ <div id="validator-badges">
679
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
680
+ </div>
681
+
682
+ </body>
683
+ </html>