procemon 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +5 -0
- data/.gitignore +9 -0
- data/Gemfile.lock +5 -5
- data/README.md +63 -46
- data/VERSION +1 -1
- data/examples/test.rb +48 -0
- data/lib/procemon.rb +4 -38
- data/lib/procemon/eval.rb +75 -0
- data/lib/procemon/{function/meta/inject_methods.rb → hooks.rb} +2 -2
- data/procemon.gemspec +4 -8
- data/test/test.rb +28 -2
- metadata +12 -31
- data/examples/how_to_inject_with_extra_process_a_method.rb +0 -38
- data/examples/require_files.rb +0 -3
- data/files.rb +0 -24
- data/lib/procemon/extra/sender.rb +0 -30
- data/lib/procemon/extra/str2duck.rb +0 -7
- data/lib/procemon/function/application.rb +0 -27
- data/lib/procemon/function/argv.rb +0 -78
- data/lib/procemon/function/daemon.rb +0 -188
- data/lib/procemon/function/documentation.rb +0 -14
- data/lib/procemon/function/file.rb +0 -67
- data/lib/procemon/function/generate.rb +0 -202
- data/lib/procemon/function/macaddr.rb +0 -97
- data/lib/procemon/function/meta/eval.rb +0 -76
- data/lib/procemon/function/name.rb +0 -13
- data/lib/procemon/function/port.rb +0 -35
- data/lib/procemon/function/tmp_dir.rb +0 -21
- data/lib/procemon/process.rb +0 -17
@@ -1,202 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
|
3
|
-
# gives you a basic meta load framework for easy config use (yaml)
|
4
|
-
# basic system is
|
5
|
-
#
|
6
|
-
# root folder:
|
7
|
-
# - config
|
8
|
-
# -| "YAML files" #> development.yaml
|
9
|
-
#
|
10
|
-
# - lib
|
11
|
-
# -- module_name
|
12
|
-
# --- meta
|
13
|
-
# ---| "YAML files" #> rack.yaml
|
14
|
-
#
|
15
|
-
def metaloader_framework(opts={})
|
16
|
-
|
17
|
-
# defaults
|
18
|
-
begin
|
19
|
-
|
20
|
-
root_folder = opts[:root]
|
21
|
-
override = opts[:override]
|
22
|
-
target_config_hash = opts[:config]
|
23
|
-
lib_folder = opts[:lib_folder]
|
24
|
-
config_folder = opts[:config_folder]
|
25
|
-
|
26
|
-
|
27
|
-
override ||= true
|
28
|
-
root_folder ||= Dir.pwd
|
29
|
-
target_config_hash ||= Application.config
|
30
|
-
|
31
|
-
lib_folder ||= File.join(root_folder,"{lib,libs}","**","meta")
|
32
|
-
config_folder ||= File.join(root_folder,"{config,conf}","**")
|
33
|
-
|
34
|
-
require "yaml"
|
35
|
-
if target_config_hash.class != Hash
|
36
|
-
target_config_hash= Hash.new()
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
# find elements
|
42
|
-
begin
|
43
|
-
|
44
|
-
Dir.glob(File.join(lib_folder,"*.{yaml,yml}")).each do |config_object|
|
45
|
-
|
46
|
-
# defaults
|
47
|
-
begin
|
48
|
-
config_name_elements= config_object.split(File::SEPARATOR)
|
49
|
-
type= config_name_elements.pop.split('.')[0]
|
50
|
-
config_name_elements.pop
|
51
|
-
|
52
|
-
category = config_name_elements.pop
|
53
|
-
tmp_hash = Hash.new()
|
54
|
-
yaml_data = YAML.load(File.open(config_object))
|
55
|
-
end
|
56
|
-
|
57
|
-
# processing
|
58
|
-
begin
|
59
|
-
if target_config_hash[category].nil?
|
60
|
-
target_config_hash[category]= { type => yaml_data }
|
61
|
-
else
|
62
|
-
unless override == false
|
63
|
-
target_config_hash[category][type]= yaml_data
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
# update by config
|
73
|
-
begin
|
74
|
-
|
75
|
-
# get config files
|
76
|
-
begin
|
77
|
-
|
78
|
-
config_yaml_paths= Array.new()
|
79
|
-
Dir.glob(File.join(config_folder,"*.{yaml,yml}")).uniq.each do |one_path|
|
80
|
-
|
81
|
-
case true
|
82
|
-
|
83
|
-
when one_path.downcase.include?('default')
|
84
|
-
config_yaml_paths[0]= one_path
|
85
|
-
|
86
|
-
when one_path.downcase.include?('development')
|
87
|
-
config_yaml_paths[1]= one_path
|
88
|
-
|
89
|
-
when one_path.downcase.include?('test')
|
90
|
-
config_yaml_paths[2]= one_path
|
91
|
-
|
92
|
-
when one_path.downcase.include?('production')
|
93
|
-
config_yaml_paths[3]= one_path
|
94
|
-
|
95
|
-
else
|
96
|
-
config_yaml_paths[config_yaml_paths.count]= one_path
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
config_yaml_paths.select!{|x| x != nil }
|
102
|
-
end
|
103
|
-
|
104
|
-
# params config load
|
105
|
-
unless Application.config_file.nil?
|
106
|
-
begin
|
107
|
-
path= File.expand_path(Application.config_file,"r")
|
108
|
-
File.open(path)
|
109
|
-
config_yaml_paths.push(path)
|
110
|
-
rescue Exception
|
111
|
-
config_yaml_paths.push(Application.config_file)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# load to last lvl environment
|
116
|
-
begin
|
117
|
-
config_yaml_paths.each do |one_yaml_file_path|
|
118
|
-
begin
|
119
|
-
yaml_data= YAML.load(File.open(one_yaml_file_path))
|
120
|
-
target_config_hash.deep_merge!(yaml_data)
|
121
|
-
|
122
|
-
unless Application.environment.nil?
|
123
|
-
if one_yaml_file_path.include?(Application.environment.to_s)
|
124
|
-
break
|
125
|
-
end
|
126
|
-
end
|
127
|
-
rescue Exception
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
return target_config_hash
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
alias :generate_config :metaloader_framework
|
139
|
-
alias :metaload_framework :metaloader_framework
|
140
|
-
|
141
|
-
def generate_documentation(
|
142
|
-
target_folder = File.join(Dir.pwd,"docs"),
|
143
|
-
keyword= "gen",
|
144
|
-
create_doc_bool = Application.doc)
|
145
|
-
|
146
|
-
if create_doc_bool == true
|
147
|
-
|
148
|
-
Dir.glob(File.join(Dir.pwd,'{doc,docs,document,documents}','**',"*_#{keyword}.{rb,ru}")).each do |one_doc_generator|
|
149
|
-
require one_doc_generator
|
150
|
-
end
|
151
|
-
puts "done!"
|
152
|
-
|
153
|
-
Process.exit
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
def get_meta_config(target_folder= File.join(Dir.pwd,"lib","**","meta") )
|
160
|
-
|
161
|
-
# defaults
|
162
|
-
begin
|
163
|
-
require "yaml"
|
164
|
-
target_config_hash= Hash.new()
|
165
|
-
end
|
166
|
-
|
167
|
-
# find elements
|
168
|
-
begin
|
169
|
-
|
170
|
-
Dir.glob(File.join(target_folder,"*.{yaml,yml}")).each do |config_object|
|
171
|
-
|
172
|
-
# defaults
|
173
|
-
begin
|
174
|
-
config_name_elements= config_object.split(File::SEPARATOR)
|
175
|
-
type= config_name_elements.pop.split('.')[0]
|
176
|
-
config_name_elements.pop
|
177
|
-
category= config_name_elements.pop
|
178
|
-
tmp_hash= Hash.new()
|
179
|
-
yaml_data= YAML.load(File.open(config_object))
|
180
|
-
end
|
181
|
-
|
182
|
-
# processing
|
183
|
-
begin
|
184
|
-
if target_config_hash[category].nil?
|
185
|
-
target_config_hash[category]= { type => yaml_data }
|
186
|
-
else
|
187
|
-
target_config_hash[category][type]= yaml_data
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
# return data
|
196
|
-
begin
|
197
|
-
return target_config_hash
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Cross platform MAC address determination. Works for:
|
3
|
-
# * /sbin/ifconfig
|
4
|
-
# * /bin/ifconfig
|
5
|
-
# * ifconfig
|
6
|
-
# * ipconfig /all
|
7
|
-
#
|
8
|
-
# To return the first MAC address on the system:
|
9
|
-
#
|
10
|
-
# Mac.address
|
11
|
-
#
|
12
|
-
# To return an array of all MAC addresses:
|
13
|
-
#
|
14
|
-
# Mac.address.list
|
15
|
-
#
|
16
|
-
#begin
|
17
|
-
# require 'rubygems'
|
18
|
-
# require 'systemu'
|
19
|
-
#rescue LoadError
|
20
|
-
# nil
|
21
|
-
#end
|
22
|
-
|
23
|
-
|
24
|
-
module Mac
|
25
|
-
|
26
|
-
VERSION = '1.6.1'
|
27
|
-
|
28
|
-
def Mac.version
|
29
|
-
::Mac::VERSION
|
30
|
-
end
|
31
|
-
|
32
|
-
def Mac.dependencies
|
33
|
-
{
|
34
|
-
'systemu' => [ 'systemu' , '~> 2.5.0' ]
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
class << self
|
40
|
-
|
41
|
-
#
|
42
|
-
# Accessor for the system's first MAC address, requires a call to #address
|
43
|
-
# first
|
44
|
-
|
45
|
-
attr_accessor "mac_address"
|
46
|
-
|
47
|
-
#
|
48
|
-
# Discovers and returns the system's MAC addresses. Returns the first
|
49
|
-
# MAC address, and includes an accessor #list for the remaining addresses:
|
50
|
-
#
|
51
|
-
# Mac.addr # => first address
|
52
|
-
# Mac.addr.list # => all addresses
|
53
|
-
|
54
|
-
def address
|
55
|
-
return @mac_address if defined? @mac_address and @mac_address
|
56
|
-
re = %r/[^:\-](?:[0-9A-F][0-9A-F][:\-]){5}[0-9A-F][0-9A-F][^:\-]/io
|
57
|
-
cmds = '/sbin/ifconfig', '/bin/ifconfig', 'ifconfig', 'ipconfig /all', 'cat /sys/class/net/*/address'
|
58
|
-
|
59
|
-
null = test(?e, '/dev/null') ? '/dev/null' : 'NUL'
|
60
|
-
|
61
|
-
output = nil
|
62
|
-
cmds.each do |cmd|
|
63
|
-
status, stdout, stderr = systemu(cmd) rescue next
|
64
|
-
next unless stdout and stdout.size > 0
|
65
|
-
output = stdout and break
|
66
|
-
end
|
67
|
-
raise "all of #{ cmds.join ' ' } failed" unless output
|
68
|
-
|
69
|
-
@mac_address = parse(output)
|
70
|
-
end
|
71
|
-
|
72
|
-
def parse(output)
|
73
|
-
lines = output.split(/\n/)
|
74
|
-
|
75
|
-
candidates = lines.select{|line| line =~ RE}
|
76
|
-
raise 'no mac address candidates' unless candidates.first
|
77
|
-
candidates.map!{|c| c[RE].strip}
|
78
|
-
|
79
|
-
maddr = candidates.first
|
80
|
-
raise 'no mac address found' unless maddr
|
81
|
-
|
82
|
-
maddr.strip!
|
83
|
-
maddr.instance_eval{ @list = candidates; def list() @list end }
|
84
|
-
maddr
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
# Shorter alias for #address
|
89
|
-
|
90
|
-
alias_method "addr", "address"
|
91
|
-
end
|
92
|
-
|
93
|
-
RE = %r/(?:[^:\-]|\A)(?:[0-9A-F][0-9A-F][:\-]){5}[0-9A-F][0-9A-F](?:[^:\-]|\Z)/io
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
MacAddr = Macaddr = Mac
|
@@ -1,76 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
|
3
|
-
# safe_eval(string [, binding [, filename [,lineno]]] *allowed_class/module_names ) -> obj
|
4
|
-
#
|
5
|
-
# Evaluates the Ruby expression(s) in <em>string</em>. If
|
6
|
-
# <em>binding</em> is given, which must be a <code>Binding</code>
|
7
|
-
# object, the evaluation is performed in its context. If the
|
8
|
-
# optional <em>filename</em> and <em>lineno</em> parameters are
|
9
|
-
# present, they will be used when reporting syntax errors.
|
10
|
-
#
|
11
|
-
# def get_binding(str)
|
12
|
-
# return binding
|
13
|
-
# end
|
14
|
-
# str = "hello"
|
15
|
-
# safe_eval "str + ' Fred'" ,Kernel #=> "hello Fred"
|
16
|
-
# safe_eval "str + ' Fred'", get_binding("bye") ,Kernel #=> "bye Fred"
|
17
|
-
def safe_eval(*args)
|
18
|
-
|
19
|
-
# defaults
|
20
|
-
begin
|
21
|
-
allowed= Array.new
|
22
|
-
eval_exception= String.new
|
23
|
-
tmp_array= nil
|
24
|
-
end
|
25
|
-
|
26
|
-
# separate allowed names
|
27
|
-
begin
|
28
|
-
tmp_array= Array.new
|
29
|
-
args.each do |argument|
|
30
|
-
case argument.class.to_s.downcase
|
31
|
-
|
32
|
-
when "class","module"
|
33
|
-
begin
|
34
|
-
allowed.push argument
|
35
|
-
end
|
36
|
-
|
37
|
-
else
|
38
|
-
begin
|
39
|
-
tmp_array.push argument
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
args= tmp_array
|
45
|
-
end
|
46
|
-
|
47
|
-
# build exception list to eval
|
48
|
-
begin
|
49
|
-
allowed.each do |one_name|
|
50
|
-
eval_exception += "|"+one_name.to_s
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# trim un wanted elements from string
|
55
|
-
begin
|
56
|
-
args.each do |argument|
|
57
|
-
case argument.class.to_s.downcase
|
58
|
-
|
59
|
-
when "string"
|
60
|
-
begin
|
61
|
-
#TODO new regex! # /(\b|\.|\{|\>)[A-Z]\w*/
|
62
|
-
#args[args.index(argument)]= argument.gsub( /(\b|\.|\{|\>)[A-Z]\w*/ ,'')
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# do save eval
|
70
|
-
begin
|
71
|
-
eval(*args)
|
72
|
-
end
|
73
|
-
|
74
|
-
end if $DEBUG == true
|
75
|
-
|
76
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Procemon
|
2
|
-
class << self
|
3
|
-
|
4
|
-
def get_port(mint_port,max_port,host="0.0.0.0")
|
5
|
-
|
6
|
-
require 'socket'
|
7
|
-
mint_port= mint_port.to_i
|
8
|
-
begin
|
9
|
-
server = TCPServer.new(host, mint_port)
|
10
|
-
server.close
|
11
|
-
return mint_port
|
12
|
-
rescue Errno::EADDRINUSE
|
13
|
-
if mint_port < max_port
|
14
|
-
pmint_portort = (mint_port.to_i + 1)
|
15
|
-
retry
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def port_open?(port,host="0.0.0.0")
|
22
|
-
|
23
|
-
require 'socket'
|
24
|
-
begin
|
25
|
-
server = TCPServer.new(host, port.to_i)
|
26
|
-
server.close
|
27
|
-
return true
|
28
|
-
rescue Errno::EADDRINUSE
|
29
|
-
return false
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Procemon
|
2
|
-
class << self
|
3
|
-
|
4
|
-
require "tmpdir"
|
5
|
-
def tmpdir_init
|
6
|
-
|
7
|
-
begin
|
8
|
-
Dir.mkdir File.join(Dir.tmpdir,$0)
|
9
|
-
rescue Errno::EEXIST
|
10
|
-
end
|
11
|
-
|
12
|
-
Application.tmpdir= File.join(Dir.tmpdir,$0)
|
13
|
-
|
14
|
-
Application.pid= File.join(Application.tmpdir,"pid")
|
15
|
-
Application.log= File.join(Application.tmpdir,"log")
|
16
|
-
Application.daemon_stderr= File.join(Application.tmpdir,"daemon_stderr")
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|