├── LICENSE ├── README.md ├── Rakefile ├── Releases ├── TODO ├── daemons.gemspec ├── daemons.tmproj ├── examples ├── call │ ├── call.rb │ ├── call.rb.log │ └── call_monitor.rb ├── daemonize │ └── daemonize.rb └── run │ ├── ctrl_crash.rb │ ├── ctrl_exec.rb │ ├── ctrl_exit.rb │ ├── ctrl_keep_pid_files.rb │ ├── ctrl_monitor.rb │ ├── ctrl_multiple.rb │ ├── ctrl_normal.rb │ ├── ctrl_ontop.rb │ ├── ctrl_optionparser.rb │ ├── ctrl_proc.rb │ ├── ctrl_proc.rb.output │ ├── ctrl_proc_multiple.rb │ ├── ctrl_proc_multiple.rb.output │ ├── ctrl_proc_simple.rb │ ├── myserver.rb │ ├── myserver_crashing.rb │ ├── myserver_crashing.rb.output │ └── myserver_exiting.rb ├── html ├── classes │ ├── Daemonize.html │ ├── Daemons.html │ └── Daemons │ │ ├── Application.html │ │ ├── ApplicationGroup.html │ │ ├── CmdException.html │ │ ├── Controller.html │ │ ├── Error.html │ │ ├── Exception.html │ │ ├── Monitor.html │ │ ├── Optparse.html │ │ ├── Pid.html │ │ ├── PidFile.html │ │ ├── PidMem.html │ │ ├── RuntimeException.html │ │ └── SystemError.html ├── created.rid ├── files │ ├── README.html │ ├── Releases.html │ ├── TODO.html │ └── lib │ │ ├── daemons │ │ ├── application_group_rb.html │ │ ├── application_rb.html │ │ ├── cmdline_rb.html │ │ ├── controller_rb.html │ │ ├── daemonize_rb.html │ │ ├── exceptions_rb.html │ │ ├── monitor_rb.html │ │ ├── pid_rb.html │ │ ├── pidfile_rb.html │ │ └── pidmem_rb.html │ │ └── daemons_rb.html ├── fr_class_index.html ├── fr_file_index.html ├── fr_method_index.html ├── index.html └── rdoc-style.css ├── lib ├── daemons.rb └── daemons │ ├── application.rb │ ├── application_group.rb │ ├── cmdline.rb │ ├── controller.rb │ ├── daemonize.rb │ ├── exceptions.rb │ ├── monitor.rb │ ├── pid.rb │ ├── pidfile.rb │ └── pidmem.rb ├── setup.rb └── test ├── call_as_daemon.rb ├── tc_main.rb ├── test1.rb └── testapp.rb /LICENSE: -------------------------------------------------------------------------------- 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 | . You can redistribute it under the terms specified in 29 | the COPYING file of the Ruby distribution. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 run as a daemon and to be controlled by simple start/stop/restart commands. 9 | 10 | If you want, you can also use daemons to run blocks of ruby code in a daemon process and to control 11 | these processes from the main application. 12 | 13 | Besides this basic functionality, daemons offers many advanced features like exception backtracing 14 | and logging (in case your ruby script crashes) and monitoring and automatic restarting of your processes 15 | if they crash. 16 | 17 | Daemons includes the daemonize.rb script written by Travis Whitton 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 myserver.rb: 27 | ```ruby 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 myserver.rb in a production environment, you need to be able to 36 | run myserver.rb 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 myserver_control.rb like this: 40 | ```ruby 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 myserver.rb without forking in the background: 57 | ``` 58 | $ ruby myserver_control.rb run 59 | ``` 60 | An additional nice feature of Daemons is that you can pass additional arguments 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 | ```ruby 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 myproc_control.rb like this and include your code: 79 | ```ruby 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 myproc.rb without forking 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 my_app.rb that wants to run a bunch of 106 | server tasks as daemon processes. 107 | ```ruby 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 | 139 | ### 4. Daemonize the currently running process 140 | 141 | Layout: you have an application my_daemon.rb that wants to run as a daemon 142 | (but without the ability to be controlled by daemons via start/stop commands) 143 | ```ruby 144 | # this is my_daemons.rb 145 | 146 | require 'rubygems' # if you use RubyGems 147 | require 'daemons' 148 | 149 | # Initialize the app while we're not a daemon 150 | init() 151 | 152 | # Become a daemon 153 | Daemons.daemonize 154 | 155 | # The server loop 156 | loop { 157 | conn = accept_conn() 158 | serve(conn) 159 | } 160 | ``` 161 | 162 | For further documentation, refer to the module documentation of Daemons. 163 | 164 | 165 | ## Download and Installation 166 | 167 | *Download*: just go to http://rubyforge.org/projects/daemons/ 168 | 169 | Installation *with* RubyGems: 170 | ``` 171 | $ su 172 | # gem install daemons 173 | ``` 174 | Installation *without* RubyGems: 175 | ``` 176 | $ tar xfz daemons-x.x.x.tar.gz 177 | $ cd daemons-x.x.x 178 | $ su 179 | # ruby setup.rb 180 | ``` 181 | ## Documentation 182 | 183 | For further documentation, refer to the module documentation of Daemons (click on Daemons). 184 | 185 | The RDoc documentation is also online at http://daemons.rubyforge.org 186 | 187 | 188 | ## Author 189 | 190 | Written in 2005-2008 by Thomas Uehlinger . 191 | 192 | ## License 193 | 194 | Copyright (c) 2005-2008 Thomas Uehlinger 195 | 196 | Permission is hereby granted, free of charge, to any person 197 | obtaining a copy of this software and associated documentation 198 | files (the "Software"), to deal in the Software without 199 | restriction, including without limitation the rights to use, 200 | copy, modify, merge, publish, distribute, sublicense, and/or sell 201 | copies of the Software, and to permit persons to whom the 202 | Software is furnished to do so, subject to the following 203 | conditions: 204 | 205 | The above copyright notice and this permission notice shall be 206 | included in all copies or substantial portions of the Software. 207 | 208 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 209 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 210 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 211 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 212 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 213 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 214 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 215 | OTHER DEALINGS IN THE SOFTWARE. 216 | 217 | This license does not apply to daemonize.rb, which is was written by 218 | Travis Whitton und published under the following license: 219 | 220 | The Daemonize extension module is copywrited free software by Travis Whitton 221 | . You can redistribute it under the terms specified in 222 | the COPYING file of the Ruby distribution. 223 | 224 | ## Feedback and other resources 225 | 226 | At http://rubyforge.org/projects/daemons. 227 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /Releases: -------------------------------------------------------------------------------- 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 (Daemons.call { my_daemon_code }) 95 | and control it from the parent process. 96 | 2. Daemonize the currently running process (Daemons.daemonize) 97 | plus the already existing mode to control your scripts (Daemons.run("script.rb")) 98 | * Improved documentation (for example "How does the daemonization process work?") 99 | * Improved "simulation mode" (:ontop 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 127 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 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 | 7 | -------------------------------------------------------------------------------- /daemons.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | Gem::Specification.new do |s| 4 | s.name = %q{daemons} 5 | s.version = "1.0.12" 6 | 7 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 8 | s.authors = ["Thomas Uehlinger"] 9 | s.autorequire = %q{daemons} 10 | s.date = %q{2009-08-26} 11 | s.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.} 12 | s.email = %q{th.uehlinger@gmx.ch} 13 | s.extra_rdoc_files = ["README", "Releases", "TODO"] 14 | s.files = ["Rakefile", "Releases", "TODO", "README", "LICENSE", "setup.rb", "lib/daemons.rb", "lib/daemons/cmdline.rb", "lib/daemons/exceptions.rb", "lib/daemons/daemonize.rb", "lib/daemons/pidfile.rb", "lib/daemons/monitor.rb", "lib/daemons/application_group.rb", "lib/daemons/controller.rb", "lib/daemons/pid.rb", "lib/daemons/pidmem.rb", "lib/daemons/application.rb", "examples/run", "examples/run/ctrl_exec.rb", "examples/run/ctrl_exit.rb", "examples/run/ctrl_multiple.rb", "examples/run/myserver_crashing.rb.output", "examples/run/ctrl_normal.rb", "examples/run/ctrl_proc_multiple.rb", "examples/run/ctrl_monitor.rb", "examples/run/myserver.rb", "examples/run/myserver_crashing.rb", "examples/run/ctrl_proc.rb", "examples/run/ctrl_proc.rb.output", "examples/run/ctrl_proc_multiple.rb.output", "examples/run/ctrl_optionparser.rb", "examples/run/ctrl_ontop.rb", "examples/run/myserver_exiting.rb", "examples/run/ctrl_crash.rb", "examples/run/ctrl_proc_simple.rb", "examples/run/ctrl_keep_pid_files.rb", "examples/call", "examples/call/call_monitor.rb", "examples/call/call.rb", "examples/daemonize", "examples/daemonize/daemonize.rb"] 15 | s.has_rdoc = true 16 | s.homepage = %q{http://daemons.rubyforge.org} 17 | s.require_paths = ["lib"] 18 | s.rubyforge_project = %q{daemons} 19 | s.rubygems_version = %q{1.3.1} 20 | s.summary = %q{A toolkit to create and control daemons in different ways} 21 | 22 | if s.respond_to? :specification_version then 23 | current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION 24 | s.specification_version = 2 25 | 26 | if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then 27 | else 28 | end 29 | else 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /daemons.tmproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | documents 6 | 7 | 8 | expanded 9 | 10 | name 11 | daemons 12 | regexFolderFilter 13 | !.*/(\.[^/]*|CVS|_darcs|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$ 14 | sourceDirectory 15 | 16 | 17 | 18 | fileHierarchyDrawerWidth 19 | 200 20 | metaData 21 | 22 | html/classes/Daemons.html 23 | 24 | caret 25 | 26 | column 27 | 28 28 | line 29 | 553 30 | 31 | firstVisibleColumn 32 | 0 33 | firstVisibleLine 34 | 533 35 | 36 | lib/daemons/application_group.rb 37 | 38 | caret 39 | 40 | column 41 | 0 42 | line 43 | 0 44 | 45 | firstVisibleColumn 46 | 0 47 | firstVisibleLine 48 | 61 49 | 50 | 51 | showFileHierarchyDrawer 52 | 53 | windowFrame 54 | {{419, 58}, {733, 788}} 55 | 56 | 57 | -------------------------------------------------------------------------------- /examples/call/call.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | 10 | require 'daemons' 11 | 12 | testfile = File.expand_path(__FILE__) + '.log' 13 | 14 | 15 | # On the first call to , an application group (accessible by Daemons.group) 16 | # will be created an the options will be kept within, so you only have to specify 17 | # :multiple once. 18 | # 19 | 20 | options = { 21 | # :ontop => true, 22 | :multiple => true 23 | } 24 | 25 | 26 | Daemons.call(options) do 27 | File.open(testfile, 'w') {|f| 28 | f.puts "test" 29 | } 30 | 31 | loop { puts "1"; sleep 5 } 32 | end 33 | puts "first task started" 34 | 35 | Daemons.call do 36 | loop { puts "2"; sleep 4 } 37 | end 38 | puts "second task started" 39 | 40 | # NOTE: this process will exit after 5 seconds 41 | Daemons.call do 42 | puts "3" 43 | sleep 5 44 | end 45 | puts "third task started" 46 | 47 | puts "waiting 20 seconds..." 48 | sleep(20) 49 | 50 | # This call would result in an exception as it will try to kill the third process 51 | # which has already terminated by that time; but using the 'true' parameter forces the 52 | # stop_all procedure. 53 | puts "trying to stop all tasks..." 54 | Daemons.group.stop_all(true) 55 | 56 | puts "done" 57 | -------------------------------------------------------------------------------- /examples/call/call.rb.log: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /examples/call/call_monitor.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | 10 | require 'daemons' 11 | 12 | testfile = File.expand_path(__FILE__) + '.log' 13 | 14 | 15 | # On the first call to , an application group (accessible by Daemons.group) 16 | # will be created an the options will be kept within, so you only have to specify 17 | # :multiple once. 18 | # 19 | 20 | options = { 21 | # :ontop => true, 22 | :multiple => true, 23 | :monitor => true 24 | } 25 | 26 | 27 | Daemons.call(options) do 28 | loop { puts "1"; sleep 20 } 29 | end 30 | puts "first task started" 31 | 32 | 33 | # NOTE: this process will exit after 5 seconds 34 | Daemons.call do 35 | File.open(testfile, 'a') {|f| 36 | f.puts "started..." 37 | puts "2" 38 | 39 | sleep 5 40 | 41 | f.puts "...exit" 42 | } 43 | end 44 | puts "second task started" 45 | 46 | puts "waiting 100 seconds..." 47 | sleep(100) 48 | 49 | # This call would result in an exception as it will try to kill the third process 50 | # which has already terminated by that time; but using the 'true' parameter forces the 51 | # stop_all procedure. 52 | puts "trying to stop all tasks..." 53 | Daemons.group.stop_all(true) 54 | 55 | puts "done" 56 | -------------------------------------------------------------------------------- /examples/daemonize/daemonize.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | 10 | 11 | require 'daemons' 12 | 13 | 14 | testfile = File.expand_path(__FILE__) + '.log' 15 | 16 | Daemons.daemonize 17 | 18 | File.open(testfile, 'w') {|f| 19 | f.write("test") 20 | } -------------------------------------------------------------------------------- /examples/run/ctrl_crash.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :log_output => true, 14 | :backtrace => true 15 | } 16 | 17 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options) 18 | -------------------------------------------------------------------------------- /examples/run/ctrl_exec.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :mode => :exec 14 | } 15 | 16 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options) 17 | -------------------------------------------------------------------------------- /examples/run/ctrl_exit.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | } 14 | 15 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver_exiting.rb'), options) 16 | -------------------------------------------------------------------------------- /examples/run/ctrl_keep_pid_files.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :keep_pid_files => true 14 | } 15 | 16 | 17 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options) -------------------------------------------------------------------------------- /examples/run/ctrl_monitor.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :monitor => true 14 | } 15 | 16 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options) 17 | -------------------------------------------------------------------------------- /examples/run/ctrl_multiple.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :multiple => true 14 | } 15 | 16 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options) 17 | -------------------------------------------------------------------------------- /examples/run/ctrl_normal.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb')) 13 | -------------------------------------------------------------------------------- /examples/run/ctrl_ontop.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :ontop => true 14 | } 15 | 16 | Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options) 17 | -------------------------------------------------------------------------------- /examples/run/ctrl_optionparser.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | require 'optparse' 11 | require 'logger' 12 | require 'ostruct' 13 | 14 | 15 | class MyApp < Logger::Application 16 | def initialize(args) 17 | super(self.class) 18 | @options = OpenStruct.new(:daemonize => true) 19 | opts = OptionParser.new do |opts| 20 | opts.banner = 'Usage: myapp [options]' 21 | opts.separator '' 22 | opts.on('-N','--no-daemonize',"Don't run as a daemon") do 23 | @options.daemonize = false 24 | end 25 | end 26 | @args = opts.parse!(args) 27 | end 28 | 29 | def run 30 | Daemons.run_proc('myapp',{:ARGV => @args, :ontop => !@options.daemonize}) do 31 | puts "@options.daemonize: #{@options.daemonize}" 32 | STDOUT.sync = true 33 | loop do 34 | print '.' 35 | sleep(2) 36 | end 37 | end 38 | end 39 | end 40 | 41 | 42 | myapp = MyApp.new(ARGV) 43 | myapp.run -------------------------------------------------------------------------------- /examples/run/ctrl_proc.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :multiple => false, 14 | :ontop => false, 15 | :backtrace => true, 16 | :log_output => true, 17 | :monitor => true 18 | } 19 | 20 | Daemons.run_proc('ctrl_proc.rb', options) do 21 | loop do 22 | puts 'ping from proc!' 23 | sleep(3) 24 | end 25 | end -------------------------------------------------------------------------------- /examples/run/ctrl_proc.rb.output: -------------------------------------------------------------------------------- 1 | ping from proc! 2 | ping from proc! 3 | ping from proc! 4 | ping from proc! 5 | ping from proc! 6 | ping from proc! 7 | ping from proc! 8 | ping from proc! 9 | ping from proc! 10 | ping from proc! 11 | ping from proc! 12 | ping from proc! 13 | ping from proc! 14 | ping from proc! 15 | ping from proc! 16 | ping from proc! 17 | ping from proc! 18 | ping from proc! 19 | ping from proc! 20 | ping from proc! 21 | ping from proc! 22 | ping from proc! 23 | ping from proc! 24 | ping from proc! 25 | ping from proc! 26 | ping from proc! 27 | ping from proc! 28 | ping from proc! 29 | ping from proc! 30 | ping from proc! 31 | ping from proc! 32 | ping from proc! 33 | ping from proc! 34 | ping from proc! 35 | ping from proc! 36 | ping from proc! 37 | ping from proc! 38 | ping from proc! 39 | ping from proc! 40 | ping from proc! 41 | ping from proc! 42 | ping from proc! 43 | ping from proc! 44 | ping from proc! 45 | ping from proc! 46 | ping from proc! 47 | ping from proc! 48 | ping from proc! 49 | ping from proc! 50 | ping from proc! 51 | ping from proc! 52 | ping from proc! 53 | ping from proc! 54 | ping from proc! 55 | ping from proc! 56 | ping from proc! 57 | ping from proc! 58 | ping from proc! 59 | ping from proc! 60 | ping from proc! 61 | ping from proc! 62 | ping from proc! 63 | ping from proc! 64 | ping from proc! 65 | ping from proc! 66 | ping from proc! 67 | ping from proc! 68 | ping from proc! 69 | ping from proc! 70 | ping from proc! 71 | ping from proc! 72 | ping from proc! 73 | ping from proc! 74 | ping from proc! 75 | ping from proc! 76 | ping from proc! 77 | ping from proc! 78 | ping from proc! 79 | ping from proc! 80 | ping from proc! 81 | ping from proc! 82 | ping from proc! 83 | ping from proc! 84 | ping from proc! 85 | ping from proc! 86 | ping from proc! 87 | ping from proc! 88 | ping from proc! 89 | ping from proc! 90 | ping from proc! 91 | ping from proc! 92 | ping from proc! 93 | ping from proc! 94 | ping from proc! 95 | ping from proc! 96 | ping from proc! 97 | ping from proc! 98 | ping from proc! 99 | ping from proc! 100 | ping from proc! 101 | ping from proc! 102 | -------------------------------------------------------------------------------- /examples/run/ctrl_proc_multiple.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | options = { 13 | :log_output => true, 14 | :multiple => true, 15 | } 16 | 17 | 18 | Daemons.run_proc('ctrl_proc_multiple.rb', options) do 19 | puts "hello" 20 | sleep(5) 21 | puts "done" 22 | end -------------------------------------------------------------------------------- /examples/run/ctrl_proc_multiple.rb.output: -------------------------------------------------------------------------------- 1 | 2 | hello 3 | -------------------------------------------------------------------------------- /examples/run/ctrl_proc_simple.rb: -------------------------------------------------------------------------------- 1 | lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) 2 | 3 | if File.exist?(File.join(lib_dir, 'daemons.rb')) 4 | $LOAD_PATH.unshift lib_dir 5 | else 6 | begin; require 'rubygems'; rescue ::Exception; end 7 | end 8 | 9 | require 'daemons' 10 | 11 | 12 | Daemons.run_proc('ctrl_proc_simple.rb') do 13 | loop do 14 | puts 'ping from proc!' 15 | sleep(3) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /examples/run/myserver.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | 4 | # This is myserver.rb, an example server that is to be controlled by daemons 5 | # and that does nothing really useful at the moment. 6 | # 7 | # Don't run this script by yourself, it can be controlled by the ctrl*.rb scripts. 8 | 9 | loop do 10 | puts 'ping from myserver.rb!' 11 | sleep(3) 12 | end 13 | -------------------------------------------------------------------------------- /examples/run/myserver_crashing.rb: -------------------------------------------------------------------------------- 1 | # This is myserver.rb, an example server that is to be controlled by daemons 2 | # and that does nothing really useful at the moment. 3 | # 4 | # Don't run this script by yourself, it can be controlled by the ctrl*.rb scripts. 5 | 6 | loop do 7 | puts 'ping from myserver.rb!' 8 | puts 'this example server will crash in 3 seconds...' 9 | 10 | sleep(3) 11 | 12 | puts 'CRASH!' 13 | raise 'CRASH!' 14 | end 15 | -------------------------------------------------------------------------------- /examples/run/myserver_crashing.rb.output: -------------------------------------------------------------------------------- 1 | /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:13: CRASH! (RuntimeError) 2 | from /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:6:in `loop' 3 | from /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:6 4 | from /home/uehli/Desktop/daemons-current/lib/daemons.rb:116:in `load' 5 | from /home/uehli/Desktop/daemons-current/lib/daemons.rb:116:in `run_via_load' 6 | from /home/uehli/Desktop/daemons-current/lib/daemons.rb:90:in `start' 7 | from /home/uehli/Desktop/daemons-current/lib/daemons.rb:359:in `run' 8 | from /home/uehli/Desktop/daemons-current/lib/daemons.rb:469:in `run' 9 | from /home/uehli/Desktop/daemons-current/lib/daemons.rb:468:in `call' 10 | from /home/uehli/Desktop/daemons-current/lib/daemons/cmdline.rb:94:in `catch_exceptions' 11 | from /home/uehli/Desktop/daemons-current/lib/daemons.rb:468:in `run' 12 | from ctrl_crash.rb:17 13 | ping from myserver.rb! 14 | this example server will crash in 3 seconds... 15 | CRASH! 16 | ping from myserver.rb! 17 | this example server will crash in 3 seconds... 18 | CRASH! 19 | /Users/uehli/Projects/daemons-proj/examples/run/myserver_crashing.rb:13: CRASH! (RuntimeError) 20 | from /Users/uehli/Projects/daemons-proj/examples/run/myserver_crashing.rb:6:in `loop' 21 | from /Users/uehli/Projects/daemons-proj/examples/run/myserver_crashing.rb:6 22 | from /Users/uehli/Projects/daemons-proj/lib/daemons/application.rb:176:in `load' 23 | from /Users/uehli/Projects/daemons-proj/lib/daemons/application.rb:176:in `start_load' 24 | from /Users/uehli/Projects/daemons-proj/lib/daemons/application.rb:257:in `start' 25 | from /Users/uehli/Projects/daemons-proj/lib/daemons/controller.rb:69:in `run' 26 | from /Users/uehli/Projects/daemons-proj/lib/daemons.rb:139:in `run' 27 | from /Users/uehli/Projects/daemons-proj/lib/daemons/cmdline.rb:105:in `call' 28 | from /Users/uehli/Projects/daemons-proj/lib/daemons/cmdline.rb:105:in `catch_exceptions' 29 | from /Users/uehli/Projects/daemons-proj/lib/daemons.rb:138:in `run' 30 | from ctrl_crash.rb:17 31 | -------------------------------------------------------------------------------- /examples/run/myserver_exiting.rb: -------------------------------------------------------------------------------- 1 | loop do 2 | puts 'ping from myserver.rb!' 3 | puts 'this example server will exit in 3 seconds...' 4 | 5 | sleep(3) 6 | 7 | Process.exit 8 | end 9 | -------------------------------------------------------------------------------- /html/classes/Daemons/CmdException.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::CmdException 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 72 | 73 |
ClassDaemons::CmdException
In: 58 | 59 | lib/daemons/exceptions.rb 60 | 61 |
62 |
Parent: 68 | 69 | Exception 70 | 71 |
74 |
75 | 76 | 77 |
78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 |
86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 | 108 |
109 |

