fire_and_forget 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -2
- data/bin/fire_forget +0 -4
- data/fire_and_forget.gemspec +3 -25
- data/lib/fire_and_forget/command.rb +1 -1
- data/lib/fire_and_forget/command/fire.rb +77 -3
- data/lib/fire_and_forget/command/set_pid.rb +4 -0
- data/lib/fire_and_forget/command/set_status.rb +4 -0
- data/lib/fire_and_forget/server.rb +2 -2
- data/lib/fire_and_forget/version.rb +1 -1
- data/test/test_fire_and_forget.rb +1 -1
- metadata +12 -45
- data/vendor/daemons-1.1.0/LICENSE +0 -29
- data/vendor/daemons-1.1.0/README +0 -224
- data/vendor/daemons-1.1.0/Rakefile +0 -88
- data/vendor/daemons-1.1.0/Releases +0 -152
- data/vendor/daemons-1.1.0/TODO +0 -2
- data/vendor/daemons-1.1.0/lib/daemons.rb +0 -288
- data/vendor/daemons-1.1.0/lib/daemons/application.rb +0 -468
- data/vendor/daemons-1.1.0/lib/daemons/application_group.rb +0 -194
- data/vendor/daemons-1.1.0/lib/daemons/change_privilege.rb +0 -19
- data/vendor/daemons-1.1.0/lib/daemons/cmdline.rb +0 -124
- data/vendor/daemons-1.1.0/lib/daemons/controller.rb +0 -140
- data/vendor/daemons-1.1.0/lib/daemons/daemonize.rb +0 -271
- data/vendor/daemons-1.1.0/lib/daemons/etc_extension.rb +0 -12
- data/vendor/daemons-1.1.0/lib/daemons/exceptions.rb +0 -28
- data/vendor/daemons-1.1.0/lib/daemons/monitor.rb +0 -138
- data/vendor/daemons-1.1.0/lib/daemons/pid.rb +0 -109
- data/vendor/daemons-1.1.0/lib/daemons/pidfile.rb +0 -116
- data/vendor/daemons-1.1.0/lib/daemons/pidmem.rb +0 -19
- data/vendor/daemons-1.1.0/setup.rb +0 -1360
@@ -1,88 +0,0 @@
|
|
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
|
-
}
|
@@ -1,152 +0,0 @@
|
|
1
|
-
= Daemons Release History
|
2
|
-
|
3
|
-
== Release 1.1.0: June 20, 2010
|
4
|
-
|
5
|
-
* Honour the options[:app_name] in Daemons.daemonize (thanks to Ryan Tecco).
|
6
|
-
* Included a new option :stop_proc to specify a proc that will be called when a
|
7
|
-
daemonized process receives a request to stop (thanks to Dave Dupre).
|
8
|
-
* Only delete the pidfile if the current pid is the original pid (ghazel).
|
9
|
-
* Start when restart but no application running (pcreux).
|
10
|
-
* Silently continue if there is no pidfile (ghazel).
|
11
|
-
* We now per default wait for processes to stop and
|
12
|
-
kill them automatically it if they do not stop within a given time
|
13
|
-
(force_kill_waittime). Use the option --no_wait to not wait for processes to
|
14
|
-
stop.
|
15
|
-
* Set log files mode to 0644 (mikehale).
|
16
|
-
* Set pid file permissions to 0644 (mikehale).
|
17
|
-
* Added ability to change process uid/gid (mikehale).
|
18
|
-
* Fix for: If you happen to start a daemon from a process that has open file
|
19
|
-
descriptors these will stay open. As it is daemonize.rb only closes ruby IO
|
20
|
-
objects (thanks to Han Holl).
|
21
|
-
* New reload command (SIGHUP) (thanks to Michael Schuerig).
|
22
|
-
|
23
|
-
== Release 1.0.10: March 21, 2008
|
24
|
-
|
25
|
-
* By default, we now delete stray pid-files (i.e. pid-files which result for
|
26
|
-
example from a killed daemon) automatically. This function can be deactivated
|
27
|
-
by passing :keep_pid_files => true as an option.
|
28
|
-
* All pid files of :multiple daemons new get deleted correctly upon exit of the
|
29
|
-
daemons (reported by Han Holl).
|
30
|
-
* Use the signal 'KILL' instead of 'TERM' on Windows platforms.
|
31
|
-
* Use exit! in trap('TERM') instead of exit when option :hard_exit is given
|
32
|
-
(thanks to Han Holl).
|
33
|
-
* Did some clarification on the exception log.
|
34
|
-
|
35
|
-
== Release 1.0.9: October 29, 2007
|
36
|
-
|
37
|
-
* fixed a severe bug in the new Pid.running? function: function returned true if
|
38
|
-
the process did not exist (thanks to Jeremy Lawler).
|
39
|
-
|
40
|
-
== Release 1.0.8: September 24, 2007
|
41
|
-
|
42
|
-
* new Pid.running? function. Checking whether a process exists by sending
|
43
|
-
signal '0' (thanks to Dru Nelson).
|
44
|
-
|
45
|
-
== Release 1.0.7: July 7, 2007
|
46
|
-
|
47
|
-
* Patch to fix wrong ARGV when using :exec (in def start_exec:
|
48
|
-
Kernel.exec(script(), *(@app_argv || []))) (thanks to Alex McGuire).
|
49
|
-
|
50
|
-
== Release 1.0.6: Mai 8, 2007
|
51
|
-
|
52
|
-
* New option to pass an ARGV-style array to run and run_proc (thanks to Marc Evans).
|
53
|
-
* Additional patches for '/var/log' (thanks to Marc Evans).
|
54
|
-
|
55
|
-
== Release 1.0.5: February 24, 2007
|
56
|
-
|
57
|
-
* Applied patch that makes daemons to use '/var/log' as logfile
|
58
|
-
directory if you use :dir_mode = :system (thanks to Han Holl).
|
59
|
-
* Daemons should now work with Ruby 1.9 (at least the basic features).
|
60
|
-
|
61
|
-
== Release 1.0.4: January 17, 2007
|
62
|
-
|
63
|
-
* Document the :log_output option (thanks to Andrew Kuklewicz).
|
64
|
-
* Set STDOUT.sync = true when redirecting to a logfile (thanks to Andrew Kuklewicz).
|
65
|
-
* Should now run also correctly when there is no working 'ps ax' on the system
|
66
|
-
(thanks to Daniel Kehoe).
|
67
|
-
|
68
|
-
== Release 1.0.3: November 1, 2006
|
69
|
-
|
70
|
-
* Set the app_name correctly also for the monitor process (thanks to Ilya Novoselov).
|
71
|
-
|
72
|
-
== Release 1.0.2: September 26, 2006
|
73
|
-
|
74
|
-
* Changed the 'ps -ax' call back to 'ps ax'.
|
75
|
-
* Fixed the documentation for the :normal :dir_mode.
|
76
|
-
* As a default for Daemons.run_proc, the pid file is now saved in the current directory.
|
77
|
-
* In :ontop mode for running a proc (this is equal to calling something like 'ruby ctrl_proc.rb run'),
|
78
|
-
the proc now runs directly in the calling script, not in a forked process anymore (thanks to Paul Butcher).
|
79
|
-
* Set $0 to app_name in the daemons (thanks to Ilya Novoselov).
|
80
|
-
|
81
|
-
== Release 1.0.1: August 30, 2006
|
82
|
-
|
83
|
-
* Fixed a regex for parsing the 'ps ax' system call. (thanks to Garance Alistair Drosehn)
|
84
|
-
|
85
|
-
== Release 1.0.0: August 29, 2006
|
86
|
-
|
87
|
-
* Fix the parsing of the 'ps ax' system call. (thanks to Garance Alistair Drosehn)
|
88
|
-
|
89
|
-
== Release 0.4.4: February 14, 2006
|
90
|
-
|
91
|
-
* Several fixes that allow us to use the Daemons::Controller
|
92
|
-
with a proc instead of wrapping a script file. This gives us all the
|
93
|
-
PID file management, monitoring, command line options, etc. without having
|
94
|
-
to specify a path to our script which can be tricky, especially when using
|
95
|
-
RubyGems. (thanks to John-Mason Shackelford)
|
96
|
-
|
97
|
-
== Release 0.4.3: November 29, 2005
|
98
|
-
|
99
|
-
* New Option: You can specify the name of the application with :app_name
|
100
|
-
on calling Daemons.run. This will be used to contruct the name of the pid files
|
101
|
-
and log files. Defaults to the basename of the script. (thanks to Stephen R. Veit)
|
102
|
-
|
103
|
-
* Bugfix: Handle the case where no controller options are given when calling Daemons,
|
104
|
-
just options after "--". (thanks to Stephen R. Veit)
|
105
|
-
|
106
|
-
|
107
|
-
== Release 0.4.2: November 15, 2005
|
108
|
-
|
109
|
-
* Bugfix for problem with :normal pid-file directory mode (pid.rb), fixed (thanks to Stephen R. Veit)
|
110
|
-
|
111
|
-
|
112
|
-
== Release 0.4.1: September 11, 2005
|
113
|
-
|
114
|
-
* Bugfix for 'run' command line mode: didn't work anymore in 0.4.0, fixed
|
115
|
-
|
116
|
-
|
117
|
-
== Release 0.4.0: July 30, 2005
|
118
|
-
|
119
|
-
* Two completely new operation modes:
|
120
|
-
1. Call a block as a daemon (<tt>Daemons.call { my_daemon_code }</tt>)
|
121
|
-
and control it from the parent process.
|
122
|
-
2. Daemonize the currently running process (<tt>Daemons.daemonize</tt>)
|
123
|
-
plus the already existing mode to control your scripts (<tt>Daemons.run("script.rb")</tt>)
|
124
|
-
* Improved documentation (for example "How does the daemonization process work?")
|
125
|
-
* Improved "simulation mode" (<tt>:ontop</tt> option)
|
126
|
-
* Some minor bugfixes
|
127
|
-
|
128
|
-
|
129
|
-
== Release 0.3.0: April 21, 2005
|
130
|
-
|
131
|
-
* New monitor functionality: automatic restarting of your applications if they crash
|
132
|
-
* 'restart' command fixed
|
133
|
-
* '--force' command modifier (please refer to the documentation)
|
134
|
-
* Some more bugfixes and improvements
|
135
|
-
|
136
|
-
|
137
|
-
== Release 0.2.1: Mar 21, 2005
|
138
|
-
|
139
|
-
* Bugfix for a problem with the 'status' command
|
140
|
-
|
141
|
-
|
142
|
-
== Release 0.2.0: Mar 21, 2005
|
143
|
-
|
144
|
-
* Exception backtrace functionality added
|
145
|
-
* Exec functionality added
|
146
|
-
* More examples added
|
147
|
-
* New commands: status, zap
|
148
|
-
|
149
|
-
|
150
|
-
== Release 0.0.1: Feb 8, 2005
|
151
|
-
|
152
|
-
* Initial release
|
data/vendor/daemons-1.1.0/TODO
DELETED
@@ -1,288 +0,0 @@
|
|
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
|
-
require 'timeout'
|
16
|
-
|
17
|
-
# All functions and classes that Daemons provides reside in this module.
|
18
|
-
#
|
19
|
-
# Daemons is normally invoked by one of the following four ways:
|
20
|
-
#
|
21
|
-
# 1. <tt>Daemons.run(script, options)</tt>:
|
22
|
-
# This is used in wrapper-scripts that are supposed to control other ruby scripts or
|
23
|
-
# external applications. Control is completely passed to the daemons library.
|
24
|
-
# Such wrapper script need to be invoked with command line options like 'start' or 'stop'
|
25
|
-
# to do anything useful.
|
26
|
-
#
|
27
|
-
# 2. <tt>Daemons.run_proc(app_name, options) { (...) }</tt>:
|
28
|
-
# This is used in wrapper-scripts that are supposed to control a proc.
|
29
|
-
# Control is completely passed to the daemons library.
|
30
|
-
# Such wrapper script need to be invoked with command line options like 'start' or 'stop'
|
31
|
-
# to do anything useful.
|
32
|
-
#
|
33
|
-
# 3. <tt>Daemons.call(options) { block }</tt>:
|
34
|
-
# Execute the block in a new daemon. <tt>Daemons.call</tt> will return immediately
|
35
|
-
# after spawning the daemon with the new Application object as a return value.
|
36
|
-
#
|
37
|
-
# 4. <tt>Daemons.daemonize(options)</tt>:
|
38
|
-
# Daemonize the currently runnig process, i.e. the calling process will become a daemon.
|
39
|
-
#
|
40
|
-
# == What does daemons internally do with my daemons?
|
41
|
-
# *or*:: why do my daemons crash when they try to open a file?
|
42
|
-
# *or*:: why can I not see any output from the daemon on the console (when using for example +puts+)?
|
43
|
-
#
|
44
|
-
# From a technical aspect of view, daemons does the following when creating a daemon:
|
45
|
-
#
|
46
|
-
# 1. Forks a child (and exits the parent process, if needed)
|
47
|
-
# 2. Becomes a session leader (which detaches the program from
|
48
|
-
# the controlling terminal).
|
49
|
-
# 3. Forks another child process and exits first child. This prevents
|
50
|
-
# the potential of acquiring a controlling terminal.
|
51
|
-
# 4. Changes the current working directory to "/".
|
52
|
-
# 5. Clears the file creation mask (sets +umask+ to 0000).
|
53
|
-
# 6. Closes file descriptors (reopens +STDOUT+ and +STDERR+ to point to a logfile if
|
54
|
-
# possible).
|
55
|
-
#
|
56
|
-
# So what does this mean for your daemons:
|
57
|
-
# - the current directory is '/'
|
58
|
-
# - you cannot receive any input from the console (for example no +gets+)
|
59
|
-
# - you cannot output anything from the daemons with +puts+/+print+ unless a logfile is used
|
60
|
-
#
|
61
|
-
# == How do PidFiles work? Where are they stored?
|
62
|
-
#
|
63
|
-
# Also, you are maybe interested in reading the documentation for the class PidFile.
|
64
|
-
# There you can find out about how Daemons works internally and how and where the so
|
65
|
-
# called <i>PidFiles</i> are stored.
|
66
|
-
#
|
67
|
-
module Daemons
|
68
|
-
|
69
|
-
VERSION = "1.1.0"
|
70
|
-
|
71
|
-
require 'daemons/daemonize'
|
72
|
-
|
73
|
-
|
74
|
-
# Passes control to Daemons.
|
75
|
-
# This is used in wrapper-scripts that are supposed to control other ruby scripts or
|
76
|
-
# external applications. Control is completely passed to the daemons library.
|
77
|
-
# Such wrapper script should be invoked with command line options like 'start' or 'stop'
|
78
|
-
# to do anything useful.
|
79
|
-
#
|
80
|
-
# +script+:: This is the path to the script that should be run as a daemon.
|
81
|
-
# Please note that Daemons runs this script with <tt>load <script></tt>.
|
82
|
-
# Also note that Daemons cannot detect the directory in which the controlling
|
83
|
-
# script resides, so this has to be either an absolute path or you have to run
|
84
|
-
# the controlling script from the appropriate directory.
|
85
|
-
#
|
86
|
-
# +options+:: A hash that may contain one or more of the options listed below
|
87
|
-
#
|
88
|
-
# === Options:
|
89
|
-
# <tt>:app_name</tt>:: The name of the application. This will be
|
90
|
-
# used to contruct the name of the pid files
|
91
|
-
# and log files. Defaults to the basename of
|
92
|
-
# the script.
|
93
|
-
# <tt>:ARGV</tt>:: An array of strings containing parameters and switches for Daemons.
|
94
|
-
# This includes both parameters for Daemons itself and the controlled scripted.
|
95
|
-
# These are assumed to be separated by an array element '--', .e.g.
|
96
|
-
# ['start', 'f', '--', 'param1_for_script', 'param2_for_script'].
|
97
|
-
# If not given, ARGV (the parameters given to the Ruby process) will be used.
|
98
|
-
# <tt>:dir_mode</tt>:: Either <tt>:script</tt> (the directory for writing the pid files to
|
99
|
-
# given by <tt>:dir</tt> is interpreted relative
|
100
|
-
# to the script location given by +script+) or <tt>:normal</tt> (the directory given by
|
101
|
-
# <tt>:dir</tt> is interpreted as a (absolute or relative) path) or <tt>:system</tt>
|
102
|
-
# (<tt>/var/run</tt> is used as the pid file directory)
|
103
|
-
#
|
104
|
-
# <tt>:dir</tt>:: Used in combination with <tt>:dir_mode</tt> (description above)
|
105
|
-
# <tt>:multiple</tt>:: Specifies whether multiple instances of the same script are allowed to run at the
|
106
|
-
# same time
|
107
|
-
# <tt>:ontop</tt>:: When given (i.e. set to true), stay on top, i.e. do not daemonize the application
|
108
|
-
# (but the pid-file and other things are written as usual)
|
109
|
-
# <tt>:mode</tt>:: <tt>:load</tt> Load the script with <tt>Kernel.load</tt>;
|
110
|
-
# note that :stop_proc only works for the :load (and :proc) mode.
|
111
|
-
# <tt>:exec</tt> Execute the script file with <tt>Kernel.exec</tt>
|
112
|
-
# <tt>:backtrace</tt>:: Write a backtrace of the last exceptions to the file '[app_name].log' in the
|
113
|
-
# pid-file directory if the application exits due to an uncaught exception
|
114
|
-
# <tt>:monitor</tt>:: Monitor the programs and restart crashed instances
|
115
|
-
# <tt>:log_output</tt>:: When given (i.e. set to true), redirect both STDOUT and STDERR to a logfile named '[app_name].output' in the pid-file directory
|
116
|
-
# <tt>:keep_pid_files</tt>:: When given do not delete lingering pid-files (files for which the process is no longer running).
|
117
|
-
# <tt>:hard_exit</tt>:: When given use exit! to end a daemons instead of exit (this will for example
|
118
|
-
# not call at_exit handlers).
|
119
|
-
# <tt>:stop_proc</tt>:: A proc that will be called when the daemonized process receives a request to stop (works only for :load and :proc mode)
|
120
|
-
#
|
121
|
-
# -----
|
122
|
-
#
|
123
|
-
# === Example:
|
124
|
-
# options = {
|
125
|
-
# :app_name => "my_app",
|
126
|
-
# :ARGV => ['start', '-f', '--', 'param_for_myscript']
|
127
|
-
# :dir_mode => :script,
|
128
|
-
# :dir => 'pids',
|
129
|
-
# :multiple => true,
|
130
|
-
# :ontop => true,
|
131
|
-
# :mode => :exec,
|
132
|
-
# :backtrace => true,
|
133
|
-
# :monitor => true
|
134
|
-
# }
|
135
|
-
#
|
136
|
-
# Daemons.run(File.join(File.dirname(__FILE__), 'myscript.rb'), options)
|
137
|
-
#
|
138
|
-
def run(script, options = {})
|
139
|
-
options[:script] = script
|
140
|
-
@controller = Controller.new(options, options[:ARGV] || ARGV)
|
141
|
-
|
142
|
-
@controller.catch_exceptions {
|
143
|
-
@controller.run
|
144
|
-
}
|
145
|
-
|
146
|
-
# I don't think anybody will ever use @group, as this location should not be reached under non-error conditions
|
147
|
-
@group = @controller.group
|
148
|
-
end
|
149
|
-
module_function :run
|
150
|
-
|
151
|
-
|
152
|
-
# Passes control to Daemons.
|
153
|
-
# This function does the same as Daemons.run except that not a script but a proc
|
154
|
-
# will be run as a daemon while this script provides command line options like 'start' or 'stop'
|
155
|
-
# and the whole pid-file management to control the proc.
|
156
|
-
#
|
157
|
-
# +app_name+:: The name of the application. This will be
|
158
|
-
# used to contruct the name of the pid files
|
159
|
-
# and log files. Defaults to the basename of
|
160
|
-
# the script.
|
161
|
-
#
|
162
|
-
# +options+:: A hash that may contain one or more of the options listed in the documentation for Daemons.run
|
163
|
-
#
|
164
|
-
# A block must be given to this function. The block will be used as the :proc entry in the options hash.
|
165
|
-
#
|
166
|
-
# -----
|
167
|
-
#
|
168
|
-
# === Example:
|
169
|
-
#
|
170
|
-
# Daemons.run_proc('myproc.rb') do
|
171
|
-
# loop do
|
172
|
-
# accept_connection()
|
173
|
-
# read_request()
|
174
|
-
# send_response()
|
175
|
-
# close_connection()
|
176
|
-
# end
|
177
|
-
# end
|
178
|
-
#
|
179
|
-
def run_proc(app_name, options = {}, &block)
|
180
|
-
options[:app_name] = app_name
|
181
|
-
options[:mode] = :proc
|
182
|
-
options[:proc] = block
|
183
|
-
|
184
|
-
# we do not have a script location so the the :script :dir_mode cannot be used, change it to :normal
|
185
|
-
if [nil, :script].include? options[:dir_mode]
|
186
|
-
options[:dir_mode] = :normal
|
187
|
-
options[:dir] = File.expand_path('.')
|
188
|
-
end
|
189
|
-
|
190
|
-
@controller = Controller.new(options, options[:ARGV] || ARGV)
|
191
|
-
|
192
|
-
@controller.catch_exceptions {
|
193
|
-
@controller.run
|
194
|
-
}
|
195
|
-
|
196
|
-
# I don't think anybody will ever use @group, as this location should not be reached under non-error conditions
|
197
|
-
@group = @controller.group
|
198
|
-
end
|
199
|
-
module_function :run_proc
|
200
|
-
|
201
|
-
|
202
|
-
# Execute the block in a new daemon. <tt>Daemons.call</tt> will return immediately
|
203
|
-
# after spawning the daemon with the new Application object as a return value.
|
204
|
-
#
|
205
|
-
# +options+:: A hash that may contain one or more of the options listed below
|
206
|
-
#
|
207
|
-
# +block+:: The block to call in the daemon.
|
208
|
-
#
|
209
|
-
# === Options:
|
210
|
-
# <tt>:multiple</tt>:: Specifies whether multiple instances of the same script are allowed to run at the
|
211
|
-
# same time
|
212
|
-
# <tt>:ontop</tt>:: When given, stay on top, i.e. do not daemonize the application
|
213
|
-
# <tt>:backtrace</tt>:: Write a backtrace of the last exceptions to the file '[app_name].log' in the
|
214
|
-
# pid-file directory if the application exits due to an uncaught exception
|
215
|
-
# -----
|
216
|
-
#
|
217
|
-
# === Example:
|
218
|
-
# options = {
|
219
|
-
# :backtrace => true,
|
220
|
-
# :monitor => true,
|
221
|
-
# :ontop => true
|
222
|
-
# }
|
223
|
-
#
|
224
|
-
# Daemons.call(options) begin
|
225
|
-
# # Server loop:
|
226
|
-
# loop {
|
227
|
-
# conn = accept_conn()
|
228
|
-
# serve(conn)
|
229
|
-
# }
|
230
|
-
# end
|
231
|
-
#
|
232
|
-
def call(options = {}, &block)
|
233
|
-
unless block_given?
|
234
|
-
raise "Daemons.call: no block given"
|
235
|
-
end
|
236
|
-
|
237
|
-
options[:proc] = block
|
238
|
-
options[:mode] = :proc
|
239
|
-
|
240
|
-
@group ||= ApplicationGroup.new('proc', options)
|
241
|
-
|
242
|
-
new_app = @group.new_application(options)
|
243
|
-
new_app.start
|
244
|
-
|
245
|
-
return new_app
|
246
|
-
end
|
247
|
-
module_function :call
|
248
|
-
|
249
|
-
|
250
|
-
# Daemonize the currently runnig process, i.e. the calling process will become a daemon.
|
251
|
-
#
|
252
|
-
# +options+:: A hash that may contain one or more of the options listed below
|
253
|
-
#
|
254
|
-
# === Options:
|
255
|
-
# <tt>:ontop</tt>:: When given, stay on top, i.e. do not daemonize the application
|
256
|
-
# <tt>:backtrace</tt>:: Write a backtrace of the last exceptions to the file '[app_name].log' in the
|
257
|
-
# pid-file directory if the application exits due to an uncaught exception
|
258
|
-
# -----
|
259
|
-
#
|
260
|
-
# === Example:
|
261
|
-
# options = {
|
262
|
-
# :backtrace => true,
|
263
|
-
# :ontop => true
|
264
|
-
# }
|
265
|
-
#
|
266
|
-
# Daemons.daemonize(options)
|
267
|
-
#
|
268
|
-
# # Server loop:
|
269
|
-
# loop {
|
270
|
-
# conn = accept_conn()
|
271
|
-
# serve(conn)
|
272
|
-
# }
|
273
|
-
#
|
274
|
-
def daemonize(options = {})
|
275
|
-
@group ||= ApplicationGroup.new(options[:app_name] || 'self', options)
|
276
|
-
|
277
|
-
@group.new_application(:mode => :none).start
|
278
|
-
end
|
279
|
-
module_function :daemonize
|
280
|
-
|
281
|
-
# Return the internal ApplicationGroup instance.
|
282
|
-
def group; @group; end
|
283
|
-
module_function :group
|
284
|
-
|
285
|
-
# Return the internal Controller instance.
|
286
|
-
def controller; @controller; end
|
287
|
-
module_function :controller
|
288
|
-
end
|