daemons 1.3.1 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +14 -19
- data/Releases +11 -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
- data/lib/daemons.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: cb08e3c11dd04ba70fdfa9a27e41d004839a48318b77bf7edb5e93976de129f7
|
4
|
+
data.tar.gz: 683d0ed93f6a41378a3ed585035b773f4008a147542ab6f29281374aa746ccf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8743b8307c977149bcfbb1d6b6b36897a1c750ef63a25f7225d7b1774eaffd128843a1d92d626c3062ff680066831214eed8dc3523216b61f15b355701f4d5
|
7
|
+
data.tar.gz: de074de7aa4ba81a507d9b06f900c2eb044628ceb3a02b5cf4abb717dfdbf6df52c56f709caa85b223d8a18b9da2c0057017074089832412a231499ef050dcde
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Ruby Daemons
|
2
|
-
|
1
|
+
# Ruby Daemons
|
2
|
+
|
3
3
|
[![Build Status](https://travis-ci.org/thuehlinger/daemons.svg?branch=master)](https://travis-ci.org/thuehlinger/daemons)[![Code Climate](https://codeclimate.com/github/acuppy/daemons/badges/gpa.svg)](https://codeclimate.com/github/acuppy/daemons)[![Test Coverage](https://circleci.com/gh/acuppy/daemons.svg?style=shield&circle-token=a4f96fd41f7682661d6543e30207427ac8870c0d)](https://circleci.com/gh/acuppy/daemons)
|
4
4
|
|
5
5
|
Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
|
@@ -12,8 +12,7 @@ Besides this basic functionality, daemons offers many advanced features like _ex
|
|
12
12
|
and logging (in case your ruby script crashes) and _monitoring_ and automatic restarting of your processes
|
13
13
|
if they crash.
|
14
14
|
|
15
|
-
Basic Usage
|
16
|
-
-----------
|
15
|
+
## Basic Usage
|
17
16
|
|
18
17
|
You can use Daemons in four different ways:
|
19
18
|
|
@@ -45,7 +44,7 @@ Daemons.run('myserver.rb')
|
|
45
44
|
|
46
45
|
And use it like this from the console:
|
47
46
|
|
48
|
-
```
|
47
|
+
``` sh
|
49
48
|
$ ruby myserver_control.rb start
|
50
49
|
(myserver.rb is now running in the background)
|
51
50
|
$ ruby myserver_control.rb restart
|
@@ -55,18 +54,17 @@ $ ruby myserver_control.rb stop
|
|
55
54
|
|
56
55
|
For testing purposes you can even run `myserver.rb` _without forking_ in the background:
|
57
56
|
|
58
|
-
```
|
57
|
+
``` sh
|
59
58
|
$ ruby myserver_control.rb run
|
60
59
|
```
|
61
60
|
|
62
61
|
An additional nice feature of Daemons is that you can pass _additional arguments_ to the script that
|
63
62
|
should be daemonized by seperating them by two _hyphens_:
|
64
63
|
|
65
|
-
```
|
64
|
+
``` sh
|
66
65
|
$ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
|
67
66
|
```
|
68
67
|
|
69
|
-
|
70
68
|
### 2. Create wrapper scripts that include your server procs
|
71
69
|
|
72
70
|
Layout: suppose you have some code you want to run in the background and control that background process
|
@@ -96,7 +94,7 @@ end
|
|
96
94
|
|
97
95
|
And use it like this from the console:
|
98
96
|
|
99
|
-
```
|
97
|
+
``` sh
|
100
98
|
$ ruby myproc_control.rb start
|
101
99
|
(myproc.rb is now running in the background)
|
102
100
|
$ ruby myproc_control.rb restart
|
@@ -106,7 +104,7 @@ $ ruby myproc_control.rb stop
|
|
106
104
|
|
107
105
|
For testing purposes you can even run `myproc.rb` _without forking_ in the background:
|
108
106
|
|
109
|
-
```
|
107
|
+
``` sh
|
110
108
|
$ ruby myproc_control.rb run
|
111
109
|
```
|
112
110
|
|
@@ -169,13 +167,12 @@ end
|
|
169
167
|
|
170
168
|
For further documentation, refer to the module documentation of Daemons.
|
171
169
|
|
172
|
-
Displaying daemon status
|
173
|
-
------------------------
|
170
|
+
## Displaying daemon status
|
174
171
|
|
175
172
|
When daemonizing a process using a wrapper script, as examples 1 and 2 above,
|
176
173
|
the status can be shown using
|
177
174
|
|
178
|
-
```
|
175
|
+
``` sh
|
179
176
|
$ ruby myproc_control.rb status
|
180
177
|
```
|
181
178
|
|
@@ -201,12 +198,10 @@ end
|
|
201
198
|
Daemons.run('myserver.rb', { show_status_callback: :custom_show_status })
|
202
199
|
```
|
203
200
|
|
204
|
-
Documentation
|
205
|
-
-------------------
|
201
|
+
## Documentation
|
206
202
|
|
207
|
-
Documentation can be found at http://www.rubydoc.info/gems/daemons
|
203
|
+
Documentation can be found at <http://www.rubydoc.info/gems/daemons>.
|
208
204
|
|
209
|
-
Author
|
210
|
-
------
|
205
|
+
## Author
|
211
206
|
|
212
|
-
Written 2005-
|
207
|
+
Written 2005-2021 by Thomas Uehlinger, 2014-2016 by Aaron Stone.
|
data/Releases
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
= Daemons Release History
|
2
2
|
|
3
|
+
== Release 1.4.1: August 26, 2021
|
4
|
+
|
5
|
+
* Fix :proc mode (pass &block explicitly) (thanks to Graham Rogers)
|
6
|
+
* Fix style of REAMDE.md
|
7
|
+
|
8
|
+
== Release 1.4.0: May 1, 2021
|
9
|
+
|
10
|
+
* Allow for customization which signals are sent to stop process (thanks to philister)
|
11
|
+
* Resolves mismatched indentations (thanks to Luis M Rodriguez)
|
12
|
+
* Allow to use pry-byebug 3.8.0 (thanks to kamipo)
|
13
|
+
|
3
14
|
== Release 1.3.1: December 14, 2018
|
4
15
|
|
5
16
|
* 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
data/lib/daemons.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.1
|
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-08-26 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
|