[Validate]

110 |
111 | 112 | 113 | -------------------------------------------------------------------------------- /html/classes/Daemons/Error.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::Error 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 72 | 73 |
ClassDaemons::Error
In: 58 | 59 | lib/daemons/exceptions.rb 60 | 61 |
62 |
Parent: 68 | 69 | Exception 70 | 71 |
74 |
75 | 76 | 77 |
78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 |
86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 | 108 |
109 |

[Validate]

110 |
111 | 112 | 113 | -------------------------------------------------------------------------------- /html/classes/Daemons/Exception.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::Exception 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassDaemons::Exception
In: 58 | 59 | lib/daemons/exceptions.rb 60 | 61 |
62 |
Parent: 68 | ::RuntimeError 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 | 82 | 83 |
84 | 85 | 86 |
87 | 88 | 89 | 90 | 91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 |
107 |

[Validate]

108 |
109 | 110 | 111 | -------------------------------------------------------------------------------- /html/classes/Daemons/Monitor.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::Monitor 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassDaemons::Monitor
In: 58 | 59 | lib/daemons/monitor.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 | 82 | 83 |
84 | 85 |
86 |

Methods

87 | 88 |
89 | find   90 | new   91 | start   92 | stop   93 |
94 |
95 | 96 |
97 | 98 | 99 | 100 | 101 |
102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 |
112 |

