Method: Daemons.run_proc
- Defined in:
- lib/daemons.rb
.run_proc(app_name, options = {}, &block) ⇒ Object
Passes control to Daemons. This function does the same as Daemons.run except that not a script but a proc will be run as a daemon while this script provides command line options like ‘start’ or ‘stop’ and the whole pid-file management to control the proc.
app_name
-
The name of the application. This will be used to contruct the name of the pid files and log files. Defaults to the basename of the script.
options
-
A hash that may contain one or more of the options listed in the documentation for Daemons.run
A block must be given to this function. The block will be used as the :proc entry in the options hash.
Example:
Daemons.run_proc('myproc.rb') do
loop do
accept_connection()
read_request()
send_response()
close_connection()
end
end
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/daemons.rb', line 185 def run_proc(app_name, = {}, &block) [:app_name] = app_name [:mode] = :proc [:proc] = block # we do not have a script location so the the :script :dir_mode cannot be used, change it to :normal if [nil, :script].include? [:dir_mode] [:dir_mode] = :normal [:dir] ||= File.('.') end @controller = Controller.new(, [:ARGV] || ARGV) @controller.catch_exceptions do @controller.run end # I don't think anybody will ever use @group, as this location should not be reached under non-error conditions @group = @controller.group end |