mikehale-daemons 1.0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2005-2007 Thomas Uehlinger
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ This license does not apply to daemonize.rb, which is was written by
25
+ Travis Whitton und published under the following license:
26
+
27
+ The Daemonize extension module is copywrited free software by Travis Whitton
28
+ <whitton@atlantic.net>. You can redistribute it under the terms specified in
29
+ the COPYING file of the Ruby distribution.
data/README ADDED
@@ -0,0 +1,232 @@
1
+ = Quick'n'dirty Daemons Version 1.0.10 gem with fix by Chris Kline and additions by Michael Hale
2
+
3
+ This is a clean import of Daemons 1.0.10, with the following changes:
4
+
5
+ # Applied Chris Kline's patch to "Making sure Ruby Daemons die" from http://blog.rapleaf.com/dev/?p=19.
6
+ # Added a gemspec to allow Github to build a gem.
7
+ # Includes ability to change the process uid/gid.
8
+ # logdir can be specified seperate from piddir.
9
+
10
+ = Daemons Version 1.0.10
11
+
12
+ (See Releases for release-specific information)
13
+
14
+ == What is Daemons?
15
+
16
+ Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
17
+ to be <i>run as a daemon</i> and to be <i>controlled by simple start/stop/restart commands</i>.
18
+
19
+ If you want, you can also use daemons to <i>run blocks of ruby code in a daemon process</i> and to control
20
+ these processes from the main application.
21
+
22
+ Besides this basic functionality, daemons offers many advanced features like <i>exception backtracing</i>
23
+ and logging (in case your ruby script crashes) and <i>monitoring</i> and automatic restarting of your processes
24
+ if they crash.
25
+
26
+ Daemons includes the <tt>daemonize.rb</tt> script written by <i>Travis Whitton</i> to do the daemonization
27
+ process.
28
+
29
+ == Basic Usage
30
+
31
+ You can use Daemons in four differet ways:
32
+
33
+ === 1. Create wrapper scripts for your server scripts or applications
34
+
35
+ Layout: suppose you have your self-written server <tt>myserver.rb</tt>:
36
+
37
+ # this is myserver.rb
38
+ # it does nothing really useful at the moment
39
+
40
+ loop do
41
+ sleep(5)
42
+ end
43
+
44
+ To use <tt>myserver.rb</tt> in a production environment, you need to be able to
45
+ run <tt>myserver.rb</tt> in the _background_ (this means detach it from the console, fork it
46
+ in the background, release all directories and file descriptors).
47
+
48
+ Just create <tt>myserver_control.rb</tt> like this:
49
+
50
+ # this is myserver_control.rb
51
+
52
+ require 'rubygems' # if you use RubyGems
53
+ require 'daemons'
54
+
55
+ Daemons.run('myserver.rb')
56
+
57
+ And use it like this from the console:
58
+
59
+ $ ruby myserver_control.rb start
60
+ (myserver.rb is now running in the background)
61
+ $ ruby myserver_control.rb restart
62
+ (...)
63
+ $ ruby myserver_control.rb stop
64
+
65
+ For testing purposes you can even run <tt>myserver.rb</tt> <i>without forking</i> in the background:
66
+
67
+ $ ruby myserver_control.rb run
68
+
69
+ An additional nice feature of Daemons is that you can pass <i>additional arguments</i> to the script that
70
+ should be daemonized by seperating them by two _hyphens_:
71
+
72
+ $ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
73
+
74
+
75
+ === 2. Create wrapper scripts that include your server procs
76
+
77
+ Layout: suppose you have some code you want to run in the background and control that background process
78
+ from a script:
79
+
80
+ # this is your code
81
+ # it does nothing really useful at the moment
82
+
83
+ loop do
84
+ sleep(5)
85
+ end
86
+
87
+ To run this code as a daemon create <tt>myproc_control.rb</tt> like this and include your code:
88
+
89
+ # this is myproc_control.rb
90
+
91
+ require 'rubygems' # if you use RubyGems
92
+ require 'daemons'
93
+
94
+ Daemons.run_proc('myproc.rb') do
95
+ loop do
96
+ sleep(5)
97
+ end
98
+ end
99
+
100
+ And use it like this from the console:
101
+
102
+ $ ruby myproc_control.rb start
103
+ (myproc.rb is now running in the background)
104
+ $ ruby myproc_control.rb restart
105
+ (...)
106
+ $ ruby myproc_control.rb stop
107
+
108
+ For testing purposes you can even run <tt>myproc.rb</tt> <i>without forking</i> in the background:
109
+
110
+ $ ruby myproc_control.rb run
111
+
112
+ === 3. Control a bunch of daemons from another application
113
+
114
+ Layout: you have an application <tt>my_app.rb</tt> that wants to run a bunch of
115
+ server tasks as daemon processes.
116
+
117
+ # this is my_app.rb
118
+
119
+ require 'rubygems' # if you use RubyGems
120
+ require 'daemons'
121
+
122
+ task1 = Daemons.call(:multiple => true) do
123
+ # first server task
124
+
125
+ loop {
126
+ conn = accept_conn()
127
+ serve(conn)
128
+ }
129
+ end
130
+
131
+ task2 = Daemons.call do
132
+ # second server task
133
+
134
+ loop {
135
+ something_different()
136
+ }
137
+ end
138
+
139
+ # the parent process continues to run
140
+
141
+ # we can even control our tasks, for example stop them
142
+ task1.stop
143
+ task2.stop
144
+
145
+ exit
146
+
147
+ === 4. Daemonize the currently running process
148
+
149
+ Layout: you have an application <tt>my_daemon.rb</tt> that wants to run as a daemon
150
+ (but without the ability to be controlled by daemons via start/stop commands)
151
+
152
+ # this is my_daemons.rb
153
+
154
+ require 'rubygems' # if you use RubyGems
155
+ require 'daemons'
156
+
157
+ # Initialize the app while we're not a daemon
158
+ init()
159
+
160
+ # Become a daemon
161
+ Daemons.daemonize
162
+
163
+ # The server loop
164
+ loop {
165
+ conn = accept_conn()
166
+ serve(conn)
167
+ }
168
+
169
+
170
+ <b>For further documentation, refer to the module documentation of Daemons.</b>
171
+
172
+
173
+ == Download and Installation
174
+
175
+ *Download*: just go to http://rubyforge.org/projects/daemons/
176
+
177
+ Installation *with* RubyGems:
178
+ $ su
179
+ # gem install daemons
180
+
181
+ Installation *without* RubyGems:
182
+ $ tar xfz daemons-x.x.x.tar.gz
183
+ $ cd daemons-x.x.x
184
+ $ su
185
+ # ruby setup.rb
186
+
187
+ == Documentation
188
+
189
+ For further documentation, refer to the module documentation of Daemons (click on Daemons).
190
+
191
+ The RDoc documentation is also online at http://daemons.rubyforge.org
192
+
193
+
194
+ == Author
195
+
196
+ Written in 2005-2008 by Thomas Uehlinger <mailto:th.uehlinger@gmx.ch>.
197
+
198
+ == License
199
+
200
+ Copyright (c) 2005-2008 Thomas Uehlinger
201
+
202
+ Permission is hereby granted, free of charge, to any person
203
+ obtaining a copy of this software and associated documentation
204
+ files (the "Software"), to deal in the Software without
205
+ restriction, including without limitation the rights to use,
206
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
207
+ copies of the Software, and to permit persons to whom the
208
+ Software is furnished to do so, subject to the following
209
+ conditions:
210
+
211
+ The above copyright notice and this permission notice shall be
212
+ included in all copies or substantial portions of the Software.
213
+
214
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
215
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
216
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
217
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
218
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
219
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
220
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
221
+ OTHER DEALINGS IN THE SOFTWARE.
222
+
223
+ This license does not apply to daemonize.rb, which is was written by
224
+ Travis Whitton und published under the following license:
225
+
226
+ The Daemonize extension module is copywrited free software by Travis Whitton
227
+ <whitton@atlantic.net>. You can redistribute it under the terms specified in
228
+ the COPYING file of the Ruby distribution.
229
+
230
+ == Feedback and other resources
231
+
232
+ At http://rubyforge.org/projects/daemons.
@@ -0,0 +1,84 @@
1
+ require 'rubygems'
2
+ Gem::manage_gems
3
+
4
+ require 'rake/gempackagetask'
5
+ #require 'rake/testtask'
6
+ require 'rake/packagetask'
7
+ require 'rake/rdoctask'
8
+
9
+ $LOAD_PATH << './lib'
10
+ require 'daemons'
11
+
12
+
13
+ PKG_NAME = "daemons"
14
+
15
+ PKG_FILES = FileList[
16
+ "Rakefile", "Releases", "TODO", "README", "LICENSE",
17
+ "setup.rb",
18
+ "lib/**/*.rb",
19
+ #"test/**/*",
20
+ "examples/**/*"
21
+ ]
22
+ #PKG_FILES.exclude(%r(^test/tmp/.+))
23
+ PKG_FILES.exclude(%r(\.pid$))
24
+ PKG_FILES.exclude(%r(\.log$))
25
+
26
+ spec = Gem::Specification.new do |s|
27
+ s.name = PKG_NAME
28
+ s.version = Daemons::VERSION
29
+ s.author = "Thomas Uehlinger"
30
+ s.email = "th.uehlinger@gmx.ch"
31
+ s.rubyforge_project = "daemons"
32
+ s.homepage = "http://daemons.rubyforge.org"
33
+ s.platform = Gem::Platform::RUBY
34
+ s.summary = "A toolkit to create and control daemons in different ways"
35
+ s.description = <<-EOF
36
+ Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
37
+ to be run as a daemon and to be controlled by simple start/stop/restart commands.
38
+
39
+ You can also call blocks as daemons and control them from the parent or just daemonize the current
40
+ process.
41
+
42
+ Besides this basic functionality, daemons offers many advanced features like exception
43
+ backtracing and logging (in case your ruby script crashes) and monitoring and automatic
44
+ restarting of your processes if they crash.
45
+ EOF
46
+
47
+ #s.files = FileList["{test,lib}/**/*"].exclude("rdoc").to_a
48
+ s.files = PKG_FILES
49
+ s.require_path = "lib"
50
+ s.autorequire = "daemons"
51
+ s.has_rdoc = true
52
+ s.extra_rdoc_files = ["README", "Releases", "TODO"]
53
+ end
54
+
55
+ Rake::GemPackageTask.new(spec) do |pkg|
56
+ pkg.need_tar = true
57
+ end
58
+
59
+
60
+ #Rake::PackageTask.new("package") do |p|
61
+ # p.name = PKG_NAME
62
+ # p.version = Daemons::VERSION
63
+ # p.need_tar = true
64
+ # p.need_zip = true
65
+ # p.package_files = PKG_FILES
66
+ #end
67
+
68
+
69
+ task :default => [:package]
70
+
71
+
72
+ task :upload do
73
+ sh "scp -r html/* uehli@rubyforge.org:/var/www/gforge-projects/daemons"
74
+ end
75
+
76
+
77
+ desc "Create the RDOC html files"
78
+ rd = Rake::RDocTask.new("rdoc") { |rdoc|
79
+ rdoc.rdoc_dir = 'html'
80
+ rdoc.title = "Daemons"
81
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
82
+ rdoc.rdoc_files.include('README', 'TODO', 'Releases')
83
+ rdoc.rdoc_files.include('lib/**/*.rb')
84
+ }
@@ -0,0 +1,126 @@
1
+ = Daemons Release History
2
+
3
+ == Release 1.0.10: November 16, 2007
4
+
5
+ * By default, we now delete stray pid-files (i.e. pid-files which result for
6
+ example from a killed daemon) automatically. This function can be deactivated by
7
+ passing :keep_pid_files => true as an option.
8
+ * All pid files of :multiple daemons new get deleted correctly upon exit of the daemons (reported by Han Holl).
9
+ * Use the signal 'KILL' instead of 'TERM' on Windows platforms.
10
+ * Use exit! in trap('TERM') instead of exit when option :hard_exit is given (thanks to Han Holl).
11
+ * Did some clarification on the exception log.
12
+
13
+ == Release 1.0.9: October 29, 2007
14
+
15
+ * fixed a severe bug in the new Pid.running? function: function returned true if the process did not exist (thanks to Jeremy Lawler).
16
+
17
+ == Release 1.0.8: September 24, 2007
18
+
19
+ * new Pid.running? function. Checking whether a process exists by sending signal '0' (thanks to Dru Nelson).
20
+
21
+ == Release 1.0.7: July 7, 2007
22
+
23
+ * Patch to fix wrong ARGV when using :exec (in def start_exec: Kernel.exec(script(), *(@app_argv || []))) (thanks to Alex McGuire).
24
+
25
+ == Release 1.0.6: Mai 8, 2007
26
+
27
+ * New option to pass an ARGV-style array to run and run_proc (thanks to Marc Evans).
28
+ * Additional patches for '/var/log' (thanks to Marc Evans).
29
+
30
+ == Release 1.0.5: February 24, 2007
31
+
32
+ * Applied patch that makes daemons to use '/var/log' as logfile
33
+ directory if you use :dir_mode = :system (thanks to Han Holl).
34
+ * Daemons should now work with Ruby 1.9 (at least the basic features).
35
+
36
+ == Release 1.0.4: January 17, 2007
37
+
38
+ * Document the :log_output option (thanks to Andrew Kuklewicz).
39
+ * Set STDOUT.sync = true when redirecting to a logfile (thanks to Andrew Kuklewicz).
40
+ * Should now run also correctly when there is no working 'ps ax' on the system (thanks to Daniel Kehoe).
41
+
42
+ == Release 1.0.3: November 1, 2006
43
+
44
+ * Set the app_name correctly also for the monitor process (thanks to Ilya Novoselov).
45
+
46
+ == Release 1.0.2: September 26, 2006
47
+
48
+ * Changed the 'ps -ax' call back to 'ps ax'.
49
+ * Fixed the documentation for the :normal :dir_mode.
50
+ * As a default for Daemons.run_proc, the pid file is now saved in the current directory.
51
+ * In :ontop mode for running a proc (this is equal to calling something like 'ruby ctrl_proc.rb run'),
52
+ the proc now runs directly in the calling script, not in a forked process anymore (thanks to Paul Butcher).
53
+ * Set $0 to app_name in the daemons (thanks to Ilya Novoselov).
54
+
55
+ == Release 1.0.1: August 30, 2006
56
+
57
+ * Fixed a regex for parsing the 'ps ax' system call. (thanks to Garance Alistair Drosehn)
58
+
59
+ == Release 1.0.0: August 29, 2006
60
+
61
+ * Fix the parsing of the 'ps ax' system call. (thanks to Garance Alistair Drosehn)
62
+
63
+ == Release 0.4.4: February 14, 2006
64
+
65
+ * Several fixes that allow us to use the Daemons::Controller
66
+ with a proc instead of wrapping a script file. This gives us all the
67
+ PID file management, monitoring, command line options, etc. without having
68
+ to specify a path to our script which can be tricky, especially when using
69
+ RubyGems. (thanks to John-Mason Shackelford)
70
+
71
+ == Release 0.4.3: November 29, 2005
72
+
73
+ * New Option: You can specify the name of the application with :app_name
74
+ on calling Daemons.run. This will be used to contruct the name of the pid files
75
+ and log files. Defaults to the basename of the script. (thanks to Stephen R. Veit)
76
+
77
+ * Bugfix: Handle the case where no controller options are given when calling Daemons,
78
+ just options after "--". (thanks to Stephen R. Veit)
79
+
80
+
81
+ == Release 0.4.2: November 15, 2005
82
+
83
+ * Bugfix for problem with :normal pid-file directory mode (pid.rb), fixed (thanks to Stephen R. Veit)
84
+
85
+
86
+ == Release 0.4.1: September 11, 2005
87
+
88
+ * Bugfix for 'run' command line mode: didn't work anymore in 0.4.0, fixed
89
+
90
+
91
+ == Release 0.4.0: July 30, 2005
92
+
93
+ * Two completely new operation modes:
94
+ 1. Call a block as a daemon (<tt>Daemons.call { my_daemon_code }</tt>)
95
+ and control it from the parent process.
96
+ 2. Daemonize the currently running process (<tt>Daemons.daemonize</tt>)
97
+ plus the already existing mode to control your scripts (<tt>Daemons.run("script.rb")</tt>)
98
+ * Improved documentation (for example "How does the daemonization process work?")
99
+ * Improved "simulation mode" (<tt>:ontop</tt> option)
100
+ * Some minor bugfixes
101
+
102
+
103
+ == Release 0.3.0: April 21, 2005
104
+
105
+ * New monitor functionality: automatic restarting of your applications if they crash
106
+ * 'restart' command fixed
107
+ * '--force' command modifier (please refer to the documentation)
108
+ * Some more bugfixes and improvements
109
+
110
+
111
+ == Release 0.2.1: Mar 21, 2005
112
+
113
+ * Bugfix for a problem with the 'status' command
114
+
115
+
116
+ == Release 0.2.0: Mar 21, 2005
117
+
118
+ * Exception backtrace functionality added
119
+ * Exec functionality added
120
+ * More examples added
121
+ * New commands: status, zap
122
+
123
+
124
+ == Release 0.0.1: Feb 8, 2005
125
+
126
+ * Initial release