Public Class methods

113 | 114 |
115 | 116 | 117 | 122 | 123 |
124 |

[Source]

126 |
127 |
128 |     # File lib/daemons/monitor.rb, line 8
129 |  8:     def self.find(dir, app_name)
130 |  9:       pid = PidFile.find_files(dir, app_name, false)[0]
131 | 10:       
132 | 11:       if pid
133 | 12:         pid = PidFile.existing(pid)
134 | 13:         
135 | 14:         unless PidFile.running?(pid.pid)
136 | 15:           begin; pid.cleanup; rescue ::Exception; end
137 | 16:           return
138 | 17:         end
139 | 18:         
140 | 19:         monitor = self.allocate
141 | 20:       
142 | 21:         monitor.instance_variable_set(:@pid, pid)
143 | 22:         
144 | 23:         return monitor
145 | 24:       end
146 | 25:       
147 | 26:       return nil
148 | 27:     end
149 | 
150 |
151 |
152 |
153 | 154 |
155 | 156 | 157 | 162 | 163 |
164 |

[Source]

166 |
167 |
168 |     # File lib/daemons/monitor.rb, line 30
169 | 30:     def initialize(an_app)
170 | 31:       @app = an_app
171 | 32:       @app_name = an_app.group.app_name + '_monitor'
172 | 33:       
173 | 34:       if an_app.pidfile_dir
174 | 35:         @pid = PidFile.new(an_app.pidfile_dir, @app_name, false)
175 | 36:       else
176 | 37:         @pid = PidMem.new
177 | 38:       end
178 | 39:     end
179 | 
180 |
181 |
182 |
183 | 184 |

