daemon-ogre 1.5.0 → 2.0.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.
- checksums.yaml +5 -13
- data/.gitignore +18 -0
- data/Gemfile.lock +12 -17
- data/README.md +14 -213
- data/VERSION +1 -1
- data/daemon-ogre.gemspec +10 -16
- data/example/daemonizable.rb +16 -0
- data/lib/daemon-ogre/argv.rb +29 -0
- data/lib/daemon-ogre/daemon.rb +159 -51
- data/lib/daemon-ogre/opts.rb +34 -0
- data/lib/daemon-ogre.rb +7 -6
- data/test/{test_daemon-ogre.rb → example.rb} +1 -1
- data/test/test.rb +3 -0
- metadata +76 -28
- data/README.rdoc +0 -247
- data/example/sample_daemon_app.rb +0 -19
- data/files.rb +0 -24
- data/lib/daemon-ogre/app.rb +0 -40
- data/lib/daemon-ogre/mpatch.rb +0 -93
- data/lib/daemon-ogre/server.rb +0 -199
- data/lib/daemon-ogre/startup.rb +0 -85
- data/lib/daemon-ogre/support.rb +0 -246
- data/test/helper.rb +0 -18
data/lib/daemon-ogre/support.rb
DELETED
@@ -1,246 +0,0 @@
|
|
1
|
-
#DaemonOgreBody
|
2
|
-
begin
|
3
|
-
module DaemonOgre
|
4
|
-
|
5
|
-
#OgreClassMethods
|
6
|
-
begin
|
7
|
-
class << self
|
8
|
-
#Based on the rb location
|
9
|
-
def load_directory(directory,*args)
|
10
|
-
arg = Hash[*args]
|
11
|
-
|
12
|
-
#directory = File.expand_path(directory)
|
13
|
-
delayed_loads = Array.new
|
14
|
-
|
15
|
-
if !arg[:delayed].nil?
|
16
|
-
raise ArgumentError, "Delayed items must be in an "+\
|
17
|
-
"Array! Example:\n:delayed => ['abc']" if arg[:delayed].class != Array
|
18
|
-
end
|
19
|
-
|
20
|
-
if !arg[:excluded].nil?
|
21
|
-
raise ArgumentError, "Exclude items must be in an "+\
|
22
|
-
"Array! Example:\n:exclude => ['abc']" if arg[:excluded].class != Array
|
23
|
-
end
|
24
|
-
|
25
|
-
arg[:type]= "rb" if arg[:type].nil?
|
26
|
-
arg[:monkey_patch]= 0 if arg[:monkey_patch].nil?
|
27
|
-
|
28
|
-
#=============================================================================================================
|
29
|
-
|
30
|
-
### GET Pre path + validation
|
31
|
-
begin
|
32
|
-
#get method callers path
|
33
|
-
|
34
|
-
pre_path = caller[arg[:monkey_patch].to_i].split('.rb:').first+('.rb')
|
35
|
-
|
36
|
-
if !pre_path.include?('/') && !pre_path.include?('\\')
|
37
|
-
pre_path = File.expand_path(pre_path)
|
38
|
-
end
|
39
|
-
|
40
|
-
separator_symbol= String.new
|
41
|
-
pre_path.include?('/') ? separator_symbol = '/' : separator_symbol = '\\'
|
42
|
-
|
43
|
-
pre_path= ((pre_path.split(separator_symbol))-([pre_path.split(separator_symbol).pop])).join(separator_symbol)
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
puts "prepath: "+pre_path.inspect if $DEBUG
|
48
|
-
|
49
|
-
puts "LOADING_FILES_FROM_"+directory.to_s.split(separator_symbol).last.split('.').first.capitalize if $DEBUG
|
50
|
-
|
51
|
-
puts "Elements found in #{directory}" if $DEBUG
|
52
|
-
puts File.join("#{pre_path}","#{directory}","**","*.#{arg[:type]}") if $DEBUG
|
53
|
-
puts Dir[File.join("#{pre_path}","#{directory}","**","*.#{arg[:type]}")].sort.inspect if $DEBUG
|
54
|
-
|
55
|
-
Dir[File.join("#{pre_path}","#{directory}","**","*.#{arg[:type]}")].sort.each do |file|
|
56
|
-
|
57
|
-
arg[:delayed]= [nil] if arg[:delayed].nil?
|
58
|
-
arg[:excluded]= [nil] if arg[:excluded].nil?
|
59
|
-
|
60
|
-
arg[:excluded].each do |except|
|
61
|
-
if file.split(separator_symbol).last.split('.').first == except.to_s.split('.').first
|
62
|
-
|
63
|
-
puts file.to_s + " cant be loaded because it's an exception" if $DEBUG
|
64
|
-
|
65
|
-
else
|
66
|
-
|
67
|
-
arg[:delayed].each do |delay|
|
68
|
-
|
69
|
-
if file.split(separator_symbol).last.split('.').first == delay.to_s.split('.').first
|
70
|
-
delayed_loads.push(file)
|
71
|
-
else
|
72
|
-
load(file)
|
73
|
-
puts file.to_s if $DEBUG
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
delayed_loads.each do |delayed_load_element|
|
82
|
-
load(delayed_load_element)
|
83
|
-
puts delayed_load_element.to_s if $DEBUG
|
84
|
-
end
|
85
|
-
puts "DONE_LOAD_FILES_FROM_"+directory.to_s.split(separator_symbol).last.split('.').first.capitalize if $DEBUG
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
def get_port(port,max_port=65535 ,host="0.0.0.0")
|
90
|
-
|
91
|
-
require 'socket'
|
92
|
-
port = port.to_i
|
93
|
-
|
94
|
-
begin
|
95
|
-
server = TCPServer.new('0.0.0.0', port)
|
96
|
-
server.close
|
97
|
-
return port
|
98
|
-
rescue Errno::EADDRINUSE
|
99
|
-
port = port.to_i + 1 if port < max_port+1
|
100
|
-
retry
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
def error_logger(error_msg,prefix="",log_file=App.log_path)
|
106
|
-
|
107
|
-
###convert error msg to more human friendly one
|
108
|
-
begin
|
109
|
-
error_msg= error_msg.to_s.gsub('", "','",'+"\n\"")
|
110
|
-
rescue Exception
|
111
|
-
error_msg= error_msg.inspect.gsub('", "','",'+"\n\"")
|
112
|
-
end
|
113
|
-
|
114
|
-
if File.exists?(File.expand_path(log_file))
|
115
|
-
error_log = File.open( File.expand_path(log_file), "a+")
|
116
|
-
error_log << "\n#{Time.now} | #{prefix}#{":" if prefix != ""} #{error_msg}"
|
117
|
-
error_log.close
|
118
|
-
else
|
119
|
-
File.new(File.expand_path(log_file), "w").write(
|
120
|
-
"#{Time.now} | #{prefix}#{":" if prefix != ""} #{error_msg}"
|
121
|
-
)
|
122
|
-
end
|
123
|
-
|
124
|
-
return {:error => error_msg}
|
125
|
-
end
|
126
|
-
|
127
|
-
def load_ymls(directory,*args)
|
128
|
-
arg= Hash[*args]
|
129
|
-
|
130
|
-
require 'yaml'
|
131
|
-
#require "hashie"
|
132
|
-
|
133
|
-
arg[:monkey_patch]= 0 if arg[:monkey_patch].nil?
|
134
|
-
|
135
|
-
|
136
|
-
### GET Pre path + validation
|
137
|
-
begin
|
138
|
-
#get method callers path
|
139
|
-
pre_path = caller[arg[:monkey_patch].to_i].split('.rb:').first+('.rb')
|
140
|
-
if !pre_path.include?('/') && !pre_path.include?('\\')
|
141
|
-
pre_path = File.expand_path(pre_path)
|
142
|
-
end
|
143
|
-
separator_symbol= String.new
|
144
|
-
pre_path.include?('/') ? separator_symbol = '/' : separator_symbol = '\\'
|
145
|
-
pre_path= ((pre_path.split(separator_symbol))-([pre_path.split(separator_symbol).pop])).join(separator_symbol)
|
146
|
-
end
|
147
|
-
|
148
|
-
puts "Elements found in #{directory}" if $DEBUG
|
149
|
-
puts File.join("#{pre_path}","#{directory}","**","*.yml") if $DEBUG
|
150
|
-
puts Dir[File.join("#{pre_path}","#{directory}","**","*.yml")].sort.inspect if $DEBUG
|
151
|
-
|
152
|
-
yaml_files = Dir[File.join("#{pre_path}","#{directory}","**","*.yml")].sort
|
153
|
-
|
154
|
-
puts "\nyaml file found: "+yaml_files.inspect if $DEBUG
|
155
|
-
|
156
|
-
@result_hash = {}
|
157
|
-
yaml_files.each_with_index do |full_path_file_name|
|
158
|
-
|
159
|
-
|
160
|
-
file_name = full_path_file_name.split(separator_symbol).last.split(separator_symbol).first
|
161
|
-
|
162
|
-
hash_key = file_name
|
163
|
-
@result_hash[hash_key] = YAML.load(File.read("#{full_path_file_name}"))
|
164
|
-
|
165
|
-
#@result_hash = @result_hash.merge!(tmp_hash)
|
166
|
-
|
167
|
-
|
168
|
-
puts "==========================================================" if $DEBUG
|
169
|
-
puts "Loading "+file_name.to_s.capitalize+"\n" if $DEBUG
|
170
|
-
puts YAML.load(File.read("#{full_path_file_name}")) if $DEBUG
|
171
|
-
puts "__________________________________________________________" if $DEBUG
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" if $DEBUG
|
176
|
-
puts "The Main Hash: \n"+@result_hash.inspect.to_s if $DEBUG
|
177
|
-
puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" if $DEBUG
|
178
|
-
|
179
|
-
return @result_hash
|
180
|
-
end
|
181
|
-
|
182
|
-
def create_on_filesystem(route_name,optionable_file_mod="w",optionable_data=nil)
|
183
|
-
begin
|
184
|
-
|
185
|
-
#file_name generate
|
186
|
-
if !route_name.to_s.split('/').last.nil? || route_name.to_s.split('/').last != ''
|
187
|
-
file_name = route_name.to_s.split('/').last
|
188
|
-
else
|
189
|
-
file_name = nil?
|
190
|
-
end
|
191
|
-
|
192
|
-
#path_way
|
193
|
-
begin
|
194
|
-
raise ArgumentError, "missing route_name: #{route_name}" if route_name.nil?
|
195
|
-
path = File.expand_path(route_name).to_s.split('/')
|
196
|
-
path = path - [File.expand_path(route_name).to_s.split('/').last]
|
197
|
-
path.shift
|
198
|
-
end
|
199
|
-
|
200
|
-
#job
|
201
|
-
begin
|
202
|
-
if !Dir.exists?('/'+path.join('/'))
|
203
|
-
|
204
|
-
at_now = '/'
|
205
|
-
path.each do |dir_to_be_checked|
|
206
|
-
|
207
|
-
at_now += "#{dir_to_be_checked}/"
|
208
|
-
Dir.mkdir(at_now) if !Dir.exists?(at_now)
|
209
|
-
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
#file_create
|
215
|
-
File.new("/#{path.join('/')}/#{file_name}", optionable_file_mod ).write optionable_data
|
216
|
-
|
217
|
-
rescue Exception => ex
|
218
|
-
puts ex
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
def process_running?(input)
|
223
|
-
begin
|
224
|
-
Process.getpgid input.chomp.to_i
|
225
|
-
return true
|
226
|
-
rescue Exception
|
227
|
-
return false
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def clone_mpath(original_path,new_name)
|
232
|
-
log_path = File.expand_path(original_path)
|
233
|
-
log_path = log_path.split('/')
|
234
|
-
log_path.pop
|
235
|
-
log_path.push(new_name)
|
236
|
-
log_path = log_path.join('/')
|
237
|
-
|
238
|
-
return log_path
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
|
245
|
-
end
|
246
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'daemon-ogre'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|