daemonite 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -0
  3. data/daemonite.gemspec +1 -1
  4. data/lib/daemonite.rb +17 -3
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd02605e10df3a5a47877ab9a0c1212eb565a7606cdcdee6b2339cfd628bacf8
4
- data.tar.gz: a89cd8b6da35b87c7ac679b607bc4ae8886546402218bcbe9367d7281ffff4e8
3
+ metadata.gz: '0698646b78cb6bac5e02db21abbb572a5dd0c127bc736c21d40fd7358d166310'
4
+ data.tar.gz: bc6875891a8f527621f52dc123b02bcc6bdcdd27c698ced0da01e16b36705fd4
5
5
  SHA512:
6
- metadata.gz: f31aa4941704d843513bec86f6e4cd6049b95c853c9c65fe7b80d6ede6148be45b069fadb06ffe8be3f77f93d483bdc8da648a9f5ac980e44a525bcb78c7a76b
7
- data.tar.gz: 17f2e8d7561787f8f2ed6ecfa95d62d3af8a4eb5e29a000413fb48ca53ce7d4bb7b45921d788c713c6ab65a23594e3bb62034b2204e2a05da7098ac0e283d664
6
+ metadata.gz: 65288788593135c089ad0ce936614ba3ebf3b783098960b863b8aedf61b5ea8bf9bd98da9f20124891fd0b9d455e296af3634dbcb5eaa74b6aad8ed0df53c5b4
7
+ data.tar.gz: 378f68232eec8c6a2bab73d523527f152d8a81f903f6bf45faf425fd54986e50955e1b1fe555fbda8a8ff572b723229bde29f70d2d54724276e6aa76d5eae39f
data/README.md CHANGED
@@ -50,6 +50,32 @@ Daemonite.new(opts)
50
50
  Also be aware that a json configuration file $PROGRAM_NAME.sub /\.rb$/, '.conf'
51
51
  is automatically read, if it exists.
52
52
 
53
+ ## Usage - Sinatra
54
+
55
+ Give PID file + daemon start, stop, restart, info functionality to sinatra. Stack overflow overflows with questions about it :-)
56
+
57
+ ```ruby
58
+ require 'sinatra/base'
59
+ require 'daemonite'
60
+
61
+ Daemonite.new do |opts|
62
+ on startup do
63
+ opts[:sin] = Sinatra.new do
64
+ set :port, 9327
65
+ Encoding.default_external = "UTF-8"
66
+
67
+ get '/' do
68
+ 'Hello world!'
69
+ end
70
+ end
71
+ end
72
+
73
+ run do
74
+ opts[:sin].run!
75
+ end
76
+ end.go!
77
+ ```
78
+
53
79
  ## Usage - Alternative
54
80
 
55
81
  ```ruby
data/daemonite.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "daemonite"
3
- s.version = "0.6.0"
3
+ s.version = "0.7.1"
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."
data/lib/daemonite.rb CHANGED
@@ -39,9 +39,10 @@ module Daemonism
39
39
 
40
40
  def daemonism(opts={},&block)
41
41
  @at_exit = nil
42
- @at_start = nil
42
+ @at_startup = nil
43
+ @at_setup = nil
43
44
 
44
- if File.exists?(opts[:basepath] + '/' + opts[:conffile])
45
+ if File.exist?(opts[:basepath] + '/' + opts[:conffile])
45
46
  opts.merge!(Psych::load_file(opts[:basepath] + '/' + opts[:conffile]))
46
47
  end
47
48
  Dir.chdir(opts[:basepath])
@@ -50,6 +51,7 @@ module Daemonism
50
51
  opts[:block] = nil
51
52
  instance_exec(opts,&block) if block_given?
52
53
 
54
+
53
55
  ########################################################################################################################
54
56
  # parse arguments
55
57
  ########################################################################################################################
@@ -63,7 +65,7 @@ module Daemonism
63
65
  end
64
66
  opt.on("--verbose", "-v", "Do not daemonize. Write ouput to console.") { opts[:verbose] = true }
65
67
  opt.on("--config=FNAME", "-cFNAME", "Config file location.") { |f,a|
66
- if File.exists?(opts[:basepath] + '/' + f)
68
+ if File.exist?(opts[:basepath] + '/' + f)
67
69
  opts.merge!(Psych::load_file(opts[:basepath] + '/' + f))
68
70
  end
69
71
  }
@@ -84,6 +86,11 @@ module Daemonism
84
86
  ########################################################################################################################
85
87
  opts[:runtime_proc].call(opts) unless opts[:runtime_proc].nil?
86
88
 
89
+ ########################################################################################################################
90
+ # call this if you want to change important things such as pidfile after parsing (but before any formal start)
91
+ ########################################################################################################################
92
+ @at_setup.call(opts) if @at_setup
93
+
87
94
  ########################################################################################################################
88
95
  # status and info
89
96
  ########################################################################################################################
@@ -176,22 +183,29 @@ module Daemonism
176
183
  @at_exit = blk
177
184
  when :startup
178
185
  @at_startup = blk
186
+ when :setup
187
+ @at_setup = blk
179
188
  end
180
189
  end
181
190
  def exit; :exit; end
182
191
  def startup; :startup; end
192
+ def setup; :setup; end
183
193
  def on_exit(&blk)
184
194
  on :exit, &blk
185
195
  end
186
196
  def on_startup(&blk)
187
197
  on :startup, &blk
188
198
  end
199
+ def on_setup(&blk)
200
+ on :setup, &blk
201
+ end
189
202
  def use(blk)
190
203
  instance_eval(&blk)
191
204
  end
192
205
  alias_method :at, :on
193
206
  alias_method :at_exit, :on_exit
194
207
  alias_method :at_startup, :on_startup
208
+ alias_method :at_setup, :on_setup
195
209
  end
196
210
 
197
211
  class Daemonite
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.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-03 00:00:00.000000000 Z
11
+ date: 2024-06-26 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
@@ -29,7 +29,7 @@ homepage: https://github.com/etm/daemonite.rb
29
29
  licenses:
30
30
  - LGPL-3.0
31
31
  metadata: {}
32
- post_install_message:
32
+ post_install_message:
33
33
  rdoc_options: []
34
34
  require_paths:
35
35
  - lib
@@ -44,8 +44,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  requirements: []
47
- rubygems_version: 3.1.2
48
- signing_key:
47
+ rubygems_version: 3.5.9
48
+ signing_key:
49
49
  specification_version: 4
50
50
  summary: Daemonite - Process.daemon and argparse wrapper for loopies.
51
51
  test_files: []