Public Instance methods

185 | 186 |
187 | 188 | 189 | 194 | 195 |
196 |

[Source]

198 |
199 |
200 |      # File lib/daemons/monitor.rb, line 107
201 | 107:     def start(applications)
202 | 108:       return if applications.empty?
203 | 109:       
204 | 110:       if @pid.kind_of?(PidFile)
205 | 111:         start_with_pidfile(applications)
206 | 112:       else
207 | 113:         start_without_pidfile(applications)
208 | 114:       end
209 | 115:     end
210 | 
211 |
212 |
213 |
214 | 215 |
216 | 217 | 218 | 223 | 224 |
225 |

[Source]

227 |
228 |
229 |      # File lib/daemons/monitor.rb, line 118
230 | 118:     def stop
231 | 119:       pid = @pid.pid
232 | 120:       begin
233 | 121:         Process.kill(Application::SIGNAL, pid)
234 | 122:         while Pid.running?(pid)
235 | 123:           sleep 0.1
236 | 124:         end
237 | 125:       rescue ::Exception => e
238 | 126:         puts "#{e} #{@pid.pid}"
239 | 127:         puts "deleting pid-file."
240 | 128:       end
241 | 129:       
242 | 130:       # We try to remove the pid-files by ourselves, in case the application
243 | 131:       # didn't clean it up.
244 | 132:       begin; @pid.cleanup; rescue ::Exception; end
245 | 133:     end
246 | 
247 |
248 |
249 |
250 | 251 | 252 |
253 | 254 | 255 |
256 | 257 | 258 |
259 |

[Validate]

260 |
261 | 262 | 263 | -------------------------------------------------------------------------------- /html/classes/Daemons/Optparse.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::Optparse 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassDaemons::Optparse
In: 58 | 59 | lib/daemons/cmdline.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 | 82 | 83 |
84 | 85 |
86 |

Methods

87 | 88 |
89 | new   90 | parse   91 |
92 |
93 | 94 |
95 | 96 | 97 | 98 | 99 |
100 | 101 | 102 | 103 | 104 | 105 |
106 |

Attributes

107 | 108 |
109 | 110 | 111 | 112 | 113 | 114 | 115 |
usage [R] 
116 |
117 |
118 | 119 | 120 | 121 | 122 |
123 |

Public Class methods

124 | 125 |
126 | 127 | 128 | 133 | 134 |
135 |

[Source]

137 |
138 |
139 |     # File lib/daemons/cmdline.rb, line 8
140 |  8:     def initialize(controller)
141 |  9:       @controller = controller
142 | 10:       @options = {}
143 | 11:       
144 | 12:       @opts = OptionParser.new do |opts|
145 | 13:         #opts.banner = "Usage: example.rb [options]"
146 | 14:         opts.banner = ""
147 | 15:         
148 | 16:         # Boolean switch.
149 | 17: #         opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
150 | 18: #           @options[:verbose] = v
151 | 19: #         end
152 | 20:         
153 | 21:         opts.on("-t", "--ontop", "Stay on top (does not daemonize)") do |t|
154 | 22:           @options[:ontop] = t
155 | 23:         end
156 | 24:         
157 | 25:         opts.on("-f", "--force", "Force operation") do |t|
158 | 26:           @options[:force] = t
159 | 27:         end
160 | 28:         
161 | 29:         #opts.separator ""
162 | 30:         #opts.separator "Specific options:"
163 | 31: 
164 | 32:         
165 | 33:         opts.separator ""
166 | 34:         opts.separator "Common options:"
167 | 35: 
168 | 36:         # No argument, shows at tail.  This will print an options summary.
169 | 37:         # Try it and see!
170 | 38:         opts.on_tail("-h", "--help", "Show this message") do
171 | 39:           #puts opts
172 | 40:           #@usage = 
173 | 41:           controller.print_usage()
174 | 42:           
175 | 43:           exit
176 | 44:         end
177 | 45: 
178 | 46:         # Another typical switch to print the version.
179 | 47:         opts.on_tail("--version", "Show version") do
180 | 48:           puts "daemons version #{Daemons::VERSION}"
181 | 49:           exit
182 | 50:         end
183 | 51:       end  
184 | 52:       
185 | 53:       begin
186 | 54:         @usage = @opts.to_s
187 | 55:       rescue ::Exception # work around a bug in ruby 1.9
188 | 56:         @usage = "            -t, --ontop                      Stay on top (does not daemonize)\n            -f, --force                      Force operation\n\n        Common options:\n            -h, --help                       Show this message\n                --version                    Show version\n"
189 | 57:       end
190 | 58:     end
191 | 
192 |
193 |
194 |
195 | 196 |

Public Instance methods

197 | 198 |
199 | 200 | 201 | 206 | 207 |
208 |

209 | Return a hash describing the options. 210 |

211 |

[Source]

213 |
214 |
215 |     # File lib/daemons/cmdline.rb, line 72
216 | 72:     def parse(args)
217 | 73:       # The options specified on the command line will be collected in *options*.
218 | 74:       # We set default values here.
219 | 75:       #options = {}
220 | 76:       
221 | 77:       
222 | 78:       ##pp args
223 | 79:       @opts.parse(args)
224 | 80:       
225 | 81:       return @options
226 | 82:     end
227 | 
228 |
229 |
230 |
231 | 232 | 233 |
234 | 235 | 236 |
237 | 238 | 239 |
240 |

[Validate]

241 |
242 | 243 | 244 | -------------------------------------------------------------------------------- /html/classes/Daemons/PidMem.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::PidMem 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 72 | 73 |
ClassDaemons::PidMem
In: 58 | 59 | lib/daemons/pidmem.rb 60 | 61 |
62 |
Parent: 68 | 69 | Pid 70 | 71 |
74 |
75 | 76 | 77 |
78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 |
86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 | 97 | 98 | 99 |
100 |

Attributes

101 | 102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 |
pid [RW] 
110 |
111 |
112 | 113 | 114 | 115 | 116 | 117 | 118 |
119 | 120 | 121 |
122 |

[Validate]

123 |
124 | 125 | 126 | -------------------------------------------------------------------------------- /html/classes/Daemons/RuntimeException.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::RuntimeException 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 72 | 73 |
ClassDaemons::RuntimeException
In: 58 | 59 | lib/daemons/exceptions.rb 60 | 61 |
62 |
Parent: 68 | 69 | Exception 70 | 71 |
74 |
75 | 76 | 77 |
78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 |
86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 | 108 |
109 |

[Validate]

110 |
111 | 112 | 113 | -------------------------------------------------------------------------------- /html/classes/Daemons/SystemError.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Daemons::SystemError 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 72 | 73 |
ClassDaemons::SystemError
In: 58 | 59 | lib/daemons/exceptions.rb 60 | 61 |
62 |
Parent: 68 | 69 | Error 70 | 71 |
74 |
75 | 76 | 77 |
78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 |
86 | 87 |
88 |

Methods

89 | 90 |
91 | new   92 |
93 |
94 | 95 |
96 | 97 | 98 | 99 | 100 |
101 | 102 | 103 | 104 | 105 | 106 |
107 |

Attributes

108 | 109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 |
system_error [R] 
117 |
118 |
119 | 120 | 121 | 122 | 123 |
124 |

Public Class methods

125 | 126 |
127 | 128 | 129 | 134 | 135 |
136 |

[Source]

138 |
139 |
140 |     # File lib/daemons/exceptions.rb, line 20
141 | 20:     def initialize(msg, system_error)
142 | 21:       super(msg)
143 | 22:       
144 | 23:       @system_error = system_error
145 | 24:     end
146 | 
147 |
148 |
149 |
150 | 151 | 152 |
153 | 154 | 155 |
156 | 157 | 158 |
159 |

[Validate]

160 |
161 | 162 | 163 | -------------------------------------------------------------------------------- /html/created.rid: -------------------------------------------------------------------------------- 1 | Wed, 26 Aug 2009 15:13:46 -0700 2 | -------------------------------------------------------------------------------- /html/files/README.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: README 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

README

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:README 55 |
Last Update:Wed Aug 26 15:13:40 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 |
72 |

Daemons Version 1.0.11

73 |

74 | (See Releases for release-specific information) 75 |

76 |

What is Daemons?

77 |

78 | Daemons provides an easy way to wrap 79 | existing ruby scripts (for example a self-written server) to be run as 80 | a daemon and to be controlled by simple start/stop/restart 81 | commands. 82 |

83 |

84 | If you want, you can also use daemons to run blocks of ruby code in a 85 | daemon process and to control these processes from the main 86 | application. 87 |

88 |

89 | Besides this basic functionality, daemons offers many advanced features 90 | like exception backtracing and logging (in case your ruby script 91 | crashes) and monitoring and automatic restarting of your processes 92 | if they crash. 93 |

94 |

95 | Daemons includes the 96 | daemonize.rb script written by Travis Whitton to do the 97 | daemonization process. 98 |

99 |

Basic Usage

100 |

101 | You can use Daemons in four differet 102 | ways: 103 |

104 |

1. Create wrapper scripts for your server scripts or applications

105 |

106 | Layout: suppose you have your self-written server myserver.rb: 107 |

108 |
109 |   # this is myserver.rb
110 |   # it does nothing really useful at the moment
111 | 
112 |   loop do
113 |     sleep(5)
114 |   end
115 | 
116 |

117 | To use myserver.rb in a production environment, you need to be 118 | able to run myserver.rb in the background (this means 119 | detach it from the console, fork it in the background, release all 120 | directories and file descriptors). 121 |

122 |

123 | Just create myserver_control.rb like this: 124 |

125 |
126 |   # this is myserver_control.rb
127 | 
128 |   require 'rubygems'        # if you use RubyGems
129 |   require 'daemons'
130 | 
131 |   Daemons.run('myserver.rb')
132 | 
133 |

134 | And use it like this from the console: 135 |

136 |
137 |   $ ruby myserver_control.rb start
138 |       (myserver.rb is now running in the background)
139 |   $ ruby myserver_control.rb restart
140 |       (...)
141 |   $ ruby myserver_control.rb stop
142 | 
143 |

144 | For testing purposes you can even run myserver.rb without 145 | forking in the background: 146 |

147 |
148 |   $ ruby myserver_control.rb run
149 | 
150 |

151 | An additional nice feature of Daemons 152 | is that you can pass additional arguments to the script that 153 | should be daemonized by seperating them by two hyphens: 154 |

155 |
156 |   $ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
157 | 
158 |

2. Create wrapper scripts that include your server procs

159 |

160 | Layout: suppose you have some code you want to run in the background and 161 | control that background process from a script: 162 |

163 |
164 |   # this is your code
165 |   # it does nothing really useful at the moment
166 | 
167 |   loop do
168 |     sleep(5)
169 |   end
170 | 
171 |

172 | To run this code as a daemon create myproc_control.rb like this 173 | and include your code: 174 |

175 |
176 |   # this is myproc_control.rb
177 | 
178 |   require 'rubygems'        # if you use RubyGems
179 |   require 'daemons'
180 | 
181 |   Daemons.run_proc('myproc.rb') do
182 |     loop do
183 |       sleep(5)
184 |     end
185 |   end
186 | 
187 |

188 | And use it like this from the console: 189 |

190 |
191 |   $ ruby myproc_control.rb start
192 |       (myproc.rb is now running in the background)
193 |   $ ruby myproc_control.rb restart
194 |       (...)
195 |   $ ruby myproc_control.rb stop
196 | 
197 |

198 | For testing purposes you can even run myproc.rb without 199 | forking in the background: 200 |

201 |
202 |   $ ruby myproc_control.rb run
203 | 
204 |

3. Control a bunch of daemons from another application

205 |

206 | Layout: you have an application my_app.rb that wants to run a 207 | bunch of server tasks as daemon processes. 208 |

209 |
210 |   # this is my_app.rb
211 | 
212 |   require 'rubygems'        # if you use RubyGems
213 |   require 'daemons'
214 | 
215 |   task1 = Daemons.call(:multiple => true) do
216 |     # first server task
217 | 
218 |     loop {
219 |       conn = accept_conn()
220 |       serve(conn)
221 |     }
222 |   end
223 | 
224 |   task2 = Daemons.call do
225 |     # second server task
226 | 
227 |     loop {
228 |       something_different()
229 |     }
230 |   end
231 | 
232 |   # the parent process continues to run
233 | 
234 |   # we can even control our tasks, for example stop them
235 |   task1.stop
236 |   task2.stop
237 | 
238 |   exit
239 | 
240 |

4. Daemonize the currently running process

241 |

242 | Layout: you have an application my_daemon.rb that wants to run as 243 | a daemon (but without the ability to be controlled by daemons via 244 | start/stop commands) 245 |

246 |
247 |   # this is my_daemons.rb
248 | 
249 |   require 'rubygems'        # if you use RubyGems
250 |   require 'daemons'
251 | 
252 |   # Initialize the app while we're not a daemon
253 |   init()
254 | 
255 |   # Become a daemon
256 |   Daemons.daemonize
257 | 
258 |   # The server loop
259 |   loop {
260 |     conn = accept_conn()
261 |     serve(conn)
262 |   }
263 | 
264 |

265 | For further documentation, refer to the module documentation of Daemons. 267 |

268 |

Download and Installation

269 |

270 | Download: just go to rubyforge.org/projects/daemons/ 272 |

273 |

274 | Installation with RubyGems: 275 |

276 |
277 |   $ su
278 |   # gem install daemons
279 | 
280 |

281 | Installation without RubyGems: 282 |

283 |
284 |   $ tar xfz daemons-x.x.x.tar.gz
285 |   $ cd daemons-x.x.x
286 |   $ su
287 |   # ruby setup.rb
288 | 
289 |

