daemonite 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/daemonite.gemspec +1 -1
  3. data/lib/daemonite.rb +48 -39
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e84d4f992152f3c11c7449081d617825107359b0a542feca239c102879d19719
4
- data.tar.gz: e30fd22e0e5e89dd91c83777ac6fd5a78b56fa9fc5097b8dc471fd2e27023c9a
3
+ metadata.gz: 74f7f995baeec2a36127f05e1e0dc6dfcc9788894cd056b6d174c10e0ec8f11e
4
+ data.tar.gz: d17d606a20d9a0565e7b97fc573c1aa91ac3457f7160c7e0596c0aa2014e42eb
5
5
  SHA512:
6
- metadata.gz: abf8a9b1943c0dcbf0eed1e1808345fcdb11720d795f8dc834d34f0a837efdd5cbc4ea2335bcd53e8ff064ff1421d72c7485be5af4636dd8bc5aac9ab98adc52
7
- data.tar.gz: 5a5514461c2356de2df7d881adc455d7e6e2a0760b05f3cf3fe64aaacc100e135c9a0e55e9ca9b9d494ebce2e2b5a316c0abaa3d0041f85b7671af1614b4f39e
6
+ metadata.gz: 6e65fc163a6a708d13962f84ee1c805578ed4674febc152a4d95766875ccf22cb0797405cfbd438b82304837ea180935177abd71a83d92f76a63ad72dce69d9f
7
+ data.tar.gz: 2aa8c2c09e32284da2d2c3615d916165ec98866514987ee267e341d3decc9b359f71bfbc7e1ded31031d3cea7df485ba80d4a26cd9ef2db76183f89787132aa9
data/daemonite.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "daemonite"
3
- s.version = "0.4.1"
3
+ s.version = "0.4.2"
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
@@ -19,6 +19,8 @@ require 'optparse'
19
19
  require 'psych'
20
20
 
21
21
  module Daemonism
22
+ @@daemonism_restart = false
23
+
22
24
  DAEMONISM_DEFAULT_OPTS = {
23
25
  :mode => :debug,
24
26
  :verbose => false,
@@ -90,59 +92,66 @@ module Daemonism
90
92
  false
91
93
  end
92
94
  end
93
- if opts[:cmdl_operation] == "info" && status.call == false
94
- puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}not running"
95
- exit
96
- end
97
- if opts[:cmdl_operation] == "info" && status.call == true
98
- puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}running as #{pid}"
99
- begin
100
- stats = `ps -o "vsz,rss,lstart,time" -p #{pid}`.split("\n")[1].strip.split(/ +/)
101
- puts "Virtual: #{"%0.2f" % (stats[0].to_f/1024)} MiB"
102
- puts "Resident: #{"%0.2f" % (stats[1].to_f/1024)} MiB"
103
- puts "Started: #{stats[2..-2].join(' ')}"
104
- puts "CPU Time: #{stats.last}"
105
- rescue
95
+ unless @@daemonism_restart
96
+ if opts[:cmdl_operation] == "info" && status.call == false
97
+ puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}not running"
98
+ exit
99
+ end
100
+ if opts[:cmdl_operation] == "info" && status.call == true
101
+ puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}running as #{pid}"
102
+ begin
103
+ stats = `ps -o "vsz,rss,lstart,time" -p #{pid}`.split("\n")[1].strip.split(/ +/)
104
+ puts "Virtual: #{"%0.2f" % (stats[0].to_f/1024)} MiB"
105
+ puts "Resident: #{"%0.2f" % (stats[1].to_f/1024)} MiB"
106
+ puts "Started: #{stats[2..-2].join(' ')}"
107
+ puts "CPU Time: #{stats.last}"
108
+ rescue
109
+ end
110
+ exit
111
+ end
112
+ if %w{start}.include?(opts[:cmdl_operation]) && status.call == true
113
+ puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}already started"
114
+ exit
106
115
  end
107
- exit
108
- end
109
- if %w{start}.include?(opts[:cmdl_operation]) && status.call == true
110
- puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}already started"
111
- exit
112
116
  end
113
117
 
114
118
  ########################################################################################################################
115
119
  # stop/restart server
116
120
  ########################################################################################################################
117
- if %w{stop restart}.include?(opts[:cmdl_operation])
118
- if status.call == false
119
- puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}maybe not started?"
120
- else
121
- puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}stopped"
122
- puts "Waiting while server goes down ..."
123
- while status.call
124
- Process.kill "SIGTERM", pid
125
- sleep 0.3
121
+ unless @@daemonism_restart
122
+ if %w{stop restart}.include?(opts[:cmdl_operation])
123
+ if status.call == false
124
+ puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}maybe not started?"
125
+ else
126
+ puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}stopped"
127
+ puts "Waiting while server goes down ..."
128
+ while status.call
129
+ Process.kill "SIGTERM", pid
130
+ sleep 0.3
131
+ end
126
132
  end
133
+ exit unless opts[:cmdl_operation] == "restart"
127
134
  end
128
- exit unless opts[:cmdl_operation] == "restart"
129
135
  end
130
136
 
131
137
  ########################################################################################################################
132
138
  # go through user defined startup thingis
133
139
  ########################################################################################################################
134
- opts[:runtime_cmds].each do |ro|
135
- ro[2].call(status.call) if opts[:cmdl_operation] == ro[0]
136
- end
140
+ unless @@daemonism_restart
141
+ opts[:runtime_cmds].each do |ro|
142
+ ro[2].call(status.call) if opts[:cmdl_operation] == ro[0]
143
+ end
144
+ @@daemonism_restart = true
137
145
 
138
- retain = $stdout.dup
139
- Process.daemon(opts[:basepath]) unless opts[:verbose]
140
- retain.puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}started as PID:#{Process.pid}"
141
- File.write(opts[:basepath] + '/' + opts[:pidfile],Process.pid) # after daemon, so that we get the forked pid
142
- Dir.chdir(opts[:basepath])
143
- ::Kernel::at_exit do
144
- File.unlink(opts[:basepath] + '/' + opts[:pidfile])
145
- @at_exit.call if @at_exit
146
+ retain = $stdout.dup
147
+ Process.daemon(opts[:basepath]) unless opts[:verbose]
148
+ retain.puts "Server #{opts[:cmdl_info].nil? ? '' : '(' + opts[:cmdl_info].to_s + ') '}started as PID:#{Process.pid}"
149
+ File.write(opts[:basepath] + '/' + opts[:pidfile],Process.pid) # after daemon, so that we get the forked pid
150
+ Dir.chdir(opts[:basepath])
151
+ ::Kernel::at_exit do
152
+ File.unlink(opts[:basepath] + '/' + opts[:pidfile])
153
+ @at_exit.call if @at_exit
154
+ end
146
155
  end
147
156
  end
148
157
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemonite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler