mwotton-daemons 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
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,223 @@
1
+ = Daemons Version 1.0.11
2
+
3
+ (See Releases for release-specific information)
4
+
5
+ == What is Daemons?
6
+
7
+ Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
8
+ to be <i>run as a daemon</i> and to be <i>controlled by simple start/stop/restart commands</i>.
9
+
10
+ If you want, you can also use daemons to <i>run blocks of ruby code in a daemon process</i> and to control
11
+ these processes from the main application.
12
+
13
+ Besides this basic functionality, daemons offers many advanced features like <i>exception backtracing</i>
14
+ and logging (in case your ruby script crashes) and <i>monitoring</i> and automatic restarting of your processes
15
+ if they crash.
16
+
17
+ Daemons includes the <tt>daemonize.rb</tt> script written by <i>Travis Whitton</i> to do the daemonization
18
+ process.
19
+
20
+ == Basic Usage
21
+
22
+ You can use Daemons in four differet ways:
23
+
24
+ === 1. Create wrapper scripts for your server scripts or applications
25
+
26
+ Layout: suppose you have your self-written server <tt>myserver.rb</tt>:
27
+
28
+ # this is myserver.rb
29
+ # it does nothing really useful at the moment
30
+
31
+ loop do
32
+ sleep(5)
33
+ end
34
+
35
+ To use <tt>myserver.rb</tt> in a production environment, you need to be able to
36
+ run <tt>myserver.rb</tt> in the _background_ (this means detach it from the console, fork it
37
+ in the background, release all directories and file descriptors).
38
+
39
+ Just create <tt>myserver_control.rb</tt> like this:
40
+
41
+ # this is myserver_control.rb
42
+
43
+ require 'rubygems' # if you use RubyGems
44
+ require 'daemons'
45
+
46
+ Daemons.run('myserver.rb')
47
+
48
+ And use it like this from the console:
49
+
50
+ $ ruby myserver_control.rb start
51
+ (myserver.rb is now running in the background)
52
+ $ ruby myserver_control.rb restart
53
+ (...)
54
+ $ ruby myserver_control.rb stop
55
+
56
+ For testing purposes you can even run <tt>myserver.rb</tt> <i>without forking</i> in the background:
57
+
58
+ $ ruby myserver_control.rb run
59
+
60
+ An additional nice feature of Daemons is that you can pass <i>additional arguments</i> to the script that
61
+ should be daemonized by seperating them by two _hyphens_:
62
+
63
+ $ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
64
+
65
+
66
+ === 2. Create wrapper scripts that include your server procs
67
+
68
+ Layout: suppose you have some code you want to run in the background and control that background process
69
+ from a script:
70
+
71
+ # this is your code
72
+ # it does nothing really useful at the moment
73
+
74
+ loop do
75
+ sleep(5)
76
+ end
77
+
78
+ To run this code as a daemon create <tt>myproc_control.rb</tt> like this and include your code:
79
+
80
+ # this is myproc_control.rb
81
+
82
+ require 'rubygems' # if you use RubyGems
83
+ require 'daemons'
84
+
85
+ Daemons.run_proc('myproc.rb') do
86
+ loop do
87
+ sleep(5)
88
+ end
89
+ end
90
+
91
+ And use it like this from the console:
92
+
93
+ $ ruby myproc_control.rb start
94
+ (myproc.rb is now running in the background)
95
+ $ ruby myproc_control.rb restart
96
+ (...)
97
+ $ ruby myproc_control.rb stop
98
+
99
+ For testing purposes you can even run <tt>myproc.rb</tt> <i>without forking</i> in the background:
100
+
101
+ $ ruby myproc_control.rb run
102
+
103
+ === 3. Control a bunch of daemons from another application
104
+
105
+ Layout: you have an application <tt>my_app.rb</tt> that wants to run a bunch of
106
+ server tasks as daemon processes.
107
+
108
+ # this is my_app.rb
109
+
110
+ require 'rubygems' # if you use RubyGems
111
+ require 'daemons'
112
+
113
+ task1 = Daemons.call(:multiple => true) do
114
+ # first server task
115
+
116
+ loop {
117
+ conn = accept_conn()
118
+ serve(conn)
119
+ }
120
+ end
121
+
122
+ task2 = Daemons.call do
123
+ # second server task
124
+
125
+ loop {
126
+ something_different()
127
+ }
128
+ end
129
+
130
+ # the parent process continues to run
131
+
132
+ # we can even control our tasks, for example stop them
133
+ task1.stop
134
+ task2.stop
135
+
136
+ exit
137
+
138
+ === 4. Daemonize the currently running process
139
+
140
+ Layout: you have an application <tt>my_daemon.rb</tt> that wants to run as a daemon
141
+ (but without the ability to be controlled by daemons via start/stop commands)
142
+
143
+ # this is my_daemons.rb
144
+
145
+ require 'rubygems' # if you use RubyGems
146
+ require 'daemons'
147
+
148
+ # Initialize the app while we're not a daemon
149
+ init()
150
+
151
+ # Become a daemon
152
+ Daemons.daemonize
153
+
154
+ # The server loop
155
+ loop {
156
+ conn = accept_conn()
157
+ serve(conn)
158
+ }
159
+
160
+
161
+ <b>For further documentation, refer to the module documentation of Daemons.</b>
162
+
163
+
164
+ == Download and Installation
165
+
166
+ *Download*: just go to http://rubyforge.org/projects/daemons/
167
+
168
+ Installation *with* RubyGems:
169
+ $ su
170
+ # gem install daemons
171
+
172
+ Installation *without* RubyGems:
173
+ $ tar xfz daemons-x.x.x.tar.gz
174
+ $ cd daemons-x.x.x
175
+ $ su
176
+ # ruby setup.rb
177
+
178
+ == Documentation
179
+
180
+ For further documentation, refer to the module documentation of Daemons (click on Daemons).
181
+
182
+ The RDoc documentation is also online at http://daemons.rubyforge.org
183
+
184
+
185
+ == Author
186
+
187
+ Written in 2005-2008 by Thomas Uehlinger <mailto:th.uehlinger@gmx.ch>.
188
+
189
+ == License
190
+
191
+ Copyright (c) 2005-2008 Thomas Uehlinger
192
+
193
+ Permission is hereby granted, free of charge, to any person
194
+ obtaining a copy of this software and associated documentation
195
+ files (the "Software"), to deal in the Software without
196
+ restriction, including without limitation the rights to use,
197
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
198
+ copies of the Software, and to permit persons to whom the
199
+ Software is furnished to do so, subject to the following
200
+ conditions:
201
+
202
+ The above copyright notice and this permission notice shall be
203
+ included in all copies or substantial portions of the Software.
204
+
205
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
206
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
207
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
208
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
209
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
210
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
211
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
212
+ OTHER DEALINGS IN THE SOFTWARE.
213
+
214
+ This license does not apply to daemonize.rb, which is was written by
215
+ Travis Whitton und published under the following license:
216
+
217
+ The Daemonize extension module is copywrited free software by Travis Whitton
218
+ <whitton@atlantic.net>. You can redistribute it under the terms specified in
219
+ the COPYING file of the Ruby distribution.
220
+
221
+ == Feedback and other resources
222
+
223
+ At http://rubyforge.org/projects/daemons.
@@ -0,0 +1,88 @@
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
+ desc 'Show information about the gem.'
72
+ task :debug_gem do
73
+ puts spec.to_ruby
74
+ end
75
+
76
+ task :upload do
77
+ sh "scp -r html/* uehli@rubyforge.org:/var/www/gforge-projects/daemons"
78
+ end
79
+
80
+
81
+ desc "Create the RDOC html files"
82
+ rd = Rake::RDocTask.new("rdoc") { |rdoc|
83
+ rdoc.rdoc_dir = 'html'
84
+ rdoc.title = "Daemons"
85
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
86
+ rdoc.rdoc_files.include('README', 'TODO', 'Releases')
87
+ rdoc.rdoc_files.include('lib/**/*.rb')
88
+ }
@@ -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