Documentation

290 |

291 | For further documentation, refer to the module documentation of Daemons (click on Daemons). 294 |

295 |

296 | The RDoc documentation is also online at daemons.rubyforge.org 298 |

299 |

Author

300 |

301 | Written in 2005-2008 by Thomas Uehlinger <th.uehlinger@gmx.ch>. 303 |

304 |

License

305 |

306 | Copyright (c) 2005-2008 Thomas Uehlinger 307 |

308 |

309 | Permission is hereby granted, free of charge, to any person obtaining a 310 | copy of this software and associated documentation files (the 311 | "Software"), to deal in the Software without restriction, 312 | including without limitation the rights to use, copy, modify, merge, 313 | publish, distribute, sublicense, and/or sell copies of the Software, and to 314 | permit persons to whom the Software is furnished to do so, subject to the 315 | following conditions: 316 |

317 |

318 | The above copyright notice and this permission notice shall be included in 319 | all copies or substantial portions of the Software. 320 |

321 |

322 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 323 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 324 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 325 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 326 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 327 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 328 | USE OR OTHER DEALINGS IN THE SOFTWARE. 329 |

330 |

331 | This license does not apply to daemonize.rb, which is was written by Travis 332 | Whitton und published under the following license: 333 |

334 |

335 | The Daemonize extension module is 336 | copywrited free software by Travis Whitton <whitton@atlantic.net>. 337 | You can redistribute it under the terms specified in the COPYING file of 338 | the Ruby distribution. 339 |

340 |

Feedback and other resources

341 |

342 | At rubyforge.org/projects/daemons. 344 |

345 | 346 |
347 | 348 | 349 |
350 | 351 | 352 |
353 | 354 | 355 | 356 | 357 |
358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 |
370 | 371 | 372 |
373 |

[Validate]

374 |
375 | 376 | 377 | -------------------------------------------------------------------------------- /html/files/Releases.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: Releases 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

Releases

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:Releases 55 |
Last Update:Tue Aug 25 22:31:41 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 |
72 |

Daemons Release History

73 |

Release 1.0.10: November 16, 2007

74 |
    75 |
  • By default, we now delete stray pid-files (i.e. pid-files which result for 76 | example from a killed daemon) automatically. This function can be 77 | deactivated by passing :keep_pid_files => true as an option. 78 | 79 |
  • 80 |
  • All pid files of :multiple daemons new get deleted correctly upon exit of 81 | the daemons (reported by Han Holl). 82 | 83 |
  • 84 |
  • Use the signal ‘KILL’ instead of ‘TERM’ on Windows 85 | platforms. 86 | 87 |
  • 88 |
  • Use exit! in trap(‘TERM’) instead of exit when option 89 | :hard_exit is given (thanks to Han Holl). 90 | 91 |
  • 92 |
  • Did some clarification on the exception log. 93 | 94 |
  • 95 |
96 |

Release 1.0.9: October 29, 2007

97 |
    98 |
  • fixed a severe bug in the new Pid.running? function: function returned true 99 | if the process did not exist (thanks to Jeremy Lawler). 100 | 101 |
  • 102 |
103 |

Release 1.0.8: September 24, 2007

104 |
    105 |
  • new Pid.running? function. Checking whether a process exists by sending 106 | signal ‘0’ (thanks to Dru Nelson). 107 | 108 |
  • 109 |
110 |

Release 1.0.7: July 7, 2007

111 |
    112 |
  • Patch to fix wrong ARGV when using :exec (in def start_exec: 113 | Kernel.exec(script(), *(@app_argv || []))) (thanks to Alex McGuire). 114 | 115 |
  • 116 |
117 |

Release 1.0.6: Mai 8, 2007

118 |
    119 |
  • New option to pass an ARGV-style array to run and run_proc (thanks to Marc 120 | Evans). 121 | 122 |
  • 123 |
  • Additional patches for ’/var/log’ (thanks to Marc Evans). 124 | 125 |
  • 126 |
127 |

Release 1.0.5: February 24, 2007

128 |
    129 |
  • Applied patch that makes daemons to use ’/var/log’ as logfile 130 | directory if you use :dir_mode = :system (thanks to Han Holl). 131 | 132 |
  • 133 |
  • Daemons should now work with Ruby 1.9 134 | (at least the basic features). 135 | 136 |
  • 137 |
138 |

Release 1.0.4: January 17, 2007

139 |
    140 |
  • Document the :log_output option (thanks to Andrew Kuklewicz). 141 | 142 |
  • 143 |
  • Set STDOUT.sync = true when redirecting to a logfile (thanks to Andrew 144 | Kuklewicz). 145 | 146 |
  • 147 |
  • Should now run also correctly when there is no working ‘ps ax’ 148 | on the system (thanks to Daniel Kehoe). 149 | 150 |
  • 151 |
152 |

Release 1.0.3: November 1, 2006

153 |
    154 |
  • Set the app_name correctly also for the monitor process (thanks to Ilya 155 | Novoselov). 156 | 157 |
  • 158 |
159 |

Release 1.0.2: September 26, 2006

160 |
    161 |
  • Changed the ‘ps -ax’ call back to ‘ps ax’. 162 | 163 |
  • 164 |
  • Fixed the documentation for the :normal :dir_mode. 165 | 166 |
  • 167 |
  • As a default for Daemons.run_proc, the pid file 169 | is now saved in the current directory. 170 | 171 |
  • 172 |
  • In :ontop mode for running a proc (this is equal to calling something like 173 | ‘ruby ctrl_proc.rb run’), the proc now runs directly in the 174 | calling script, not in a forked process anymore (thanks to Paul Butcher). 175 | 176 |
  • 177 |
  • Set $0 to app_name in the daemons (thanks to Ilya Novoselov). 178 | 179 |
  • 180 |
181 |

Release 1.0.1: August 30, 2006

182 |
    183 |
  • Fixed a regex for parsing the ‘ps ax’ system call. (thanks to 184 | Garance Alistair Drosehn) 185 | 186 |
  • 187 |
188 |

Release 1.0.0: August 29, 2006

189 |
    190 |
  • Fix the parsing of the ‘ps ax’ system call. (thanks to Garance 191 | Alistair Drosehn) 192 | 193 |
  • 194 |
195 |

Release 0.4.4: February 14, 2006

196 |
    197 |
  • Several fixes that allow us to use the Daemons::Controller with a 199 | proc instead of wrapping a script file. This gives us all the PID file 200 | management, monitoring, command line options, etc. without having to 201 | specify a path to our script which can be tricky, especially when using 202 | RubyGems. (thanks to John-Mason Shackelford) 203 | 204 |
  • 205 |
206 |

Release 0.4.3: November 29, 2005

207 |
    208 |
  • New Option: You can specify the name of the application with :app_name on 209 | calling Daemons.run. This 210 | will be used to contruct the name of the pid files and log files. Defaults 211 | to the basename of the script. (thanks to Stephen R. Veit) 212 | 213 |
  • 214 |
  • Bugfix: Handle the case where no controller options are given when calling 215 | Daemons, just options after 216 | "—". (thanks to Stephen R. Veit) 217 | 218 |
  • 219 |
220 |

Release 0.4.2: November 15, 2005

221 |
    222 |
  • Bugfix for problem with :normal pid-file directory mode (pid.rb), fixed 223 | (thanks to Stephen R. Veit) 224 | 225 |
  • 226 |
227 |

Release 0.4.1: September 11, 2005

228 |
    229 |
  • Bugfix for ‘run’ command line mode: didn‘t work anymore 230 | in 0.4.0, fixed 231 | 232 |
  • 233 |
234 |

Release 0.4.0: July 30, 2005

235 |
    236 |
  • Two completely new operation modes: 237 | 238 |
      239 |
    1. Call a block as a daemon (Daemons.call { my_daemon_code 241 | }) and control it from the parent process. 242 | 243 |
    2. 244 |
    3. Daemonize the currently running 245 | process (Daemons.daemonize) 247 | 248 |
    4. 249 |
    250 |

    251 | plus the already existing mode to control your scripts (Daemons.run("script.rb")) 253 |

    254 |
  • 255 |
  • Improved documentation (for example "How does the daemonization 256 | process work?") 257 | 258 |
  • 259 |
  • Improved "simulation mode" (:ontop option) 260 | 261 |
  • 262 |
  • Some minor bugfixes 263 | 264 |
  • 265 |
