daemonite 0.4.1 → 0.4.2
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/daemonite.gemspec +1 -1
- data/lib/daemonite.rb +48 -39
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74f7f995baeec2a36127f05e1e0dc6dfcc9788894cd056b6d174c10e0ec8f11e
|
4
|
+
data.tar.gz: d17d606a20d9a0565e7b97fc573c1aa91ac3457f7160c7e0596c0aa2014e42eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e65fc163a6a708d13962f84ee1c805578ed4674febc152a4d95766875ccf22cb0797405cfbd438b82304837ea180935177abd71a83d92f76a63ad72dce69d9f
|
7
|
+
data.tar.gz: 2aa8c2c09e32284da2d2c3615d916165ec98866514987ee267e341d3decc9b359f71bfbc7e1ded31031d3cea7df485ba80d4a26cd9ef2db76183f89787132aa9
|
data/daemonite.gemspec
CHANGED
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
118
|
-
if
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
|