daemons 1.2.6 → 1.3.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
2
  SHA1:
3
- metadata.gz: fc83cd9641e813a84137af3a5ee5a0ce14ae8b3f
4
- data.tar.gz: 6ff0dedb0c407a49ab2b3037fe7aeba50c161ee4
3
+ metadata.gz: b9dd7a0ebbf277c1b9181d6a0b2842a23745a641
4
+ data.tar.gz: c0c19d888f7e3a5e9bf2adef3d461e9901e3ba62
5
5
  SHA512:
6
- metadata.gz: e712b26c9135ec38e02d4283ae52cfdf2b13f22c7168d66e66563223e34653f1603232e6e2dc65c1a5f39df8411f59fd9a1e6be106ae878456a4ef6d314d5eed
7
- data.tar.gz: 8ba557b1f944a37544079bac30b25a86395c8e74366eca728ef9e245f12c1d2483a9ee777f715390c6975c45f6fb522162e69a95fc2d2b945ee512814f7d3047
6
+ metadata.gz: 01bad14851edb2e7bda6f5e477e9e5f4137023869e71f654c77c5f2d02950605337f01d16fb408a7759342777a8f0035f0ca976d856134834b4b8a4b2c62f461
7
+ data.tar.gz: 3909cb80e4a2d5b0ec534912b9ba572acb6db8ed7fbd5592ad9789999f4d8bf502061c6883f06afc478c5fc9abe7938eb8da774a78fded8aa1b3b08bb081cbb0
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2005-2017 Thomas Uehlinger, 2014-2016 Aaron Stone
1
+ Copyright (c) 2005-2018 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
@@ -201,7 +201,7 @@ end
201
201
  Daemons.run('myserver.rb', { show_status_callback: :custom_show_status })
202
202
  ```
203
203
 
204
- Documenation
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-2017 by Thomas Uehlinger, 2014-2016 by Aaron Stone.
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.
@@ -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,
@@ -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 = method(function)
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
 
@@ -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 "Usage: #{@app_name} <command> <options> -- <application options>"
75
- puts
76
- puts '* where <command> is one of:'
77
- puts ' start start an instance of the application'
78
- puts ' stop stop all instances of the application'
79
- puts ' restart stop all instances and restart them afterwards'
80
- puts ' reload send a SIGHUP to all instances of the application'
81
- puts ' run start the application and stay on top'
82
- puts ' zap set the application to a stopped state'
83
- puts ' status show status (PID) of application instances'
84
- puts
85
- puts '* and where <options> may contain several of the following:'
86
-
87
- puts @optparse.usage
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)
@@ -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>.rb<number>.pid
17
- # (Note that <tt><number></tt> is omitted if only one instance of the script can
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}_num*.pid")]
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
- File.join(@dir, "#{@progname}#{@number ? '_num' + @number.to_s : '' }.pid")
86
+ suffix = "#{pid_delimiter}#{@number}" if @number
87
+ File.join(@dir, "#{@progname}#{suffix}.pid")
85
88
  end
86
89
 
87
90
  def exist?
@@ -1,3 +1,3 @@
1
1
  module Daemons
2
- VERSION = '1.2.6'
2
+ VERSION = '1.3.0'
3
3
  end
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.2.6
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