266 |

Release 0.3.0: April 21, 2005

267 |
    268 |
  • New monitor functionality: automatic restarting of your applications if 269 | they crash 270 | 271 |
  • 272 |
  • ‘restart’ command fixed 273 | 274 |
  • 275 |
  • ’—force’ command modifier (please refer to the 276 | documentation) 277 | 278 |
  • 279 |
  • Some more bugfixes and improvements 280 | 281 |
  • 282 |
283 |

Release 0.2.1: Mar 21, 2005

284 |
    285 |
  • Bugfix for a problem with the ‘status’ command 286 | 287 |
  • 288 |
289 |

Release 0.2.0: Mar 21, 2005

290 |
    291 |
  • Exception backtrace functionality added 292 | 293 |
  • 294 |
  • Exec functionality added 295 | 296 |
  • 297 |
  • More examples added 298 | 299 |
  • 300 |
  • New commands: status, zap 301 | 302 |
  • 303 |
304 |

Release 0.0.1: Feb 8, 2005

305 |
    306 |
  • Initial release 307 | 308 |
  • 309 |
310 | 311 |
312 | 313 | 314 |
315 | 316 | 317 |
318 | 319 | 320 | 321 | 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 |
335 | 336 | 337 |
338 |

[Validate]

339 |
340 | 341 | 342 | -------------------------------------------------------------------------------- /html/files/TODO.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: TODO 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

TODO

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:TODO 55 |
Last Update:Tue Aug 25 22:22:46 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 |
72 |
    73 |
  • write the README (2005-02-07) DONE 74 | 75 |
  • 76 |
  • write some real tests (2005-02-08) 77 | 78 |
  • 79 |
  • document the new options (2005-03-14) DONE 80 | 81 |
  • 82 |
  • start/stop with —force options (2005-04-05) 83 | 84 |
  • 85 |
  • option to give some console output on start/stop commands (2005-04-05) 86 | 87 |
  • 88 |
89 | 90 |
91 | 92 | 93 |
94 | 95 | 96 |
97 | 98 | 99 | 100 | 101 |
102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 | 115 | 116 |
117 |

[Validate]

118 |
119 | 120 | 121 | -------------------------------------------------------------------------------- /html/files/lib/daemons/application_group_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: application_group.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

application_group.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/application_group.rb 55 |
Last Update:Tue Aug 25 22:32:53 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /html/files/lib/daemons/application_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: application.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

application.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/application.rb 55 |
Last Update:Tue Aug 25 22:43:56 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 |
73 |

Required files

74 | 75 |
76 | daemons/pidfile   77 | daemons/pidmem   78 | logger   79 |
80 |
81 | 82 |
83 | 84 | 85 |
86 | 87 | 88 | 89 | 90 |
91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 |
103 | 104 | 105 |
106 |

[Validate]

107 |
108 | 109 | 110 | -------------------------------------------------------------------------------- /html/files/lib/daemons/cmdline_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: cmdline.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

cmdline.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/cmdline.rb 55 |
Last Update:Tue Aug 25 22:22:46 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /html/files/lib/daemons/controller_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: controller.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

controller.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/controller.rb 55 |
Last Update:Tue Aug 25 22:22:46 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /html/files/lib/daemons/daemonize_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: daemonize.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

daemonize.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/daemonize.rb 55 |
Last Update:Tue Aug 25 22:22:46 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 |
72 |

Daemonize Library

73 |

74 | February. 4, 2005 Travis Whitton <whitton@atlantic.net> 75 |

76 |

77 | Daemonize allows you to 78 | easily modify any existing Ruby program to run as a daemon. See README.rdoc 79 | for more details. 80 |

81 |

How to install

82 |
    83 |
  1. su to root 84 | 85 |
  2. 86 |
  3. ruby install.rb 87 | 88 |
  4. 89 |
90 |

91 | build the docs if you want to 92 |

93 |
    94 |
  1. rdoc —main README.rdoc daemonize.rb README.rdoc 95 | 96 |
  2. 97 |
98 |

Copying

99 |

100 | The Daemonize extension 101 | module is copywrited free software by Travis Whitton 102 | <whitton@atlantic.net>. You can redistribute it under the terms 103 | specified in the COPYING file of the Ruby distribution. 104 |

105 |

WARRANTY

106 |

107 | THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR 108 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES 109 | OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 110 |

111 |

Purpose

112 |

113 | Daemonize is a module derived 114 | from Perl‘s Proc::Daemon module. This module allows you to easily 115 | modify any existing Ruby program to run as a daemon. A daemon is a process 116 | that runs in the background with no controlling terminal. Generally servers 117 | (like FTP and HTTP servers) run as daemon processes. Note, do not make the 118 | mistake that a daemon == server. Converting a program to a daemon by hand 119 | is a relatively simple process; however, this module will save you the 120 | effort of repeatedly looking up the procedure, and it will also insure that 121 | your programs are daemonized in the safest and most corrects fashion 122 | possible. 123 |

124 |

Procedure

125 |

126 | The Daemonize module does the 127 | following: 128 |

129 |

130 | Forks a child and exits the parent process. 131 |

132 |

133 | Becomes a session leader (which detaches the program from the controlling 134 | terminal). 135 |

136 |

137 | Forks another child process and exits first child. This prevents the 138 | potential of acquiring a controlling terminal. 139 |

140 |

141 | Changes the current working directory to "/". 142 |

143 |

144 | Clears the file creation mask. 145 |

146 |

147 | Closes file descriptors. 148 |

149 |

Example usage

150 |

151 | Using the Daemonize module is 152 | extremely simple: 153 |

154 |
155 |     require 'daemonize'
156 | 
157 |     class TestDaemon
158 |       include Daemonize
159 | 
160 |       def initialize
161 |         daemonize()
162 |         loop do
163 |           # do some work here
164 |         end
165 |       end
166 |     end
167 | 
168 |

Credits

169 |

170 | Daemonize was written by 171 | Travis Whitton and is based on Perl‘s Proc::Daemonize, which was 172 | written by Earl Hood. The above documentation is also partially borrowed 173 | from the Proc::Daemonize POD documentation. 174 |

175 | 176 |
177 | 178 | 179 |
180 | 181 | 182 |
183 | 184 | 185 | 186 | 187 |
188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 |
200 | 201 | 202 |
203 |

[Validate]

204 |
205 | 206 | 207 | -------------------------------------------------------------------------------- /html/files/lib/daemons/exceptions_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: exceptions.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

exceptions.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/exceptions.rb 55 |
Last Update:Tue Aug 25 22:22:46 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /html/files/lib/daemons/monitor_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: monitor.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

monitor.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/monitor.rb 55 |
Last Update:Tue Aug 25 22:42:43 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 |
73 |

Required files

74 | 75 |
76 | daemons/daemonize   77 |
78 |
79 | 80 |
81 | 82 | 83 |
84 | 85 | 86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 |
101 | 102 | 103 |
104 |

[Validate]

105 |
106 | 107 | 108 | -------------------------------------------------------------------------------- /html/files/lib/daemons/pid_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: pid.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

pid.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/pid.rb 55 |
Last Update:Tue Aug 25 22:32:34 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 |
73 |

Required files

74 | 75 |
76 | open3   77 |
78 |
79 | 80 |
81 | 82 | 83 |
84 | 85 | 86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 |
101 | 102 | 103 |
104 |

[Validate]

105 |
106 | 107 | 108 | -------------------------------------------------------------------------------- /html/files/lib/daemons/pidfile_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: pidfile.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

pidfile.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/pidfile.rb 55 |
Last Update:Tue Aug 25 22:32:21 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 |
73 |

Required files

74 | 75 |
76 | daemons/pid   77 |
78 |
79 | 80 |
81 | 82 | 83 |
84 | 85 | 86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 |
101 | 102 | 103 |
104 |

[Validate]

