daemonite 0.4.2 → 0.5.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/daemonite.gemspec +1 -1
  3. data/lib/daemonite.rb +30 -5
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74f7f995baeec2a36127f05e1e0dc6dfcc9788894cd056b6d174c10e0ec8f11e
4
- data.tar.gz: d17d606a20d9a0565e7b97fc573c1aa91ac3457f7160c7e0596c0aa2014e42eb
3
+ metadata.gz: a2aefaeee8ed856d896cb663cc2c2d8666f437e948e172d3d4f3bb8f8ac2bad5
4
+ data.tar.gz: 18face311c11441c3baa56eb74586bd13a2dc2fce37efd4475b4963121ae8b2f
5
5
  SHA512:
6
- metadata.gz: 6e65fc163a6a708d13962f84ee1c805578ed4674febc152a4d95766875ccf22cb0797405cfbd438b82304837ea180935177abd71a83d92f76a63ad72dce69d9f
7
- data.tar.gz: 2aa8c2c09e32284da2d2c3615d916165ec98866514987ee267e341d3decc9b359f71bfbc7e1ded31031d3cea7df485ba80d4a26cd9ef2db76183f89787132aa9
6
+ metadata.gz: 481799bb690fec6d0090db1ff7e762ebf00ea65248c9b5a21311058b49b5661eb141c5f6dd930850c8e53d8f3809f668aedbe585702f337d8674061fef6fb009
7
+ data.tar.gz: 015b1b64ebe9e4f954275c8e526c9f5de27a1ee52d5c5b965d0284e7bff355a342db2d2dfda9af62070aff3cbec23444efb42ec3771cc8083f9547a36ac8ee57
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "daemonite"
3
- s.version = "0.4.2"
3
+ s.version = "0.5.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "Daemonite - Process.daemon and argparse wrapper for loopies."
@@ -37,6 +37,9 @@ module Daemonism
37
37
  }
38
38
 
39
39
  def daemonism(opts={},&block)
40
+ @at_exit = nil
41
+ @at_start = nil
42
+
40
43
  if File.exists?(opts[:basepath] + '/' + opts[:conffile])
41
44
  opts.merge!(Psych::load_file(opts[:basepath] + '/' + opts[:conffile]))
42
45
  end
@@ -70,12 +73,12 @@ module Daemonism
70
73
  end
71
74
  opt.parse!
72
75
  }
73
- unless (%w{start stop restart info} + opts[:runtime_cmds].map{|ro| ro[0] }).include?(ARGV[0])
76
+
77
+ unless (%w{start stop restart} + opts[:runtime_cmds].map{|ro| ro[0] }).include?(ARGV[0])
74
78
  puts ARGV.options
75
- exit
79
+ exit!
76
80
  end
77
81
  opts[:cmdl_operation] = ARGV[0]
78
- @at_exit = nil
79
82
  end
80
83
  ########################################################################################################################
81
84
  opts[:runtime_proc].call(opts) unless opts[:runtime_proc].nil?
@@ -155,9 +158,25 @@ module Daemonism
155
158
  end
156
159
  end
157
160
 
158
- def at_exit(&blk)
159
- @at_exit = blk
161
+ def on(event,&blk)
162
+ case event
163
+ when :exit
164
+ @at_exit = blk
165
+ when :startup
166
+ @at_startup = blk
167
+ end
168
+ end
169
+ def exit; :exit; end
170
+ def startup; :startup; end
171
+ def on_exit(&blk)
172
+ on :exit, &blk
173
+ end
174
+ def on_startup(&blk)
175
+ on :startup, &blk
160
176
  end
177
+ alias_method :at, :on
178
+ alias_method :at_exit, :on_exit
179
+ alias_method :at_startup, :on_startup
161
180
  end
162
181
 
163
182
  class Daemonite
@@ -174,7 +193,10 @@ class Daemonite
174
193
 
175
194
  def go!
176
195
  begin
196
+ @at_startup.call if @at_startup
177
197
  @opts[:block].call(@opts)
198
+ rescue SystemExit, Interrupt
199
+ puts "Server stopped due to interrupt (PID:#{Process.pid})"
178
200
  rescue => e
179
201
  puts "Server stopped due to error (PID:#{Process.pid})"
180
202
  end
@@ -182,9 +204,12 @@ class Daemonite
182
204
 
183
205
  def loop!
184
206
  begin
207
+ @at_startup.call if @at_startup
185
208
  loop do
186
209
  @opts[:block].call(@opts)
187
210
  end unless @opts[:block].nil?
211
+ rescue SystemExit, Interrupt
212
+ puts "Server stopped due to interrupt (PID:#{Process.pid})"
188
213
  rescue => e
189
214
  puts "Server stopped due to error (PID:#{Process.pid})"
190
215
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemonite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-23 00:00:00.000000000 Z
11
+ date: 2019-04-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Daemonite - Process.daemon and argparse wrapper for loopies.
14
14
  email: juergen.mangler@gmail.com