pidify 0.1.0-i386-linux

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.
@@ -0,0 +1,338 @@
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: Pidify</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">Pidify</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/pidify_rb.html">
59
+ pidify.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+ <div id="description">
76
+ <p>
77
+ Use the module methods in <a href="Pidify.html">Pidify</a> to save/delete
78
+ the PID of a running script, or kill a running script using a saved PID.
79
+ </p>
80
+ <p>
81
+ Example:
82
+ </p>
83
+ <pre>
84
+ require 'pidify'
85
+ Pidify.running? # =&gt; false
86
+ Pidify.start
87
+ Pidify.running? # =&gt; true
88
+ puts &quot;I am running with PID #{Pidify.pid}!&quot;
89
+ Pidify.stop
90
+ Pidify.running? # =&gt; false
91
+ </pre>
92
+ <p>
93
+ A more useful example:
94
+ </p>
95
+ <pre>
96
+ require 'pidify'
97
+ require 'daemons'
98
+ Signal.trap('INT') { Pidify.stop; exit }
99
+ module Doer
100
+ def self.start
101
+ puts &quot;starting&quot;
102
+ raise &quot;Failed to start: already running (PID file exists).&quot; if Pidify.running?
103
+ Daemons.daemonize
104
+ Pidify.start
105
+ loop do
106
+ puts &quot;hello world&quot;
107
+ sleep 1
108
+ end
109
+ end
110
+ end
111
+ if ARGV.include? 'stop'
112
+ Pidify.stop
113
+ puts &quot;Daemon stopped.&quot;
114
+ else
115
+ puts &quot;Daemon starting.&quot;
116
+ Doer.start
117
+ end
118
+ </pre>
119
+
120
+ </div>
121
+
122
+
123
+ </div>
124
+
125
+ <div id="method-list">
126
+ <h3 class="section-bar">Methods</h3>
127
+
128
+ <div class="name-list">
129
+ <a href="#M000007">delete_pid</a>&nbsp;&nbsp;
130
+ <a href="#M000005">pid</a>&nbsp;&nbsp;
131
+ <a href="#M000001">pid_directory</a>&nbsp;&nbsp;
132
+ <a href="#M000002">pid_directory=</a>&nbsp;&nbsp;
133
+ <a href="#M000003">pid_file</a>&nbsp;&nbsp;
134
+ <a href="#M000004">running?</a>&nbsp;&nbsp;
135
+ <a href="#M000006">save_pid</a>&nbsp;&nbsp;
136
+ <a href="#M000008">start</a>&nbsp;&nbsp;
137
+ <a href="#M000009">stop</a>&nbsp;&nbsp;
138
+ </div>
139
+ </div>
140
+
141
+ </div>
142
+
143
+
144
+ <!-- if includes -->
145
+
146
+ <div id="section">
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ <!-- if method_list -->
156
+ <div id="methods">
157
+ <h3 class="section-bar">Public Class methods</h3>
158
+
159
+ <div id="method-M000007" class="method-detail">
160
+ <a name="M000007"></a>
161
+
162
+ <div class="method-heading">
163
+ <a href="Pidify.src/M000007.html" target="Code" class="method-signature"
164
+ onclick="popupCode('Pidify.src/M000007.html');return false;">
165
+ <span class="method-name">delete_pid</span><span class="method-args">()</span>
166
+ </a>
167
+ </div>
168
+
169
+ <div class="method-description">
170
+ <p>
171
+ Deletes the PID file. Calling stop calls this automatically, but will also
172
+ try to send a kill signal to the running process, if it is different from
173
+ this one. BEWARE that this tries to delete whatever file is returned by <a
174
+ href="Pidify.html#M000003">pid_file</a> and does no error checking on it!
175
+ </p>
176
+ </div>
177
+ </div>
178
+
179
+ <div id="method-M000005" class="method-detail">
180
+ <a name="M000005"></a>
181
+
182
+ <div class="method-heading">
183
+ <a href="Pidify.src/M000005.html" target="Code" class="method-signature"
184
+ onclick="popupCode('Pidify.src/M000005.html');return false;">
185
+ <span class="method-name">pid</span><span class="method-args">()</span>
186
+ </a>
187
+ </div>
188
+
189
+ <div class="method-description">
190
+ <p>
191
+ Returns the PID stored in the <a href="Pidify.html#M000003">pid_file</a>
192
+ (not necessarily the PID of this script).
193
+ </p>
194
+ </div>
195
+ </div>
196
+
197
+ <div id="method-M000001" class="method-detail">
198
+ <a name="M000001"></a>
199
+
200
+ <div class="method-heading">
201
+ <a href="Pidify.src/M000001.html" target="Code" class="method-signature"
202
+ onclick="popupCode('Pidify.src/M000001.html');return false;">
203
+ <span class="method-name">pid_directory</span><span class="method-args">()</span>
204
+ </a>
205
+ </div>
206
+
207
+ <div class="method-description">
208
+ <p>
209
+ Returns the Pathname of the PID storage directory (defaults to /var/run).
210
+ </p>
211
+ </div>
212
+ </div>
213
+
214
+ <div id="method-M000002" class="method-detail">
215
+ <a name="M000002"></a>
216
+
217
+ <div class="method-heading">
218
+ <a href="Pidify.src/M000002.html" target="Code" class="method-signature"
219
+ onclick="popupCode('Pidify.src/M000002.html');return false;">
220
+ <span class="method-name">pid_directory=</span><span class="method-args">(dir)</span>
221
+ </a>
222
+ </div>
223
+
224
+ <div class="method-description">
225
+ <p>
226
+ Sets the PID storage directory (defaults to /var/run). Be VERY CAREFUL
227
+ using this, as <a href="Pidify.html#M000007">delete_pid</a> will try to
228
+ delete whatever file it thinks is the <a
229
+ href="Pidify.html#M000003">pid_file</a> for this script in the <a
230
+ href="Pidify.html#M000001">pid_directory</a>. It&#8217;s probably a good
231
+ idea not to change this at all.
232
+ </p>
233
+ </div>
234
+ </div>
235
+
236
+ <div id="method-M000003" class="method-detail">
237
+ <a name="M000003"></a>
238
+
239
+ <div class="method-heading">
240
+ <a href="Pidify.src/M000003.html" target="Code" class="method-signature"
241
+ onclick="popupCode('Pidify.src/M000003.html');return false;">
242
+ <span class="method-name">pid_file</span><span class="method-args">()</span>
243
+ </a>
244
+ </div>
245
+
246
+ <div class="method-description">
247
+ <p>
248
+ Returns the PID filename as a Pathname.
249
+ </p>
250
+ </div>
251
+ </div>
252
+
253
+ <div id="method-M000004" class="method-detail">
254
+ <a name="M000004"></a>
255
+
256
+ <div class="method-heading">
257
+ <a href="Pidify.src/M000004.html" target="Code" class="method-signature"
258
+ onclick="popupCode('Pidify.src/M000004.html');return false;">
259
+ <span class="method-name">running?</span><span class="method-args">()</span>
260
+ </a>
261
+ </div>
262
+
263
+ <div class="method-description">
264
+ <p>
265
+ Returns true if the PID file exists for this script.
266
+ </p>
267
+ </div>
268
+ </div>
269
+
270
+ <div id="method-M000006" class="method-detail">
271
+ <a name="M000006"></a>
272
+
273
+ <div class="method-heading">
274
+ <a href="Pidify.src/M000006.html" target="Code" class="method-signature"
275
+ onclick="popupCode('Pidify.src/M000006.html');return false;">
276
+ <span class="method-name">save_pid</span><span class="method-args">()</span>
277
+ </a>
278
+ </div>
279
+
280
+ <div class="method-description">
281
+ <p>
282
+ Saves the PID of this script into the <a
283
+ href="Pidify.html#M000003">pid_file</a>. Automatically called by start.
284
+ </p>
285
+ </div>
286
+ </div>
287
+
288
+ <div id="method-M000008" class="method-detail">
289
+ <a name="M000008"></a>
290
+
291
+ <div class="method-heading">
292
+ <a href="Pidify.src/M000008.html" target="Code" class="method-signature"
293
+ onclick="popupCode('Pidify.src/M000008.html');return false;">
294
+ <span class="method-name">start</span><span class="method-args">()</span>
295
+ </a>
296
+ </div>
297
+
298
+ <div class="method-description">
299
+ <p>
300
+ Saves the PID of this script into the <a
301
+ href="Pidify.html#M000003">pid_file</a> by calling <a
302
+ href="Pidify.html#M000006">save_pid</a>. Raises an exception if running?
303
+ returns false.
304
+ </p>
305
+ </div>
306
+ </div>
307
+
308
+ <div id="method-M000009" class="method-detail">
309
+ <a name="M000009"></a>
310
+
311
+ <div class="method-heading">
312
+ <a href="Pidify.src/M000009.html" target="Code" class="method-signature"
313
+ onclick="popupCode('Pidify.src/M000009.html');return false;">
314
+ <span class="method-name">stop</span><span class="method-args">(signal='SIGINT')</span>
315
+ </a>
316
+ </div>
317
+
318
+ <div class="method-description">
319
+ <p>
320
+ Deletes the saved PID file and, if the PID belongs to a process different
321
+ from this script, sends a kill signal to the saved PID.
322
+ </p>
323
+ </div>
324
+ </div>
325
+
326
+
327
+ </div>
328
+
329
+
330
+ </div>
331
+
332
+
333
+ <div id="validator-badges">
334
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
335
+ </div>
336
+
337
+ </body>
338
+ </html>
@@ -0,0 +1,18 @@
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>
7
+ <head>
8
+ <title>pid_directory (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 71</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pid_directory</span>
15
+ <span class="ruby-ivar">@pid_directory</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,19 @@
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>
7
+ <head>
8
+ <title>pid_directory= (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 79</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pid_directory=</span>(<span class="ruby-identifier">dir</span>)
15
+ <span class="ruby-ivar">@pid_directory</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">dir</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Pathname</span>
16
+ <span class="ruby-ivar">@pid_directory</span> = <span class="ruby-identifier">dir</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Pathname</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -0,0 +1,18 @@
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>
7
+ <head>
8
+ <title>pid_file (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 85</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pid_file</span>
15
+ <span class="ruby-ivar">@pid_directory</span> <span class="ruby-operator">+</span> (<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">$0</span>).<span class="ruby-identifier">basename</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">'.pid'</span>)
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
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>
7
+ <head>
8
+ <title>running? (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 90</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">running?</span>
15
+ <span class="ruby-keyword kw">return</span> <span class="ruby-constant">FileTest</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">pid_file</span>)
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,20 @@
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>
7
+ <head>
8
+ <title>pid (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 96</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pid</span>
15
+ <span class="ruby-identifier">dpid</span> = <span class="ruby-keyword kw">nil</span>
16
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">pid_file</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span> <span class="ruby-identifier">dpid</span> = <span class="ruby-identifier">file</span>.<span class="ruby-identifier">gets</span>.<span class="ruby-identifier">chomp</span> }
17
+ <span class="ruby-identifier">dpid</span>.<span class="ruby-identifier">to_i</span>
18
+ <span class="ruby-keyword kw">end</span></pre>
19
+ </body>
20
+ </html>
@@ -0,0 +1,18 @@
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>
7
+ <head>
8
+ <title>save_pid (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 103</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_pid</span>
15
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">pid_file</span>, <span class="ruby-value str">'w'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">$$</span> }
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
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>
7
+ <head>
8
+ <title>delete_pid (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 111</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_pid</span>
15
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">pid_file</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">FileTest</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">pid_file</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,19 @@
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>
7
+ <head>
8
+ <title>start (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 117</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>
15
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Failed to start: already running (PID file exists).&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">running?</span>
16
+ <span class="ruby-identifier">save_pid</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -0,0 +1,31 @@
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>
7
+ <head>
8
+ <title>stop (Pidify)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File pidify.rb, line 124</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>(<span class="ruby-identifier">signal</span>=<span class="ruby-value str">'SIGINT'</span>)
15
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">running?</span>
16
+ <span class="ruby-keyword kw">begin</span>
17
+ <span class="ruby-identifier">pid</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pid</span>
18
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pid</span>
19
+ <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-identifier">signal</span>, <span class="ruby-identifier">pid</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pid</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">$$</span>
20
+ <span class="ruby-identifier">delete_pid</span>
21
+ <span class="ruby-keyword kw">else</span>
22
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Failed to stop: no PID found.&quot;</span>
23
+ <span class="ruby-keyword kw">end</span>
24
+ <span class="ruby-keyword kw">rescue</span>
25
+ <span class="ruby-identifier">delete_pid</span>
26
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Failed to stop: process already stopped; deleted PID file.&quot;</span>
27
+ <span class="ruby-keyword kw">end</span>
28
+ <span class="ruby-keyword kw">end</span>
29
+ <span class="ruby-keyword kw">end</span></pre>
30
+ </body>
31
+ </html>
data/doc/created.rid ADDED
@@ -0,0 +1 @@
1
+ Mon Jan 09 11:53:33 EST 2006
@@ -0,0 +1,146 @@
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: pidify.rb</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>pidify.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>pidify.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Mon Jan 09 11:53:26 EST 2006</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/Pidify.html">Pidify</a></h1>
73
+ <h2>Synopsis</h2>
74
+ <p>
75
+ A Ruby module to simplify storing and deleting the PID of a running
76
+ program. It also provides the ability to kill a running program whose PID
77
+ it has already saved. This allows a program to check if there is currently
78
+ another running instance of itself, and give it the ability to kill that
79
+ instance based on PID.
80
+ </p>
81
+ <p>
82
+ Note that this does no special process checking and relies solely on the
83
+ PID files it creates and maintains.
84
+ </p>
85
+ <p>
86
+ See <a href="../classes/Pidify.html">Pidify</a> for more information and
87
+ examples.
88
+ </p>
89
+ <h2>Requirements</h2>
90
+ <ul>
91
+ <li>Ruby 1.8
92
+
93
+ </li>
94
+ <li>Pathname module
95
+
96
+ </li>
97
+ </ul>
98
+ <h2>Author</h2>
99
+ <p>
100
+ Payton Swick, 2005
101
+ </p>
102
+ <h2>License</h2>
103
+ <p>
104
+ Creative Commons Attribution <a
105
+ href="http://creativecommons.org/licenses/by/2.0">creativecommons.org/licenses/by/2.0</a>/
106
+ </p>
107
+
108
+ </div>
109
+
110
+ <div id="requires-list">
111
+ <h3 class="section-bar">Required files</h3>
112
+
113
+ <div class="name-list">
114
+ pathname&nbsp;&nbsp;
115
+ </div>
116
+ </div>
117
+
118
+ </div>
119
+
120
+
121
+ </div>
122
+
123
+
124
+ <!-- if includes -->
125
+
126
+ <div id="section">
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+ <!-- if method_list -->
136
+
137
+
138
+ </div>
139
+
140
+
141
+ <div id="validator-badges">
142
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
143
+ </div>
144
+
145
+ </body>
146
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/Pidify.html">Pidify</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Files
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Files</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Files</h1>
22
+ <div id="index-entries">
23
+ <a href="files/pidify_rb.html">pidify.rb</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,35 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Methods
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Methods</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Methods</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/Pidify.html#M000007">delete_pid (Pidify)</a><br />
24
+ <a href="classes/Pidify.html#M000005">pid (Pidify)</a><br />
25
+ <a href="classes/Pidify.html#M000001">pid_directory (Pidify)</a><br />
26
+ <a href="classes/Pidify.html#M000002">pid_directory= (Pidify)</a><br />
27
+ <a href="classes/Pidify.html#M000003">pid_file (Pidify)</a><br />
28
+ <a href="classes/Pidify.html#M000004">running? (Pidify)</a><br />
29
+ <a href="classes/Pidify.html#M000006">save_pid (Pidify)</a><br />
30
+ <a href="classes/Pidify.html#M000008">start (Pidify)</a><br />
31
+ <a href="classes/Pidify.html#M000009">stop (Pidify)</a><br />
32
+ </div>
33
+ </div>
34
+ </body>
35
+ </html>
data/doc/index.html ADDED
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/pidify_rb.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
data/lib/pidify.rb ADDED
@@ -0,0 +1,141 @@
1
+ # = Pidify
2
+ #
3
+ # == Synopsis
4
+ #
5
+ # A Ruby module to simplify storing and deleting the PID of a running program.
6
+ # It also provides the ability to kill a running program whose PID it has
7
+ # already saved. This allows a program to check if there is currently another
8
+ # running instance of itself, and give it the ability to kill that instance
9
+ # based on PID.
10
+ #
11
+ # Note that this does no special process checking and relies solely on the PID
12
+ # files it creates and maintains.
13
+ #
14
+ # See Pidify for more information and examples.
15
+ #
16
+ # == Requirements
17
+ #
18
+ # - Ruby 1.8
19
+ # - Pathname module
20
+ #
21
+ # == Author
22
+ # Payton Swick, 2005
23
+ #
24
+ # == License
25
+ # Creative Commons Attribution
26
+ # http://creativecommons.org/licenses/by/2.0/
27
+ #
28
+
29
+ # Use the module methods in Pidify to save/delete the PID of a running script,
30
+ # or kill a running script using a saved PID.
31
+ #
32
+ # Example:
33
+ # require 'pidify'
34
+ # Pidify.running? # => false
35
+ # Pidify.start
36
+ # Pidify.running? # => true
37
+ # puts "I am running with PID #{Pidify.pid}!"
38
+ # Pidify.stop
39
+ # Pidify.running? # => false
40
+ #
41
+ # A more useful example:
42
+ # require 'pidify'
43
+ # require 'daemons'
44
+ # Signal.trap('INT') { Pidify.stop; exit }
45
+ # module Doer
46
+ # def self.start
47
+ # puts "starting"
48
+ # raise "Failed to start: already running (PID file exists)." if Pidify.running?
49
+ # Daemons.daemonize
50
+ # Pidify.start
51
+ # loop do
52
+ # puts "hello world"
53
+ # sleep 1
54
+ # end
55
+ # end
56
+ # end
57
+ # if ARGV.include? 'stop'
58
+ # Pidify.stop
59
+ # puts "Daemon stopped."
60
+ # else
61
+ # puts "Daemon starting."
62
+ # Doer.start
63
+ # end
64
+ #
65
+ module Pidify
66
+ require 'pathname'
67
+ @pid_directory = Pathname.new("/var/run")
68
+
69
+ class << self
70
+ # Returns the Pathname of the PID storage directory (defaults to /var/run).
71
+ def pid_directory
72
+ @pid_directory
73
+ end
74
+
75
+ # Sets the PID storage directory (defaults to /var/run). Be VERY CAREFUL
76
+ # using this, as delete_pid will try to delete whatever file it thinks is
77
+ # the pid_file for this script in the pid_directory. It's probably a good
78
+ # idea not to change this at all.
79
+ def pid_directory=(dir)
80
+ @pid_directory = Pathname.new(dir) unless dir.kind_of? Pathname
81
+ @pid_directory = dir if dir.kind_of? Pathname
82
+ end
83
+
84
+ # Returns the PID filename as a Pathname.
85
+ def pid_file
86
+ @pid_directory + (Pathname.new($0).basename.to_s+'.pid')
87
+ end
88
+
89
+ # Returns true if the PID file exists for this script.
90
+ def running?
91
+ return FileTest.exists?(pid_file)
92
+ end
93
+
94
+ # Returns the PID stored in the pid_file (not necessarily the PID of this
95
+ # script).
96
+ def pid
97
+ dpid = nil
98
+ File.open(pid_file) { |file| dpid = file.gets.chomp }
99
+ dpid.to_i
100
+ end
101
+
102
+ # Saves the PID of this script into the pid_file. Automatically called by start.
103
+ def save_pid
104
+ File.open(pid_file, 'w') { |file| file.puts $$ }
105
+ end
106
+
107
+ # Deletes the PID file. Calling stop calls this automatically, but will
108
+ # also try to send a kill signal to the running process, if it is different
109
+ # from this one. BEWARE that this tries to delete whatever file is
110
+ # returned by pid_file and does no error checking on it!
111
+ def delete_pid
112
+ File.delete(pid_file) if FileTest.exists? pid_file
113
+ end
114
+
115
+ # Saves the PID of this script into the pid_file by calling save_pid.
116
+ # Raises an exception if running? returns false.
117
+ def start
118
+ raise "Failed to start: already running (PID file exists)." if running?
119
+ save_pid
120
+ end
121
+
122
+ # Deletes the saved PID file and, if the PID belongs to a process different
123
+ # from this script, sends a kill signal to the saved PID.
124
+ def stop(signal='SIGINT')
125
+ if running?
126
+ begin
127
+ pid = self.pid
128
+ if pid
129
+ Process.kill(signal, pid) if pid != $$
130
+ delete_pid
131
+ else
132
+ raise "Failed to stop: no PID found."
133
+ end
134
+ rescue
135
+ delete_pid
136
+ raise "Failed to stop: process already stopped; deleted PID file."
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: pidify
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2006-01-10 00:00:00 -05:00
8
+ summary: This allows a script to check if there is currently another running instance of itself, and give it the ability to kill that instance based on PID.
9
+ require_paths:
10
+ - lib
11
+ email: payton@foolord.com
12
+ homepage: http://foolord.com/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: i386-linux
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Payton Swick
30
+ files:
31
+ - lib/pidify.rb
32
+ - doc/created.rid
33
+ - doc/rdoc-style.css
34
+ - doc/files
35
+ - doc/classes
36
+ - doc/fr_file_index.html
37
+ - doc/fr_class_index.html
38
+ - doc/fr_method_index.html
39
+ - doc/index.html
40
+ - doc/files/pidify_rb.html
41
+ - doc/classes/Pidify.src
42
+ - doc/classes/Pidify.html
43
+ - doc/classes/Pidify.src/M000001.html
44
+ - doc/classes/Pidify.src/M000002.html
45
+ - doc/classes/Pidify.src/M000003.html
46
+ - doc/classes/Pidify.src/M000004.html
47
+ - doc/classes/Pidify.src/M000005.html
48
+ - doc/classes/Pidify.src/M000006.html
49
+ - doc/classes/Pidify.src/M000007.html
50
+ - doc/classes/Pidify.src/M000008.html
51
+ - doc/classes/Pidify.src/M000009.html
52
+ test_files: []
53
+
54
+ rdoc_options: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ requirements: []
63
+
64
+ dependencies: []
65
+