daemons 1.1.9 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +207 -0
- data/Releases +85 -24
- data/examples/call/call.rb +13 -16
- data/examples/call/call_monitor.rb +13 -17
- data/examples/daemonize/daemonize.rb +4 -8
- data/examples/run/ctrl_crash.rb +0 -1
- data/examples/run/ctrl_custom_logfiles.rb +18 -0
- data/examples/run/ctrl_exec.rb +0 -1
- data/examples/run/ctrl_exit.rb +0 -1
- data/examples/run/ctrl_keep_pid_files.rb +1 -3
- data/examples/run/ctrl_monitor.rb +0 -1
- data/examples/run/ctrl_monitor_multiple.rb +17 -0
- data/examples/run/ctrl_monitor_nocrash.rb +15 -0
- data/examples/run/ctrl_multiple.rb +0 -1
- data/examples/run/ctrl_ontop.rb +0 -1
- data/examples/run/ctrl_optionparser.rb +5 -7
- data/examples/run/ctrl_proc.rb +8 -9
- data/examples/run/ctrl_proc_multiple.rb +4 -6
- data/examples/run/ctrl_proc_rand.rb +2 -4
- data/examples/run/ctrl_proc_simple.rb +0 -1
- data/examples/run/myserver.rb +0 -1
- data/examples/run/myserver_crashing.rb +5 -5
- data/examples/run/myserver_exiting.rb +2 -2
- data/examples/run/myserver_hanging.rb +4 -5
- data/examples/run/myserver_slowstop.rb +5 -6
- data/lib/daemons/application.rb +235 -229
- data/lib/daemons/application_group.rb +115 -100
- data/lib/daemons/change_privilege.rb +2 -4
- data/lib/daemons/cmdline.rb +75 -62
- data/lib/daemons/controller.rb +36 -54
- data/lib/daemons/daemonize.rb +74 -75
- data/lib/daemons/etc_extension.rb +3 -4
- data/lib/daemons/exceptions.rb +11 -13
- data/lib/daemons/monitor.rb +57 -77
- data/lib/daemons/pid.rb +26 -56
- data/lib/daemons/pidfile.rb +49 -44
- data/lib/daemons/pidmem.rb +5 -9
- data/lib/daemons/reporter.rb +54 -0
- data/lib/daemons/syslogio.rb +240 -0
- data/lib/daemons/version.rb +3 -0
- data/lib/daemons.rb +87 -77
- metadata +111 -46
- data/README +0 -214
- data/Rakefile +0 -90
- data/TODO +0 -2
- data/setup.rb +0 -1360
data/README
DELETED
@@ -1,214 +0,0 @@
|
|
1
|
-
= Daemons Version 1.1.9
|
2
|
-
|
3
|
-
(See Releases for release-specific information)
|
4
|
-
|
5
|
-
== What is Daemons?
|
6
|
-
|
7
|
-
Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
|
8
|
-
to be <i>run as a daemon</i> and to be <i>controlled by simple start/stop/restart commands</i>.
|
9
|
-
|
10
|
-
If you want, you can also use daemons to <i>run blocks of ruby code in a daemon process</i> and to control
|
11
|
-
these processes from the main application.
|
12
|
-
|
13
|
-
Besides this basic functionality, daemons offers many advanced features like <i>exception backtracing</i>
|
14
|
-
and logging (in case your ruby script crashes) and <i>monitoring</i> and automatic restarting of your processes
|
15
|
-
if they crash.
|
16
|
-
|
17
|
-
== Basic Usage
|
18
|
-
|
19
|
-
You can use Daemons in four different ways:
|
20
|
-
|
21
|
-
=== 1. Create wrapper scripts for your server scripts or applications
|
22
|
-
|
23
|
-
Layout: suppose you have your self-written server <tt>myserver.rb</tt>:
|
24
|
-
|
25
|
-
# this is myserver.rb
|
26
|
-
# it does nothing really useful at the moment
|
27
|
-
|
28
|
-
loop do
|
29
|
-
sleep(5)
|
30
|
-
end
|
31
|
-
|
32
|
-
To use <tt>myserver.rb</tt> in a production environment, you need to be able to
|
33
|
-
run <tt>myserver.rb</tt> in the _background_ (this means detach it from the console, fork it
|
34
|
-
in the background, release all directories and file descriptors).
|
35
|
-
|
36
|
-
Just create <tt>myserver_control.rb</tt> like this:
|
37
|
-
|
38
|
-
# this is myserver_control.rb
|
39
|
-
|
40
|
-
require 'rubygems' # if you use RubyGems
|
41
|
-
require 'daemons'
|
42
|
-
|
43
|
-
Daemons.run('myserver.rb')
|
44
|
-
|
45
|
-
And use it like this from the console:
|
46
|
-
|
47
|
-
$ ruby myserver_control.rb start
|
48
|
-
(myserver.rb is now running in the background)
|
49
|
-
$ ruby myserver_control.rb restart
|
50
|
-
(...)
|
51
|
-
$ ruby myserver_control.rb stop
|
52
|
-
|
53
|
-
For testing purposes you can even run <tt>myserver.rb</tt> <i>without forking</i> in the background:
|
54
|
-
|
55
|
-
$ ruby myserver_control.rb run
|
56
|
-
|
57
|
-
An additional nice feature of Daemons is that you can pass <i>additional arguments</i> to the script that
|
58
|
-
should be daemonized by seperating them by two _hyphens_:
|
59
|
-
|
60
|
-
$ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
|
61
|
-
|
62
|
-
|
63
|
-
=== 2. Create wrapper scripts that include your server procs
|
64
|
-
|
65
|
-
Layout: suppose you have some code you want to run in the background and control that background process
|
66
|
-
from a script:
|
67
|
-
|
68
|
-
# this is your code
|
69
|
-
# it does nothing really useful at the moment
|
70
|
-
|
71
|
-
loop do
|
72
|
-
sleep(5)
|
73
|
-
end
|
74
|
-
|
75
|
-
To run this code as a daemon create <tt>myproc_control.rb</tt> like this and include your code:
|
76
|
-
|
77
|
-
# this is myproc_control.rb
|
78
|
-
|
79
|
-
require 'rubygems' # if you use RubyGems
|
80
|
-
require 'daemons'
|
81
|
-
|
82
|
-
Daemons.run_proc('myproc.rb') do
|
83
|
-
loop do
|
84
|
-
sleep(5)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
And use it like this from the console:
|
89
|
-
|
90
|
-
$ ruby myproc_control.rb start
|
91
|
-
(myproc.rb is now running in the background)
|
92
|
-
$ ruby myproc_control.rb restart
|
93
|
-
(...)
|
94
|
-
$ ruby myproc_control.rb stop
|
95
|
-
|
96
|
-
For testing purposes you can even run <tt>myproc.rb</tt> <i>without forking</i> in the background:
|
97
|
-
|
98
|
-
$ ruby myproc_control.rb run
|
99
|
-
|
100
|
-
=== 3. Control a bunch of daemons from another application
|
101
|
-
|
102
|
-
Layout: you have an application <tt>my_app.rb</tt> that wants to run a bunch of
|
103
|
-
server tasks as daemon processes.
|
104
|
-
|
105
|
-
# this is my_app.rb
|
106
|
-
|
107
|
-
require 'rubygems' # if you use RubyGems
|
108
|
-
require 'daemons'
|
109
|
-
|
110
|
-
task1 = Daemons.call(:multiple => true) do
|
111
|
-
# first server task
|
112
|
-
|
113
|
-
loop {
|
114
|
-
conn = accept_conn()
|
115
|
-
serve(conn)
|
116
|
-
}
|
117
|
-
end
|
118
|
-
|
119
|
-
task2 = Daemons.call do
|
120
|
-
# second server task
|
121
|
-
|
122
|
-
loop {
|
123
|
-
something_different()
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
127
|
-
# the parent process continues to run
|
128
|
-
|
129
|
-
# we can even control our tasks, for example stop them
|
130
|
-
task1.stop
|
131
|
-
task2.stop
|
132
|
-
|
133
|
-
exit
|
134
|
-
|
135
|
-
=== 4. Daemonize the currently running process
|
136
|
-
|
137
|
-
Layout: you have an application <tt>my_daemon.rb</tt> that wants to run as a daemon
|
138
|
-
(but without the ability to be controlled by daemons via start/stop commands)
|
139
|
-
|
140
|
-
# this is my_daemons.rb
|
141
|
-
|
142
|
-
require 'rubygems' # if you use RubyGems
|
143
|
-
require 'daemons'
|
144
|
-
|
145
|
-
# Initialize the app while we're not a daemon
|
146
|
-
init()
|
147
|
-
|
148
|
-
# Become a daemon
|
149
|
-
Daemons.daemonize
|
150
|
-
|
151
|
-
# The server loop
|
152
|
-
loop {
|
153
|
-
conn = accept_conn()
|
154
|
-
serve(conn)
|
155
|
-
}
|
156
|
-
|
157
|
-
|
158
|
-
<b>For further documentation, refer to the module documentation of Daemons.</b>
|
159
|
-
|
160
|
-
|
161
|
-
== Download and Installation
|
162
|
-
|
163
|
-
*Download*: just go to http://rubyforge.org/projects/daemons/
|
164
|
-
|
165
|
-
Installation *with* RubyGems:
|
166
|
-
$ su
|
167
|
-
# gem install daemons
|
168
|
-
|
169
|
-
Installation *without* RubyGems:
|
170
|
-
$ tar xfz daemons-x.x.x.tar.gz
|
171
|
-
$ cd daemons-x.x.x
|
172
|
-
$ su
|
173
|
-
# ruby setup.rb
|
174
|
-
|
175
|
-
== Documentation
|
176
|
-
|
177
|
-
For further documentation, refer to the module documentation of Daemons (click on Daemons).
|
178
|
-
|
179
|
-
The RDoc documentation is also online at http://daemons.rubyforge.org
|
180
|
-
|
181
|
-
|
182
|
-
== Author
|
183
|
-
|
184
|
-
Written 2005-2010 by Thomas Uehlinger <mailto:th.uehlinger@gmx.ch>.
|
185
|
-
Anonymous SVN checkout is available with "svn checkout http://daemons.rubyforge.org/svn/".
|
186
|
-
|
187
|
-
== License
|
188
|
-
|
189
|
-
Copyright (c) 2005-2012 Thomas Uehlinger
|
190
|
-
|
191
|
-
Permission is hereby granted, free of charge, to any person
|
192
|
-
obtaining a copy of this software and associated documentation
|
193
|
-
files (the "Software"), to deal in the Software without
|
194
|
-
restriction, including without limitation the rights to use,
|
195
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
196
|
-
copies of the Software, and to permit persons to whom the
|
197
|
-
Software is furnished to do so, subject to the following
|
198
|
-
conditions:
|
199
|
-
|
200
|
-
The above copyright notice and this permission notice shall be
|
201
|
-
included in all copies or substantial portions of the Software.
|
202
|
-
|
203
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
204
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
205
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
206
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
207
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
208
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
209
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
210
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
211
|
-
|
212
|
-
== Feedback and other resources
|
213
|
-
|
214
|
-
At http://rubyforge.org/projects/daemons.
|
data/Rakefile
DELETED
@@ -1,90 +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/**/*.rb"
|
21
|
-
]
|
22
|
-
#PKG_FILES.exclude(%r(^test/tmp/.+))
|
23
|
-
PKG_FILES.exclude(%r(\.pid$))
|
24
|
-
PKG_FILES.exclude(%r(\.log$))
|
25
|
-
PKG_FILES.exclude(%r(\.output$))
|
26
|
-
PKG_FILES.exclude(%r(\.txt$))
|
27
|
-
|
28
|
-
spec = Gem::Specification.new do |s|
|
29
|
-
s.name = PKG_NAME
|
30
|
-
s.version = Daemons::VERSION
|
31
|
-
s.author = "Thomas Uehlinger"
|
32
|
-
s.email = "th.uehlinger@gmx.ch"
|
33
|
-
s.rubyforge_project = "daemons"
|
34
|
-
s.homepage = "http://daemons.rubyforge.org"
|
35
|
-
s.platform = Gem::Platform::RUBY
|
36
|
-
s.summary = "A toolkit to create and control daemons in different ways"
|
37
|
-
s.description = <<-EOF
|
38
|
-
Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
|
39
|
-
to be run as a daemon and to be controlled by simple start/stop/restart commands.
|
40
|
-
|
41
|
-
You can also call blocks as daemons and control them from the parent or just daemonize the current
|
42
|
-
process.
|
43
|
-
|
44
|
-
Besides this basic functionality, daemons offers many advanced features like exception
|
45
|
-
backtracing and logging (in case your ruby script crashes) and monitoring and automatic
|
46
|
-
restarting of your processes if they crash.
|
47
|
-
EOF
|
48
|
-
|
49
|
-
#s.files = FileList["{test,lib}/**/*"].exclude("rdoc").to_a
|
50
|
-
s.files = PKG_FILES
|
51
|
-
s.require_path = "lib"
|
52
|
-
s.autorequire = "daemons"
|
53
|
-
s.has_rdoc = true
|
54
|
-
s.extra_rdoc_files = ["README", "Releases", "TODO"]
|
55
|
-
end
|
56
|
-
|
57
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
58
|
-
pkg.need_tar = true
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
#Rake::PackageTask.new("package") do |p|
|
63
|
-
# p.name = PKG_NAME
|
64
|
-
# p.version = Daemons::VERSION
|
65
|
-
# p.need_tar = true
|
66
|
-
# p.need_zip = true
|
67
|
-
# p.package_files = PKG_FILES
|
68
|
-
#end
|
69
|
-
|
70
|
-
|
71
|
-
task :default => [:package]
|
72
|
-
|
73
|
-
desc 'Show information about the gem.'
|
74
|
-
task :debug_gem do
|
75
|
-
puts spec.to_ruby
|
76
|
-
end
|
77
|
-
|
78
|
-
task :upload do
|
79
|
-
sh "scp -r html/* uehli@rubyforge.org:/var/www/gforge-projects/daemons"
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
desc "Create the RDOC html files"
|
84
|
-
rd = Rake::RDocTask.new("rdoc") { |rdoc|
|
85
|
-
rdoc.rdoc_dir = 'html'
|
86
|
-
rdoc.title = "Daemons"
|
87
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
|
88
|
-
rdoc.rdoc_files.include('README', 'TODO', 'Releases')
|
89
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
90
|
-
}
|