daemons 1.2.6 → 1.3.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 +4 -4
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/Releases +6 -0
- data/lib/daemons.rb +2 -0
- data/lib/daemons/application.rb +8 -3
- data/lib/daemons/application_group.rb +4 -1
- data/lib/daemons/cmdline.rb +45 -16
- data/lib/daemons/pidfile.rb +9 -6
- data/lib/daemons/version.rb +1 -1
- 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: b9dd7a0ebbf277c1b9181d6a0b2842a23745a641
|
4
|
+
data.tar.gz: c0c19d888f7e3a5e9bf2adef3d461e9901e3ba62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01bad14851edb2e7bda6f5e477e9e5f4137023869e71f654c77c5f2d02950605337f01d16fb408a7759342777a8f0035f0ca976d856134834b4b8a4b2c62f461
|
7
|
+
data.tar.gz: 3909cb80e4a2d5b0ec534912b9ba572acb6db8ed7fbd5592ad9789999f4d8bf502061c6883f06afc478c5fc9abe7938eb8da774a78fded8aa1b3b08bb081cbb0
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -201,7 +201,7 @@ end
|
|
201
201
|
Daemons.run('myserver.rb', { show_status_callback: :custom_show_status })
|
202
202
|
```
|
203
203
|
|
204
|
-
|
204
|
+
Documentation
|
205
205
|
-------------------
|
206
206
|
|
207
207
|
Documentation can be found at http://www.rubydoc.info/gems/daemons.
|
@@ -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-
|
212
|
+
Written 2005-2018 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.3.0: December 10, 2018
|
4
|
+
|
5
|
+
* Make logging more configurable.
|
6
|
+
* Add configuration options for pid file delimters, force_kill_waittime
|
7
|
+
* All status callback to be anything callable.
|
8
|
+
|
3
9
|
== Release 1.2.6: December 24, 2017
|
4
10
|
|
5
11
|
* Add links to rubydoc.info documentation.
|
data/lib/daemons.rb
CHANGED
@@ -99,6 +99,7 @@ module Daemons
|
|
99
99
|
# <tt>:dir</tt>:: Used in combination with <tt>:dir_mode</tt> (description above)
|
100
100
|
# <tt>:multiple</tt>:: Specifies whether multiple instances of the same script are allowed to run at the
|
101
101
|
# same time
|
102
|
+
# <tt>:pid_delimiter</tt>:: Specifies the separator used when enumerating multiple process names/pid-files. Default is '_num'.
|
102
103
|
# <tt>:ontop</tt>:: When given (i.e. set to true), stay on top, i.e. do not daemonize the application
|
103
104
|
# (but the pid-file and other things are written as usual)
|
104
105
|
# <tt>:shush</tt>:: When given (i.e. set to true), turn on silent mode (no output to the terminal)
|
@@ -129,6 +130,7 @@ module Daemons
|
|
129
130
|
# :dir_mode => :script,
|
130
131
|
# :dir => 'pids',
|
131
132
|
# :multiple => true,
|
133
|
+
# :pid_delimiter => '.n',
|
132
134
|
# :ontop => true,
|
133
135
|
# :shush => false,
|
134
136
|
# :mode => :exec,
|
data/lib/daemons/application.rb
CHANGED
@@ -31,7 +31,7 @@ module Daemons
|
|
31
31
|
['dir', 'log_dir', 'logfilename', 'output_logfilename'].each do |k|
|
32
32
|
@options[k] = File.expand_path(@options[k]) if @options.key?(k)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
@dir_mode = @dir = @script = nil
|
36
36
|
|
37
37
|
@force_kill_waittime = @options[:force_kill_waittime] || 20
|
@@ -44,7 +44,7 @@ module Daemons
|
|
44
44
|
if @options[:no_pidfiles]
|
45
45
|
@pid = PidMem.new
|
46
46
|
elsif dir = pidfile_dir
|
47
|
-
@pid = PidFile.new(dir, @group.app_name, @group.multiple)
|
47
|
+
@pid = PidFile.new(dir, @group.app_name, @group.multiple, @options[:pid_delimiter])
|
48
48
|
else
|
49
49
|
@pid = PidMem.new
|
50
50
|
end
|
@@ -52,7 +52,12 @@ module Daemons
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def show_status_callback=(function)
|
55
|
-
@show_status_callback =
|
55
|
+
@show_status_callback =
|
56
|
+
if function.respond_to?(:call)
|
57
|
+
function
|
58
|
+
else
|
59
|
+
method(function)
|
60
|
+
end
|
56
61
|
end
|
57
62
|
|
58
63
|
def change_privilege
|
@@ -38,8 +38,11 @@ module Daemons
|
|
38
38
|
@dir = @options[:dir] || ''
|
39
39
|
|
40
40
|
@keep_pid_files = @options[:keep_pid_files] || false
|
41
|
+
|
41
42
|
@no_pidfiles = @options[:no_pidfiles] || false
|
42
43
|
|
44
|
+
@pid_delimiter = @options[:pid_delimiter]
|
45
|
+
|
43
46
|
@applications = []
|
44
47
|
end
|
45
48
|
|
@@ -94,7 +97,7 @@ module Daemons
|
|
94
97
|
@monitor = Monitor.find(dir, app_name + '_monitor')
|
95
98
|
|
96
99
|
reporter = Reporter.new(options)
|
97
|
-
pid_files = PidFile.find_files(dir, app_name, ! @keep_pid_files) do |pid, file|
|
100
|
+
pid_files = PidFile.find_files(dir, app_name, ! @keep_pid_files, @pid_delimiter) do |pid, file|
|
98
101
|
reporter.deleted_found_pidfile(pid, file)
|
99
102
|
end
|
100
103
|
|
data/lib/daemons/cmdline.rb
CHANGED
@@ -12,7 +12,7 @@ module Daemons
|
|
12
12
|
opts.on('-t', '--ontop', 'Stay on top (does not daemonize)') do |t|
|
13
13
|
@options[:ontop] = t
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
opts.on('-s', '--shush', 'Silent mode (no output to the terminal)') do |t|
|
17
17
|
@options[:shush] = t
|
18
18
|
end
|
@@ -25,9 +25,37 @@ module Daemons
|
|
25
25
|
@options[:no_wait] = t
|
26
26
|
end
|
27
27
|
|
28
|
+
opts.on('-w', '--force_kill_waittime SECONDS', Integer, 'Maximum time to wait for processes to stop before force-killing') do |t|
|
29
|
+
@options[:force_kill_waittime] = t
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('--pid_delimiter STRING', 'Text used to separate process number in full process name and pid-file name') do |value|
|
33
|
+
@options[:pid_delimiter] = value
|
34
|
+
end
|
35
|
+
|
28
36
|
opts.separator ''
|
29
37
|
opts.separator 'Common options:'
|
30
38
|
|
39
|
+
opts.on('-l', '--log_output', 'Enable input/output stream redirection') do |value|
|
40
|
+
@options[:log_output] = value
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('--logfilename FILE', String, 'Custom log file name for exceptions') do |value|
|
44
|
+
@options[:logfilename] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on('--output_logfilename FILE', String, 'Custom file name for input/output stream redirection log') do |value|
|
48
|
+
@options[:output_logfilename] = value
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on('--log_dir DIR', String, 'Directory for log files') do |value|
|
52
|
+
@options[:log_dir] = value
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('--syslog', 'Enable output redirction into SYSLOG instead of a file') do |value|
|
56
|
+
@options[:log_output_syslog] = value
|
57
|
+
end
|
58
|
+
|
31
59
|
# No argument, shows at tail. This will print an options summary
|
32
60
|
opts.on_tail('-h', '--help', 'Show this message') do
|
33
61
|
controller.print_usage
|
@@ -62,7 +90,7 @@ END
|
|
62
90
|
def parse(args)
|
63
91
|
# The options specified on the command line will be collected in *options*.
|
64
92
|
# We set default values here.
|
65
|
-
|
93
|
+
|
66
94
|
@opts.parse(args)
|
67
95
|
|
68
96
|
@options
|
@@ -71,20 +99,21 @@ END
|
|
71
99
|
|
72
100
|
class Controller
|
73
101
|
def print_usage
|
74
|
-
puts
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
102
|
+
puts <<-USAGE.gsub(/^ {6}/, '')
|
103
|
+
Usage: #{@app_name} <command> <options> -- <application options>
|
104
|
+
|
105
|
+
* where <command> is one of:
|
106
|
+
start start an instance of the application
|
107
|
+
stop stop all instances of the application
|
108
|
+
restart stop all instances and restart them afterwards
|
109
|
+
reload send a SIGHUP to all instances of the application
|
110
|
+
run run the application in the foreground (same as start -t)
|
111
|
+
zap set the application to a stopped state
|
112
|
+
status show status (PID) of application instances
|
113
|
+
|
114
|
+
* and where <options> may contain several of the following:
|
115
|
+
#{@optparse.usage}
|
116
|
+
USAGE
|
88
117
|
end
|
89
118
|
|
90
119
|
def catch_exceptions(&block)
|
data/lib/daemons/pidfile.rb
CHANGED
@@ -13,8 +13,8 @@ module Daemons
|
|
13
13
|
# === How does a Pid-File look like?
|
14
14
|
#
|
15
15
|
# Pid-Files generated by Daemons have to following format:
|
16
|
-
# <scriptname
|
17
|
-
# (Note that <tt
|
16
|
+
# <scriptname>_num<number>.pid
|
17
|
+
# (Note that <tt>_num<number></tt> is omitted if only one instance of the script can
|
18
18
|
# run at any time)
|
19
19
|
#
|
20
20
|
# Each file just contains one line with the pid as string (for example <tt>6432</tt>).
|
@@ -28,10 +28,11 @@ module Daemons
|
|
28
28
|
# 3. in the preconfigured directory <tt>/var/run</tt> (<tt>:system</tt> option for <tt>:dir_mode</tt>)
|
29
29
|
#
|
30
30
|
class PidFile < Pid
|
31
|
+
DEFAULT_PID_DELIMITER = '_num'
|
31
32
|
attr_reader :dir, :progname, :multiple, :number
|
32
33
|
|
33
|
-
def self.find_files(dir, progname, delete = false)
|
34
|
-
files = Dir[File.join(dir, "#{progname}
|
34
|
+
def self.find_files(dir, progname, delete = false, pid_delimiter = nil)
|
35
|
+
files = Dir[File.join(dir, "#{progname}#{pid_delimiter || DEFAULT_PID_DELIMITER}*.pid")]
|
35
36
|
files = Dir[File.join(dir, "#{progname}.pid")] if files.size == 0
|
36
37
|
|
37
38
|
files.delete_if { |f| not (File.file?(f) and File.readable?(f)) }
|
@@ -62,10 +63,11 @@ module Daemons
|
|
62
63
|
new_instance
|
63
64
|
end
|
64
65
|
|
65
|
-
def initialize(dir, progname, multiple = false)
|
66
|
+
def initialize(dir, progname, multiple = false, pid_delimiter = nil)
|
66
67
|
@dir = File.expand_path(dir)
|
67
68
|
@progname = progname
|
68
69
|
@multiple = multiple
|
70
|
+
@pid_delimiter = pid_delimiter || DEFAULT_PID_DELIMITER
|
69
71
|
@number = nil
|
70
72
|
@number = 0 if multiple
|
71
73
|
|
@@ -81,7 +83,8 @@ module Daemons
|
|
81
83
|
end
|
82
84
|
|
83
85
|
def filename
|
84
|
-
|
86
|
+
suffix = "#{pid_delimiter}#{@number}" if @number
|
87
|
+
File.join(@dir, "#{@progname}#{suffix}.pid")
|
85
88
|
end
|
86
89
|
|
87
90
|
def exist?
|
data/lib/daemons/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daemons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Uehlinger
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.5.2
|
151
|
+
rubygems_version: 2.5.2.3
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: A toolkit to create and control daemons in different ways
|