105 |
106 | 107 | 108 | -------------------------------------------------------------------------------- /html/files/lib/daemons/pidmem_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: pidmem.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

pidmem.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons/pidmem.rb 55 |
Last Update:Tue Aug 25 22:22:46 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 |
73 |

Required files

74 | 75 |
76 | daemons/pid   77 |
78 |
79 | 80 |
81 | 82 | 83 |
84 | 85 | 86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 |
101 | 102 | 103 |
104 |

[Validate]

105 |
106 | 107 | 108 | -------------------------------------------------------------------------------- /html/files/lib/daemons_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: daemons.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

daemons.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/daemons.rb 55 |
Last Update:Tue Aug 25 22:48:31 -0700 2009
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 |
73 |

Required files

74 | 75 |
76 | optparse   77 | optparse/time   78 | daemons/pidfile   79 | daemons/cmdline   80 | daemons/exceptions   81 | daemons/monitor   82 | daemons/application   83 | daemons/application_group   84 | daemons/controller   85 | daemons/daemonize   86 |
87 |
88 | 89 |
90 | 91 | 92 |
93 | 94 | 95 | 96 | 97 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
110 | 111 | 112 |
113 |

[Validate]

114 |
115 | 116 | 117 | -------------------------------------------------------------------------------- /html/fr_class_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 12 | 13 | 14 | Classes 15 | 16 | 17 | 18 | 19 | 20 | 40 | 41 | -------------------------------------------------------------------------------- /html/fr_file_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 12 | 13 | 14 | Files 15 | 16 | 17 | 18 | 19 | 20 | 39 | 40 | -------------------------------------------------------------------------------- /html/fr_method_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 12 | 13 | 14 | Methods 15 | 16 | 17 | 18 | 19 | 20 |
21 |

Methods

22 |
23 | call (Daemons)
24 | call_as_daemon (Daemonize)
25 | catch_exceptions (Daemons::Controller)
26 | cleanup (Daemons::Pid)
27 | cleanup (Daemons::PidFile)
28 | controller (Daemons)
29 | create_monitor (Daemons::ApplicationGroup)
30 | daemonize (Daemonize)
31 | daemonize (Daemons)
32 | dir (Daemons::Pid)
33 | exception_log (Daemons::Application)
34 | exist? (Daemons::PidFile)
35 | exist? (Daemons::Pid)
36 | existing (Daemons::PidFile)
37 | filename (Daemons::PidFile)
38 | find (Daemons::Monitor)
39 | find_applications (Daemons::ApplicationGroup)
40 | find_files (Daemons::PidFile)
41 | group (Daemons)
42 | logfile (Daemons::Application)
43 | new (Daemons::Optparse)
44 | new (Daemons::Application)
45 | new (Daemons::Controller)
46 | new (Daemons::SystemError)
47 | new (Daemons::ApplicationGroup)
48 | new (Daemons::Pid)
49 | new (Daemons::Monitor)
50 | new (Daemons::PidFile)
51 | new_application (Daemons::ApplicationGroup)
52 | output_logfile (Daemons::Application)
53 | parse (Daemons::Optparse)
54 | pid (Daemons::PidFile)
55 | pid (Daemons::Pid)
56 | pid= (Daemons::Pid)
57 | pid= (Daemons::PidFile)
58 | pidfile_dir (Daemons::ApplicationGroup)
59 | pidfile_dir (Daemons::Application)
60 | print_usage (Daemons::Controller)
61 | redirect_io (Daemonize)
62 | run (Daemons::Controller)
63 | run (Daemons)
64 | run_proc (Daemons)
65 | running? (Daemons::Application)
66 | running? (Daemons::Pid)
67 | safefork (Daemonize)
68 | script (Daemons::Application)
69 | setup (Daemons::ApplicationGroup)
70 | setup_options (Daemons::Controller)
71 | show_status (Daemons::Application)
72 | show_status (Daemons::ApplicationGroup)
73 | simulate (Daemonize)
74 | split_argv (Daemons::Controller)
75 | start (Daemons::Monitor)
76 | start (Daemons::Application)
77 | start_all (Daemons::ApplicationGroup)
78 | start_exec (Daemons::Application)
79 | start_load (Daemons::Application)
80 | start_none (Daemons::Application)
81 | start_proc (Daemons::Application)
82 | stop (Daemons::Monitor)
83 | stop (Daemons::Application)
84 | stop_all (Daemons::ApplicationGroup)
85 | zap (Daemons::Application)
86 | zap! (Daemons::Application)
87 | zap_all (Daemons::ApplicationGroup)
88 |
89 |
90 | 91 | -------------------------------------------------------------------------------- /html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 13 | Daemons 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /html/rdoc-style.css: -------------------------------------------------------------------------------- 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; } -------------------------------------------------------------------------------- /lib/daemons.rb: -------------------------------------------------------------------------------- 1 | require 'optparse' 2 | require 'optparse/time' 3 | 4 | 5 | require 'daemons/pidfile' 6 | require 'daemons/cmdline' 7 | require 'daemons/exceptions' 8 | require 'daemons/monitor' 9 | 10 | 11 | require 'daemons/application' 12 | require 'daemons/application_group' 13 | require 'daemons/controller' 14 | 15 | 16 | # All functions and classes that Daemons provides reside in this module. 17 | # 18 | # Daemons is normally invoked by one of the following four ways: 19 | # 20 | # 1. Daemons.run(script, options): 21 | # This is used in wrapper-scripts that are supposed to control other ruby scripts or 22 | # external applications. Control is completely passed to the daemons library. 23 | # Such wrapper script need to be invoked with command line options like 'start' or 'stop' 24 | # to do anything useful. 25 | # 26 | # 2. Daemons.run_proc(app_name, options) { (...) }: 27 | # This is used in wrapper-scripts that are supposed to control a proc. 28 | # Control is completely passed to the daemons library. 29 | # Such wrapper script need to be invoked with command line options like 'start' or 'stop' 30 | # to do anything useful. 31 | # 32 | # 3. Daemons.call(options) { block }: 33 | # Execute the block in a new daemon. Daemons.call will return immediately 34 | # after spawning the daemon with the new Application object as a return value. 35 | # 36 | # 4. Daemons.daemonize(options): 37 | # Daemonize the currently runnig process, i.e. the calling process will become a daemon. 38 | # 39 | # == What does daemons internally do with my daemons? 40 | # *or*:: why do my daemons crash when they try to open a file? 41 | # *or*:: why can I not see any output from the daemon on the console (when using for example +puts+)? 42 | # 43 | # From a technical aspect of view, daemons does the following when creating a daemon: 44 | # 45 | # 1. Forks a child (and exits the parent process, if needed) 46 | # 2. Becomes a session leader (which detaches the program from 47 | # the controlling terminal). 48 | # 3. Forks another child process and exits first child. This prevents 49 | # the potential of acquiring a controlling terminal. 50 | # 4. Changes the current working directory to "/". 51 | # 5. Clears the file creation mask (sets +umask+ to 0000). 52 | # 6. Closes file descriptors (reopens +STDOUT+ and +STDERR+ to point to a logfile if 53 | # possible). 54 | # 55 | # So what does this mean for your daemons: 56 | # - the current directory is '/' 57 | # - you cannot receive any input from the console (for example no +gets+) 58 | # - you cannot output anything from the daemons with +puts+/+print+ unless a logfile is used 59 | # 60 | # == How do PidFiles work? Where are they stored? 61 | # 62 | # Also, you are maybe interested in reading the documentation for the class PidFile. 63 | # There you can find out about how Daemons works internally and how and where the so 64 | # called PidFiles are stored. 65 | # 66 | module Daemons 67 | 68 | VERSION = "1.0.11" 69 | 70 | require 'daemons/daemonize' 71 | 72 | 73 | # Passes control to Daemons. 74 | # This is used in wrapper-scripts that are supposed to control other ruby scripts or 75 | # external applications. Control is completely passed to the daemons library. 76 | # Such wrapper script should be invoked with command line options like 'start' or 'stop' 77 | # to do anything useful. 78 | # 79 | # +script+:: This is the path to the script that should be run as a daemon. 80 | # Please note that Daemons runs this script with load