daemons 1.3.1 → 1.4.0
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 +5 -5
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/Releases +6 -0
- data/lib/daemons/application.rb +40 -39
- data/lib/daemons/application_group.rb +1 -1
- data/lib/daemons/cmdline.rb +3 -0
- data/lib/daemons/reporter.rb +5 -6
- data/lib/daemons/version.rb +1 -1
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5114c4c5cb5dba3befcc82f6eaa45d901036bc7357a6d4d81cfd8cad8c49dae6
|
4
|
+
data.tar.gz: 0eb7b12972a659d053b87d4d59e24d5a3de21a9ff94c3432e8da62ac08f5c127
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00970b9deb9eab30e1ce69b31ceca7617bf406692f5dbbb5a9459c5a5a898bc8a0e751fb751cb463f027be1977b54c0b914fcee996ad0cbea997829ce54d2360'
|
7
|
+
data.tar.gz: f98f5696a4f482e29eb22c38fddc9fa6dafcfaaa4c6989a5015191c53711848e703267dc3c0da25080d9509035bf91b7aac7f009b4ccbb6de53fd8a299a4834b
|
data/LICENSE
CHANGED
data/README.md
CHANGED
data/Releases
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
= Daemons Release History
|
2
2
|
|
3
|
+
== Release 1.4.0: May 1, 2021
|
4
|
+
|
5
|
+
* Allow for customization which signals are sent to stop process (thanks to philister)
|
6
|
+
* Resolves mismatched indentations (thanks to Luis M Rodriguez)
|
7
|
+
* Allow to use pry-byebug 3.8.0 (thanks to kamipo)
|
8
|
+
|
3
9
|
== Release 1.3.1: December 14, 2018
|
4
10
|
|
5
11
|
* Fix undefined local variable or method `pid_delimiter'
|
data/lib/daemons/application.rb
CHANGED
@@ -36,6 +36,8 @@ module Daemons
|
|
36
36
|
|
37
37
|
@force_kill_waittime = @options[:force_kill_waittime] || 20
|
38
38
|
|
39
|
+
@signals_and_waits = parse_signals_and_waits(@options[:signals_and_waits])
|
40
|
+
|
39
41
|
@show_status_callback = method(:default_show_status)
|
40
42
|
|
41
43
|
@report = Reporter.new(@options)
|
@@ -203,7 +205,7 @@ module Daemons
|
|
203
205
|
if $daemons_stop_proc
|
204
206
|
$daemons_stop_proc.call
|
205
207
|
end
|
206
|
-
|
208
|
+
rescue ::Exception
|
207
209
|
end
|
208
210
|
|
209
211
|
begin; @pid.cleanup; rescue ::Exception; end
|
@@ -260,7 +262,7 @@ module Daemons
|
|
260
262
|
if $daemons_stop_proc
|
261
263
|
$daemons_stop_proc.call
|
262
264
|
end
|
263
|
-
|
265
|
+
rescue ::Exception
|
264
266
|
end
|
265
267
|
|
266
268
|
begin; @pid.cleanup; rescue ::Exception; end
|
@@ -373,6 +375,7 @@ module Daemons
|
|
373
375
|
return
|
374
376
|
end
|
375
377
|
|
378
|
+
# confusing: pid is also a attribute_reader
|
376
379
|
pid = @pid.pid
|
377
380
|
|
378
381
|
# Catch errors when trying to kill a process that doesn't
|
@@ -380,47 +383,12 @@ module Daemons
|
|
380
383
|
# restarted by the monitor yet. By catching the error, we allow the
|
381
384
|
# pid file clean-up to occur.
|
382
385
|
begin
|
383
|
-
|
386
|
+
wait_and_retry_kill_harder(pid, @signals_and_waits, no_wait)
|
384
387
|
rescue Errno::ESRCH => e
|
385
388
|
@report.output_message("#{e} #{pid}")
|
386
389
|
@report.output_message('deleting pid-file.')
|
387
390
|
end
|
388
391
|
|
389
|
-
unless no_wait
|
390
|
-
if @force_kill_waittime > 0
|
391
|
-
@report.stopping_process(group.app_name, pid)
|
392
|
-
$stdout.flush
|
393
|
-
|
394
|
-
begin
|
395
|
-
Timeout.timeout(@force_kill_waittime, TimeoutError) do
|
396
|
-
while Pid.running?(pid)
|
397
|
-
sleep(0.2)
|
398
|
-
end
|
399
|
-
end
|
400
|
-
rescue TimeoutError
|
401
|
-
@report.forcefully_stopping_process(group.app_name, pid)
|
402
|
-
$stdout.flush
|
403
|
-
|
404
|
-
begin
|
405
|
-
Process.kill('KILL', pid)
|
406
|
-
rescue Errno::ESRCH
|
407
|
-
end
|
408
|
-
|
409
|
-
begin
|
410
|
-
Timeout.timeout(20, TimeoutError) do
|
411
|
-
while Pid.running?(pid)
|
412
|
-
sleep(1)
|
413
|
-
end
|
414
|
-
end
|
415
|
-
rescue TimeoutError
|
416
|
-
@report.cannot_stop_process(group.app_name, pid)
|
417
|
-
$stdout.flush
|
418
|
-
end
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
end
|
423
|
-
|
424
392
|
sleep(0.1)
|
425
393
|
unless Pid.running?(pid)
|
426
394
|
# We try to remove the pid-files by ourselves, in case the application
|
@@ -428,7 +396,30 @@ module Daemons
|
|
428
396
|
zap!
|
429
397
|
|
430
398
|
@report.stopped_process(group.app_name, pid)
|
431
|
-
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
# @param Hash remaing_signals
|
403
|
+
# @param Boolean no_wait Send first Signal and return
|
404
|
+
def wait_and_retry_kill_harder(pid, remaining_signals, no_wait = false)
|
405
|
+
sig_wait = remaining_signals.shift
|
406
|
+
sig = sig_wait[:sig]
|
407
|
+
wait = sig_wait[:wait]
|
408
|
+
Process.kill(sig, pid)
|
409
|
+
return if no_wait || !wait.positive?
|
410
|
+
|
411
|
+
@report.stopping_process(group.app_name, pid, sig, wait)
|
412
|
+
|
413
|
+
begin
|
414
|
+
Timeout.timeout(wait, TimeoutError) do
|
415
|
+
sleep(0.2) while Pid.running?(pid)
|
416
|
+
end
|
417
|
+
rescue TimeoutError
|
418
|
+
if remaining_signals.any?
|
419
|
+
wait_and_retry_kill_harder(pid, remaining_signals)
|
420
|
+
else
|
421
|
+
@report.cannot_stop_process(group.app_name, pid)
|
422
|
+
end
|
432
423
|
end
|
433
424
|
end
|
434
425
|
|
@@ -478,5 +469,15 @@ module Daemons
|
|
478
469
|
def dir
|
479
470
|
@dir or group.dir
|
480
471
|
end
|
472
|
+
|
473
|
+
def parse_signals_and_waits(argv)
|
474
|
+
unless argv
|
475
|
+
return [
|
476
|
+
{ sig: 'TERM', wait: @force_kill_waittime },
|
477
|
+
{ sig: 'KILL', wait: 20 }
|
478
|
+
]
|
479
|
+
end
|
480
|
+
argv.split('|').collect{ |part| splitted = part.split(':'); {sig: splitted[0], wait: splitted[1].to_i}}
|
481
|
+
end
|
481
482
|
end
|
482
483
|
end
|
data/lib/daemons/cmdline.rb
CHANGED
@@ -28,6 +28,9 @@ module Daemons
|
|
28
28
|
opts.on('-w', '--force_kill_waittime SECONDS', Integer, 'Maximum time to wait for processes to stop before force-killing') do |t|
|
29
29
|
@options[:force_kill_waittime] = t
|
30
30
|
end
|
31
|
+
opts.on('--signals_and_waits STRING', String, 'which signal to use to stop and how long to wait e.g. TERM:20|KILL:20') do |t|
|
32
|
+
@options[:signals_and_waits] = t
|
33
|
+
end
|
31
34
|
|
32
35
|
opts.on('--pid_delimiter STRING', 'Text used to separate process number in full process name and pid-file name') do |value|
|
33
36
|
@options[:pid_delimiter] = value
|
data/lib/daemons/reporter.rb
CHANGED
@@ -32,20 +32,19 @@ module Daemons
|
|
32
32
|
output_message 'option :backtrace is not supported with :mode => :exec, ignoring'
|
33
33
|
end
|
34
34
|
|
35
|
-
def stopping_process(app_name, pid)
|
36
|
-
output_message "#{app_name}: trying to stop process with pid #{pid}..."
|
37
|
-
|
38
|
-
|
39
|
-
def forcefully_stopping_process(app_name, pid)
|
40
|
-
output_message "#{app_name}: process with pid #{pid} won't stop, we forcefully kill it..."
|
35
|
+
def stopping_process(app_name, pid, sig, wait)
|
36
|
+
output_message "#{app_name}: trying to stop process with pid #{pid}#{' forcefully :(' if sig == 'KILL'} sending #{sig} and waiting #{wait}s ..."
|
37
|
+
$stdout.flush
|
41
38
|
end
|
42
39
|
|
43
40
|
def cannot_stop_process(app_name, pid)
|
44
41
|
output_message "#{app_name}: unable to forcefully kill process with pid #{pid}."
|
42
|
+
$stdout.flush
|
45
43
|
end
|
46
44
|
|
47
45
|
def stopped_process(app_name, pid)
|
48
46
|
output_message "#{app_name}: process with pid #{pid} successfully stopped."
|
47
|
+
$stdout.flush
|
49
48
|
end
|
50
49
|
|
51
50
|
def status(app_name, running, pid_exists, pid)
|
data/lib/daemons/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daemons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Uehlinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '12.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 12.3.3
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '12.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 12.3.3
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rspec
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +64,14 @@ dependencies:
|
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.0
|
67
|
+
version: '3.0'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.0
|
74
|
+
version: '3.0'
|
69
75
|
description: |2
|
70
76
|
Daemons provides an easy way to wrap existing ruby scripts (for example a
|
71
77
|
self-written server) to be run as a daemon and to be controlled by simple
|
@@ -147,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
153
|
- !ruby/object:Gem::Version
|
148
154
|
version: '0'
|
149
155
|
requirements: []
|
150
|
-
|
151
|
-
rubygems_version: 2.5.2.3
|
156
|
+
rubygems_version: 3.0.3
|
152
157
|
signing_key:
|
153
158
|
specification_version: 4
|
154
159
|
summary: A toolkit to create and control daemons in different ways
|