mlanett-daemons 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in daemons.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ daemons (1.0.13)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (>= 1.0)
16
+ daemons!
17
+ rake
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.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require "rdoc/task"
3
+
4
+ task :upload do
5
+ sh "scp -r html/* uehli@rubyforge.org:/var/www/gforge-projects/daemons"
6
+ end
7
+
8
+ desc "Create the RDOC html files"
9
+ rd = Rake::RDocTask.new("rdoc") do |rdoc|
10
+ rdoc.rdoc_dir = 'html'
11
+ rdoc.title = "Daemons"
12
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
13
+ rdoc.rdoc_files.include('README', 'TODO', 'Releases')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
data/Releases ADDED
@@ -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
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ * write the README (2005-02-07) *DONE*
2
+ * write some real tests (2005-02-08)
3
+ * document the new options (2005-03-14) *DONE*
4
+ * start/stop with --force options (2005-04-05)
5
+ * option to give some console output on start/stop commands (2005-04-05)
6
+
data/daemons.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'daemons/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mlanett-daemons"
8
+ spec.version = Daemons::VERSION
9
+
10
+ spec.authors = ["Thomas Uehlinger"]
11
+ spec.autorequire = %q{daemons}
12
+ spec.date = %q{2009-08-26}
13
+ spec.description = %q{Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server) to be run as a daemon and to be controlled by simple start/stop/restart commands. You can also call blocks as daemons and control them from the parent or just daemonize the current process. Besides this basic functionality, daemons offers many advanced features like exception backtracing and logging (in case your ruby script crashes) and monitoring and automatic restarting of your processes if they crash.}
14
+ spec.email = %q{th.uehlinger@gmx.ch}
15
+ spec.has_rdoc = true
16
+ spec.homepage = %q{http://daemons.rubyforge.org}
17
+ spec.rubyforge_project = %q{daemons}
18
+ spec.summary = %q{A toolkit to create and control daemons in different ways}
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", ">= 1.0"
26
+ spec.add_development_dependency "rake"
27
+ end