daemons 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2b3903b602fe522c5bfd073703d563554ea0dc00
4
- data.tar.gz: 98a54946242d0a0034576ab9fefb68b7c4bcf4f7
2
+ SHA256:
3
+ metadata.gz: 5114c4c5cb5dba3befcc82f6eaa45d901036bc7357a6d4d81cfd8cad8c49dae6
4
+ data.tar.gz: 0eb7b12972a659d053b87d4d59e24d5a3de21a9ff94c3432e8da62ac08f5c127
5
5
  SHA512:
6
- metadata.gz: 0a3557bbfa8e6938eb468e91f4c5c6e376d6ec35dce02740dc744492f1373f4d29a89a12c338d021f203de5edaf80047841d790106909961ec09a2dd682b4452
7
- data.tar.gz: f0088e769e05b46de5fd115112782447b42e3687e3df071c3ecdc6021613d569e444034db2ceffd3c03cc8861b9be1918d6da5b8fd0bf2234df919683dcb0c41
6
+ metadata.gz: '00970b9deb9eab30e1ce69b31ceca7617bf406692f5dbbb5a9459c5a5a898bc8a0e751fb751cb463f027be1977b54c0b914fcee996ad0cbea997829ce54d2360'
7
+ data.tar.gz: f98f5696a4f482e29eb22c38fddc9fa6dafcfaaa4c6989a5015191c53711848e703267dc3c0da25080d9509035bf91b7aac7f009b4ccbb6de53fd8a299a4834b
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2005-2018 Thomas Uehlinger, 2014-2016 Aaron Stone
1
+ Copyright (c) 2005-2021 Thomas Uehlinger, 2014-2016 Aaron Stone
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -209,4 +209,4 @@ Documentation can be found at http://www.rubydoc.info/gems/daemons.
209
209
  Author
210
210
  ------
211
211
 
212
- Written 2005-2018 by Thomas Uehlinger, 2014-2016 by Aaron Stone.
212
+ Written 2005-2021 by Thomas Uehlinger, 2014-2016 by Aaron Stone.
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'
@@ -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
- rescue ::Exception
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
- rescue ::Exception
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
- Process.kill(SIGNAL, pid)
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
- $stdout.flush
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
@@ -83,7 +83,7 @@ module Daemons
83
83
  end
84
84
  pids = processes.map { |p| p.split(/\s/)[0].to_i }
85
85
  end
86
- rescue ::Exception
86
+ rescue ::Exception
87
87
  end
88
88
 
89
89
  pids.map do |f|
@@ -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
@@ -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
- end
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)
@@ -1,3 +1,3 @@
1
1
  module Daemons
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
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.3.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: 2018-12-14 00:00:00.000000000 Z
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: '0'
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: '0'
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.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.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
- rubyforge_project:
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