process-daemon 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/process/daemon.rb +2 -2
- data/lib/process/daemon/controller.rb +10 -3
- data/lib/process/daemon/version.rb +1 -1
- data/test/test_daemon.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ac6a1383d85f2ac030dd67378c030b390ec8e57
|
4
|
+
data.tar.gz: bf7e354b299aa95289c9413f6433f05c3e089e1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2dd1c47ad979b2799212c33db7794254a5b732a84bdb55076ee4725936c4f2c3dd40eea3a70f21f8663946208391d2b12b300e9e0f22f655f885fbfbf0925f4
|
7
|
+
data.tar.gz: de24582d288d5299e142c6a094eaabda43cc8f73fe512f660a114d5aa7de235e04fd835efec09d9aec5f26bfdd609f35ecc8f91cd6a18a2500e7180bc86cac0f
|
data/README.md
CHANGED
@@ -75,3 +75,27 @@ Then run `daemon.rb start`. To stop the daemon, run `daemon.rb stop`.
|
|
75
75
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
76
|
4. Push to the branch (`git push origin my-new-feature`)
|
77
77
|
5. Create new Pull Request
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
Released under the MIT license.
|
82
|
+
|
83
|
+
Copyright, 2014, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
84
|
+
|
85
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
86
|
+
of this software and associated documentation files (the "Software"), to deal
|
87
|
+
in the Software without restriction, including without limitation the rights
|
88
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
89
|
+
copies of the Software, and to permit persons to whom the Software is
|
90
|
+
furnished to do so, subject to the following conditions:
|
91
|
+
|
92
|
+
The above copyright notice and this permission notice shall be included in
|
93
|
+
all copies or substantial portions of the Software.
|
94
|
+
|
95
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
96
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
97
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
98
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
99
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
100
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
101
|
+
THE SOFTWARE.
|
data/lib/process/daemon.rb
CHANGED
@@ -32,6 +32,9 @@ module Process
|
|
32
32
|
@daemon = daemon
|
33
33
|
|
34
34
|
@output = options[:output] || $stdout
|
35
|
+
|
36
|
+
# How long to wait until sending SIGTERM and eventually SIGKILL to the daemon process group when asking it to stop:
|
37
|
+
@stop_timeout = options[:stop_timeout] || 10.0
|
35
38
|
end
|
36
39
|
|
37
40
|
# This function is called from the daemon executable. It processes ARGV and checks whether the user is asking for `start`, `stop`, `restart`, `status`.
|
@@ -151,6 +154,9 @@ module Process
|
|
151
154
|
return daemon_state
|
152
155
|
end
|
153
156
|
|
157
|
+
# How long to wait between checking the daemon process when shutting down:
|
158
|
+
STOP_PERIOD = 0.1
|
159
|
+
|
154
160
|
# Stops the daemon process.
|
155
161
|
def stop
|
156
162
|
@output.puts Rainbow("Stopping daemon...").blue
|
@@ -175,15 +181,16 @@ module Process
|
|
175
181
|
# Interrupt the process group:
|
176
182
|
pgid = -Process.getpgid(pid)
|
177
183
|
Process.kill("INT", pgid)
|
178
|
-
sleep 0.1
|
179
184
|
|
180
|
-
|
185
|
+
(@stop_timeout / STOP_PERIOD).to_i.times do
|
186
|
+
sleep STOP_PERIOD if ProcessFile.running(@daemon)
|
187
|
+
end
|
181
188
|
|
182
189
|
# Kill/Term loop - if the @daemon didn't die easily, shoot
|
183
190
|
# it a few more times.
|
184
191
|
attempts = 5
|
185
192
|
while ProcessFile.running(@daemon) and attempts > 0
|
186
|
-
sig = (attempts
|
193
|
+
sig = (attempts <= 2) ? "KILL" : "TERM"
|
187
194
|
|
188
195
|
@output.puts Rainbow("Sending #{sig} to process group #{pgid}...").red
|
189
196
|
Process.kill(sig, pgid)
|
data/test/test_daemon.rb
CHANGED
@@ -57,14 +57,14 @@ class XMLRPCDaemon < Process::Daemon
|
|
57
57
|
|
58
58
|
@rpc_server.mount("/RPC2", @listener)
|
59
59
|
|
60
|
-
$stdout.flush
|
61
|
-
$stderr.flush
|
62
|
-
|
63
60
|
begin
|
61
|
+
puts "Daemon starting..."
|
64
62
|
@rpc_server.start
|
63
|
+
puts "Daemon stopping..."
|
65
64
|
rescue Interrupt
|
66
65
|
puts "Daemon interrupted..."
|
67
66
|
ensure
|
67
|
+
puts "Daemon shutdown..."
|
68
68
|
@rpc_server.shutdown
|
69
69
|
end
|
70
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|