mlanett-daemons 1.0.13 → 1.1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +12 -2
- data/LICENSE +1 -8
- data/README-mlanett.rdoc +8 -0
- data/{README → README.rdoc} +6 -15
- data/Releases +84 -9
- data/TODO +1 -5
- data/daemons.gemspec +1 -0
- data/examples/call/call.rb +1 -0
- data/examples/daemonize/daemonize.rb +10 -3
- data/examples/run/ctrl_hanging.rb +19 -0
- data/examples/run/ctrl_monitor_multiple.rb +18 -0
- data/examples/run/ctrl_normal.rb +0 -1
- data/examples/run/ctrl_proc.rb.output +20 -0
- data/examples/run/ctrl_proc_rand.rb +23 -0
- data/examples/run/ctrl_slowstop.rb +16 -0
- data/examples/run/myserver_crashing.rb +2 -2
- data/examples/run/myserver_hanging.rb +21 -0
- data/examples/run/myserver_slowstop.rb +21 -0
- data/lib/daemons.rb +38 -10
- data/lib/daemons/application.rb +131 -26
- data/lib/daemons/application_group.rb +58 -10
- data/lib/daemons/change_privilege.rb +19 -0
- data/lib/daemons/cmdline.rb +10 -6
- data/lib/daemons/controller.rb +5 -2
- data/lib/daemons/daemonize.rb +64 -150
- data/lib/daemons/etc_extension.rb +12 -0
- data/lib/daemons/exceptions.rb +3 -0
- data/lib/daemons/monitor.rb +27 -19
- data/lib/daemons/pid.rb +13 -14
- data/lib/daemons/pidfile.rb +14 -7
- data/lib/daemons/pidmem.rb +9 -0
- data/lib/daemons/version.rb +1 -1
- data/spec/pidfile_spec.rb +12 -0
- data/spec/spec_helper.rb +1 -0
- metadata +31 -47
- data/daemons.tmproj +0 -56
- data/examples/run/myserver_crashing.rb.output +0 -30
- data/html/classes/Daemonize.html +0 -497
- data/html/classes/Daemons.html +0 -683
- data/html/classes/Daemons/Application.html +0 -836
- data/html/classes/Daemons/ApplicationGroup.html +0 -508
- data/html/classes/Daemons/CmdException.html +0 -113
- data/html/classes/Daemons/Controller.html +0 -429
- data/html/classes/Daemons/Error.html +0 -113
- data/html/classes/Daemons/Exception.html +0 -111
- data/html/classes/Daemons/Monitor.html +0 -263
- data/html/classes/Daemons/Optparse.html +0 -244
- data/html/classes/Daemons/Pid.html +0 -339
- data/html/classes/Daemons/PidFile.html +0 -441
- data/html/classes/Daemons/PidMem.html +0 -126
- data/html/classes/Daemons/RuntimeException.html +0 -113
- data/html/classes/Daemons/SystemError.html +0 -163
- data/html/created.rid +0 -1
- data/html/files/README.html +0 -377
- data/html/files/Releases.html +0 -342
- data/html/files/TODO.html +0 -121
- data/html/files/lib/daemons/application_group_rb.html +0 -101
- data/html/files/lib/daemons/application_rb.html +0 -110
- data/html/files/lib/daemons/cmdline_rb.html +0 -101
- data/html/files/lib/daemons/controller_rb.html +0 -101
- data/html/files/lib/daemons/daemonize_rb.html +0 -207
- data/html/files/lib/daemons/exceptions_rb.html +0 -101
- data/html/files/lib/daemons/monitor_rb.html +0 -108
- data/html/files/lib/daemons/pid_rb.html +0 -108
- data/html/files/lib/daemons/pidfile_rb.html +0 -108
- data/html/files/lib/daemons/pidmem_rb.html +0 -108
- data/html/files/lib/daemons_rb.html +0 -117
- data/html/fr_class_index.html +0 -41
- data/html/fr_file_index.html +0 -40
- data/html/fr_method_index.html +0 -91
- data/html/index.html +0 -24
- data/html/rdoc-style.css +0 -208
- data/test/call_as_daemon.rb +0 -12
- data/test/tc_main.rb +0 -24
- data/test/test1.rb +0 -19
- data/test/testapp.rb +0 -11
data/lib/daemons/exceptions.rb
CHANGED
data/lib/daemons/monitor.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'daemons/exceptions'
|
2
|
+
|
1
3
|
|
2
4
|
module Daemons
|
3
5
|
|
@@ -38,29 +40,33 @@ module Daemons
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
def watch(
|
42
|
-
sleep(
|
43
|
+
def watch(application_group)
|
44
|
+
sleep(5)
|
43
45
|
|
44
46
|
loop do
|
45
|
-
applications.each {|a|
|
46
|
-
sleep(10)
|
47
|
-
|
47
|
+
application_group.applications.each {|a|
|
48
48
|
unless a.running?
|
49
49
|
a.zap!
|
50
50
|
|
51
|
-
|
51
|
+
sleep(1)
|
52
|
+
|
53
|
+
Process.detach(fork { a.start(restart=true) })
|
54
|
+
|
55
|
+
sleep(5)
|
52
56
|
|
53
|
-
|
57
|
+
#application_group.setup
|
54
58
|
end
|
55
59
|
}
|
56
60
|
|
57
|
-
sleep(
|
61
|
+
#sleep(5)
|
62
|
+
#application_group.setup
|
63
|
+
#sleep(30)
|
58
64
|
end
|
59
65
|
end
|
60
66
|
private :watch
|
61
67
|
|
62
68
|
|
63
|
-
def start_with_pidfile(
|
69
|
+
def start_with_pidfile(application_group)
|
64
70
|
fork do
|
65
71
|
Daemonize.daemonize(nil, @app_name)
|
66
72
|
|
@@ -81,7 +87,7 @@ module Daemons
|
|
81
87
|
# exit
|
82
88
|
# }
|
83
89
|
|
84
|
-
watch(
|
90
|
+
watch(application_group)
|
85
91
|
rescue ::Exception => e
|
86
92
|
begin
|
87
93
|
File.open(@app.logfile, 'a') {|f|
|
@@ -98,19 +104,19 @@ module Daemons
|
|
98
104
|
end
|
99
105
|
private :start_with_pidfile
|
100
106
|
|
101
|
-
def start_without_pidfile(
|
102
|
-
Thread.new { watch(
|
107
|
+
def start_without_pidfile(application_group)
|
108
|
+
Thread.new { watch(application_group) }
|
103
109
|
end
|
104
110
|
private :start_without_pidfile
|
105
111
|
|
106
112
|
|
107
|
-
def start(
|
108
|
-
return if applications.empty?
|
113
|
+
def start(application_group)
|
114
|
+
return if application_group.applications.empty?
|
109
115
|
|
110
116
|
if @pid.kind_of?(PidFile)
|
111
|
-
start_with_pidfile(
|
117
|
+
start_with_pidfile(application_group)
|
112
118
|
else
|
113
|
-
start_without_pidfile(
|
119
|
+
start_without_pidfile(application_group)
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
@@ -119,9 +125,11 @@ module Daemons
|
|
119
125
|
begin
|
120
126
|
pid = @pid.pid
|
121
127
|
Process.kill(Application::SIGNAL, pid)
|
122
|
-
|
123
|
-
|
124
|
-
|
128
|
+
Timeout::timeout(5, TimeoutError) {
|
129
|
+
while Pid.running?(pid)
|
130
|
+
sleep(0.1)
|
131
|
+
end
|
132
|
+
}
|
125
133
|
rescue ::Exception => e
|
126
134
|
puts "#{e} #{pid}"
|
127
135
|
puts "deleting pid-file."
|
data/lib/daemons/pid.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
|
2
|
-
ONE_NINE = RUBY_VERSION >= "1.9"
|
3
|
-
if WINDOWS
|
4
|
-
if ONE_NINE
|
5
|
-
require 'open3'
|
6
|
-
else
|
7
|
-
require 'rubygems'
|
8
|
-
require 'win32/open3'
|
9
|
-
end
|
10
|
-
end
|
1
|
+
require 'daemons/exceptions'
|
11
2
|
|
12
3
|
|
13
4
|
module Daemons
|
@@ -18,8 +9,8 @@ module Daemons
|
|
18
9
|
# We have seen an odd problem where the pid file exists but is empty
|
19
10
|
# In this case we want to not send a kill but we do want to zap the file
|
20
11
|
# Thus while technically pid==0 => this process => running=true, treat it as running=false
|
21
|
-
return false if pid == 0
|
22
|
-
|
12
|
+
return false if ! pid || pid == 0
|
13
|
+
|
23
14
|
# Check if process is in existence
|
24
15
|
# The simplest way to do this is to send signal '0'
|
25
16
|
# (which is a single system call) that doesn't actually
|
@@ -27,6 +18,8 @@ module Daemons
|
|
27
18
|
begin
|
28
19
|
Process.kill(0, pid)
|
29
20
|
return true
|
21
|
+
rescue TimeoutError
|
22
|
+
raise
|
30
23
|
rescue Errno::ESRCH
|
31
24
|
return false
|
32
25
|
rescue ::Exception # for example on EPERM (process exists but does not belong to us)
|
@@ -63,6 +56,7 @@ module Daemons
|
|
63
56
|
# end
|
64
57
|
|
65
58
|
|
59
|
+
|
66
60
|
# Returns the directory that should be used to write the pid file to
|
67
61
|
# depending on the given mode.
|
68
62
|
#
|
@@ -100,11 +94,16 @@ module Daemons
|
|
100
94
|
def pid=(p)
|
101
95
|
end
|
102
96
|
|
97
|
+
# Check whether the process is running
|
98
|
+
def running?
|
99
|
+
return Pid.running?(pid())
|
100
|
+
end
|
101
|
+
|
103
102
|
# Cleanup method
|
104
103
|
def cleanup
|
105
104
|
end
|
106
105
|
|
107
|
-
#
|
106
|
+
# Exist? method
|
108
107
|
def exist?
|
109
108
|
true
|
110
109
|
end
|
@@ -112,4 +111,4 @@ module Daemons
|
|
112
111
|
end
|
113
112
|
|
114
113
|
|
115
|
-
end
|
114
|
+
end
|
data/lib/daemons/pidfile.rb
CHANGED
@@ -34,8 +34,10 @@ module Daemons
|
|
34
34
|
attr_reader :dir, :progname, :multiple, :number
|
35
35
|
|
36
36
|
def PidFile.find_files(dir, progname, delete = false)
|
37
|
-
files = Dir[File.join(dir, "#{progname}*.pid")]
|
38
|
-
|
37
|
+
files = Dir[File.join(dir, "#{progname}*.pid")].select {|f|
|
38
|
+
f =~ /#{progname}\d*\.pid/
|
39
|
+
}
|
40
|
+
|
39
41
|
files.delete_if {|f| not (File.file?(f) and File.readable?(f))}
|
40
42
|
if delete
|
41
43
|
files.delete_if do |f|
|
@@ -76,7 +78,7 @@ module Daemons
|
|
76
78
|
@number += 1
|
77
79
|
end
|
78
80
|
|
79
|
-
if @number
|
81
|
+
if @number >= 1024
|
80
82
|
raise RuntimeException('cannot run more than 1024 instances of the application')
|
81
83
|
end
|
82
84
|
end
|
@@ -92,6 +94,7 @@ module Daemons
|
|
92
94
|
|
93
95
|
def pid=(p)
|
94
96
|
File.open(filename, 'w') {|f|
|
97
|
+
f.chmod(0644)
|
95
98
|
f.puts p #Process.pid
|
96
99
|
}
|
97
100
|
end
|
@@ -101,11 +104,15 @@ module Daemons
|
|
101
104
|
end
|
102
105
|
|
103
106
|
def pid
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
+
begin
|
108
|
+
File.open(filename) {|f|
|
109
|
+
return f.gets.to_i
|
110
|
+
}
|
111
|
+
rescue ::Exception
|
112
|
+
return nil
|
113
|
+
end
|
107
114
|
end
|
108
115
|
|
109
116
|
end
|
110
117
|
|
111
|
-
end
|
118
|
+
end
|
data/lib/daemons/pidmem.rb
CHANGED
data/lib/daemons/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Daemons::PidFile do
|
4
|
+
describe "#find_files" do
|
5
|
+
it 'does not include files with shared prefix' do
|
6
|
+
Dir.stub('[]') { %w{srv.pid srv123.pid srv-other.pid} }
|
7
|
+
File.stub(:readable?) { true }
|
8
|
+
File.stub(:file?) { true }
|
9
|
+
expect(Daemons::PidFile.find_files('/', 'srv')).to eql %w{srv.pid srv123.pid}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'daemons'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mlanett-daemons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.10.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description: Daemons provides an easy way to wrap existing ruby scripts (for example
|
47
63
|
a self-written server) to be run as a daemon and to be controlled by simple start/stop/restart
|
48
64
|
commands. You can also call blocks as daemons and control them from the parent
|
@@ -59,12 +75,12 @@ files:
|
|
59
75
|
- Gemfile
|
60
76
|
- Gemfile.lock
|
61
77
|
- LICENSE
|
62
|
-
- README
|
78
|
+
- README-mlanett.rdoc
|
79
|
+
- README.rdoc
|
63
80
|
- Rakefile
|
64
81
|
- Releases
|
65
82
|
- TODO
|
66
83
|
- daemons.gemspec
|
67
|
-
- daemons.tmproj
|
68
84
|
- examples/call/call.rb
|
69
85
|
- examples/call/call.rb.log
|
70
86
|
- examples/call/call_monitor.rb
|
@@ -72,8 +88,10 @@ files:
|
|
72
88
|
- examples/run/ctrl_crash.rb
|
73
89
|
- examples/run/ctrl_exec.rb
|
74
90
|
- examples/run/ctrl_exit.rb
|
91
|
+
- examples/run/ctrl_hanging.rb
|
75
92
|
- examples/run/ctrl_keep_pid_files.rb
|
76
93
|
- examples/run/ctrl_monitor.rb
|
94
|
+
- examples/run/ctrl_monitor_multiple.rb
|
77
95
|
- examples/run/ctrl_multiple.rb
|
78
96
|
- examples/run/ctrl_normal.rb
|
79
97
|
- examples/run/ctrl_ontop.rb
|
@@ -82,52 +100,22 @@ files:
|
|
82
100
|
- examples/run/ctrl_proc.rb.output
|
83
101
|
- examples/run/ctrl_proc_multiple.rb
|
84
102
|
- examples/run/ctrl_proc_multiple.rb.output
|
103
|
+
- examples/run/ctrl_proc_rand.rb
|
85
104
|
- examples/run/ctrl_proc_simple.rb
|
105
|
+
- examples/run/ctrl_slowstop.rb
|
86
106
|
- examples/run/myserver.rb
|
87
107
|
- examples/run/myserver_crashing.rb
|
88
|
-
- examples/run/myserver_crashing.rb.output
|
89
108
|
- examples/run/myserver_exiting.rb
|
90
|
-
-
|
91
|
-
-
|
92
|
-
- html/classes/Daemons/Application.html
|
93
|
-
- html/classes/Daemons/ApplicationGroup.html
|
94
|
-
- html/classes/Daemons/CmdException.html
|
95
|
-
- html/classes/Daemons/Controller.html
|
96
|
-
- html/classes/Daemons/Error.html
|
97
|
-
- html/classes/Daemons/Exception.html
|
98
|
-
- html/classes/Daemons/Monitor.html
|
99
|
-
- html/classes/Daemons/Optparse.html
|
100
|
-
- html/classes/Daemons/Pid.html
|
101
|
-
- html/classes/Daemons/PidFile.html
|
102
|
-
- html/classes/Daemons/PidMem.html
|
103
|
-
- html/classes/Daemons/RuntimeException.html
|
104
|
-
- html/classes/Daemons/SystemError.html
|
105
|
-
- html/created.rid
|
106
|
-
- html/files/README.html
|
107
|
-
- html/files/Releases.html
|
108
|
-
- html/files/TODO.html
|
109
|
-
- html/files/lib/daemons/application_group_rb.html
|
110
|
-
- html/files/lib/daemons/application_rb.html
|
111
|
-
- html/files/lib/daemons/cmdline_rb.html
|
112
|
-
- html/files/lib/daemons/controller_rb.html
|
113
|
-
- html/files/lib/daemons/daemonize_rb.html
|
114
|
-
- html/files/lib/daemons/exceptions_rb.html
|
115
|
-
- html/files/lib/daemons/monitor_rb.html
|
116
|
-
- html/files/lib/daemons/pid_rb.html
|
117
|
-
- html/files/lib/daemons/pidfile_rb.html
|
118
|
-
- html/files/lib/daemons/pidmem_rb.html
|
119
|
-
- html/files/lib/daemons_rb.html
|
120
|
-
- html/fr_class_index.html
|
121
|
-
- html/fr_file_index.html
|
122
|
-
- html/fr_method_index.html
|
123
|
-
- html/index.html
|
124
|
-
- html/rdoc-style.css
|
109
|
+
- examples/run/myserver_hanging.rb
|
110
|
+
- examples/run/myserver_slowstop.rb
|
125
111
|
- lib/daemons.rb
|
126
112
|
- lib/daemons/application.rb
|
127
113
|
- lib/daemons/application_group.rb
|
114
|
+
- lib/daemons/change_privilege.rb
|
128
115
|
- lib/daemons/cmdline.rb
|
129
116
|
- lib/daemons/controller.rb
|
130
117
|
- lib/daemons/daemonize.rb
|
118
|
+
- lib/daemons/etc_extension.rb
|
131
119
|
- lib/daemons/exceptions.rb
|
132
120
|
- lib/daemons/monitor.rb
|
133
121
|
- lib/daemons/pid.rb
|
@@ -135,10 +123,8 @@ files:
|
|
135
123
|
- lib/daemons/pidmem.rb
|
136
124
|
- lib/daemons/version.rb
|
137
125
|
- setup.rb
|
138
|
-
-
|
139
|
-
-
|
140
|
-
- test/test1.rb
|
141
|
-
- test/testapp.rb
|
126
|
+
- spec/pidfile_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
142
128
|
homepage: http://daemons.rubyforge.org
|
143
129
|
licenses: []
|
144
130
|
post_install_message:
|
@@ -164,7 +150,5 @@ signing_key:
|
|
164
150
|
specification_version: 3
|
165
151
|
summary: A toolkit to create and control daemons in different ways
|
166
152
|
test_files:
|
167
|
-
-
|
168
|
-
-
|
169
|
-
- test/test1.rb
|
170
|
-
- test/testapp.rb
|
153
|
+
- spec/pidfile_spec.rb
|
154
|
+
- spec/spec_helper.rb
|
data/daemons.tmproj
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
-
<plist version="1.0">
|
4
|
-
<dict>
|
5
|
-
<key>documents</key>
|
6
|
-
<array>
|
7
|
-
<dict>
|
8
|
-
<key>expanded</key>
|
9
|
-
<true/>
|
10
|
-
<key>name</key>
|
11
|
-
<string>daemons</string>
|
12
|
-
<key>regexFolderFilter</key>
|
13
|
-
<string>!.*/(\.[^/]*|CVS|_darcs|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
|
14
|
-
<key>sourceDirectory</key>
|
15
|
-
<string></string>
|
16
|
-
</dict>
|
17
|
-
</array>
|
18
|
-
<key>fileHierarchyDrawerWidth</key>
|
19
|
-
<integer>200</integer>
|
20
|
-
<key>metaData</key>
|
21
|
-
<dict>
|
22
|
-
<key>html/classes/Daemons.html</key>
|
23
|
-
<dict>
|
24
|
-
<key>caret</key>
|
25
|
-
<dict>
|
26
|
-
<key>column</key>
|
27
|
-
<integer>28</integer>
|
28
|
-
<key>line</key>
|
29
|
-
<integer>553</integer>
|
30
|
-
</dict>
|
31
|
-
<key>firstVisibleColumn</key>
|
32
|
-
<integer>0</integer>
|
33
|
-
<key>firstVisibleLine</key>
|
34
|
-
<integer>533</integer>
|
35
|
-
</dict>
|
36
|
-
<key>lib/daemons/application_group.rb</key>
|
37
|
-
<dict>
|
38
|
-
<key>caret</key>
|
39
|
-
<dict>
|
40
|
-
<key>column</key>
|
41
|
-
<integer>0</integer>
|
42
|
-
<key>line</key>
|
43
|
-
<integer>0</integer>
|
44
|
-
</dict>
|
45
|
-
<key>firstVisibleColumn</key>
|
46
|
-
<integer>0</integer>
|
47
|
-
<key>firstVisibleLine</key>
|
48
|
-
<integer>61</integer>
|
49
|
-
</dict>
|
50
|
-
</dict>
|
51
|
-
<key>showFileHierarchyDrawer</key>
|
52
|
-
<true/>
|
53
|
-
<key>windowFrame</key>
|
54
|
-
<string>{{419, 58}, {733, 788}}</string>
|
55
|
-
</dict>
|
56
|
-
</plist>
|