rsence-pre 2.2.0.28 → 2.2.0.29
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.
- data/VERSION +1 -1
- data/conf/default_conf.yaml +8 -6
- data/conf/rsence_command_strings.yaml +8 -6
- data/lib/rsence.rb +4 -4
- data/lib/rsence/argv.rb +218 -0
- data/lib/rsence/argv/argv_util.rb +58 -0
- data/lib/rsence/argv/env_check.rb +58 -0
- data/lib/rsence/argv/help_argv.rb +15 -0
- data/lib/rsence/argv/initenv_argv.rb +218 -0
- data/lib/rsence/argv/save_argv.rb +92 -0
- data/lib/rsence/argv/startup_argv.rb +118 -0
- data/lib/rsence/argv/status_argv.rb +132 -0
- data/lib/rsence/argv/test_port.rb +32 -0
- data/lib/{daemon → rsence}/daemon.rb +21 -6
- data/lib/{conf/default.rb → rsence/default_config.rb} +0 -1
- data/lib/{plugins → rsence}/dependencies.rb +0 -0
- data/lib/{util → rsence}/gzstring.rb +0 -0
- data/lib/rsence/http.rb +3 -0
- data/lib/{http → rsence/http}/broker.rb +12 -3
- data/lib/{http → rsence/http}/rackup.rb +0 -0
- data/lib/{http → rsence/http}/request.rb +0 -4
- data/lib/{http → rsence/http}/response.rb +0 -1
- data/lib/{session → rsence}/msg.rb +1 -1
- data/lib/{plugins → rsence}/pluginmanager.rb +2 -2
- data/lib/{plugins → rsence}/plugins.rb +7 -7
- data/lib/{plugins → rsence/plugins}/gui_plugin.rb +0 -0
- data/lib/{plugins → rsence/plugins}/guiparser.rb +0 -0
- data/lib/{plugins → rsence/plugins}/plugin.rb +0 -0
- data/lib/{plugins → rsence/plugins}/plugin_base.rb +0 -0
- data/lib/{plugins → rsence/plugins}/plugin_plugins.rb +0 -0
- data/lib/{plugins → rsence/plugins}/plugin_sqlite_db.rb +0 -0
- data/lib/{plugins → rsence/plugins}/servlet.rb +0 -0
- data/lib/{session → rsence}/sessionmanager.rb +2 -2
- data/lib/{session → rsence}/sessionstorage.rb +1 -1
- data/lib/{daemon → rsence}/sigcomm.rb +0 -0
- data/lib/{transporter → rsence}/transporter.rb +3 -3
- data/lib/{values/hvalue.rb → rsence/value.rb} +0 -0
- data/lib/{values → rsence}/valuemanager.rb +1 -1
- metadata +100 -91
- data/lib/conf/argv.rb +0 -842
@@ -0,0 +1,218 @@
|
|
1
|
+
module RSence
|
2
|
+
module ArgvUtil
|
3
|
+
|
4
|
+
# asks y/n and returns booleans,
|
5
|
+
# the default tells if which one is for just enter
|
6
|
+
def yesno(default=false)
|
7
|
+
if default
|
8
|
+
question = "Y/n? "
|
9
|
+
else
|
10
|
+
question = "y/N? "
|
11
|
+
end
|
12
|
+
print question
|
13
|
+
answer = $stdin.gets.strip.downcase[0]
|
14
|
+
answer = answer.chr if answer
|
15
|
+
if answer == 'n'
|
16
|
+
return false
|
17
|
+
elsif answer == 'y'
|
18
|
+
return true
|
19
|
+
elsif answer == nil
|
20
|
+
return default
|
21
|
+
else
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# The initenv command and its parser. Asks questions about the environment before doing anything else.
|
27
|
+
def parse_initenv_argv
|
28
|
+
init_args
|
29
|
+
expect_option = false
|
30
|
+
option_name = false
|
31
|
+
valid_env = false
|
32
|
+
interactive = true
|
33
|
+
create_blank = false
|
34
|
+
if @argv.length >= 2
|
35
|
+
@argv[1..-1].each_with_index do |arg,i|
|
36
|
+
if expect_option
|
37
|
+
if [:port].include?(option_name) and arg.to_i.to_s != arg
|
38
|
+
puts ERB.new( @strs[:messages][:invalid_option_expected_number] ).result( binding )
|
39
|
+
exit
|
40
|
+
else
|
41
|
+
@args[option_name] = arg
|
42
|
+
end
|
43
|
+
expect_option = false
|
44
|
+
else
|
45
|
+
if arg.start_with?('--')
|
46
|
+
if arg == '--port'
|
47
|
+
expect_option = true
|
48
|
+
option_name = :port
|
49
|
+
elsif arg == '--addr'
|
50
|
+
expect_option = true
|
51
|
+
option_name = :addr
|
52
|
+
elsif arg == '--server'
|
53
|
+
expect_option = true
|
54
|
+
option_name = :server
|
55
|
+
elsif arg == '--title'
|
56
|
+
expect_option = true
|
57
|
+
option_name = :title
|
58
|
+
elsif arg == '--database'
|
59
|
+
expect_option = true
|
60
|
+
option_name = :db
|
61
|
+
elsif arg == '--uri-prefix'
|
62
|
+
expect_option = true
|
63
|
+
option_name = :base_url
|
64
|
+
elsif arg == '--blank'
|
65
|
+
create_blank = true
|
66
|
+
elsif arg == '--non-interactive'
|
67
|
+
interactive = false
|
68
|
+
else
|
69
|
+
invalid_option(arg)
|
70
|
+
end
|
71
|
+
elsif arg.start_with?('-')
|
72
|
+
arg.split('')[1..-1].each do |chr|
|
73
|
+
if chr == 'q'
|
74
|
+
interactive = false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
else
|
78
|
+
@args[:env_path] = File.expand_path(arg)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
if expect_option
|
83
|
+
puts ERB.new( @strs[:messages][:no_value_for_option] ).result( binding )
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
if valid_env?(@args[:env_path],true)
|
88
|
+
puts @strs[:initenv][:env_already_initialized]
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
92
|
+
if File.exists?(@args[:env_path])
|
93
|
+
env_empty = true # true while entries start with a dot
|
94
|
+
env_clear = true # true while entries don't contain RSence project files
|
95
|
+
env_entries = ['conf', 'db', 'log', 'plugins', 'run', 'README', 'VERSION']
|
96
|
+
Dir.entries(@args[:env_path]).each do |entry|
|
97
|
+
next if entry.start_with?('.')
|
98
|
+
env_empty = false
|
99
|
+
if env_entries.include? entry
|
100
|
+
env_clear = false
|
101
|
+
break
|
102
|
+
end
|
103
|
+
end
|
104
|
+
unless env_clear
|
105
|
+
puts ERB.new( @strs[:initenv][:env_not_clear] ).result( binding )
|
106
|
+
print @strs[:initenv][:continue_question]
|
107
|
+
exit unless yesno
|
108
|
+
end
|
109
|
+
unless env_empty
|
110
|
+
puts ERB.new( @strs[:initenv][:env_not_empty] ).result( binding )
|
111
|
+
print @strs[:initenv][:continue_question]
|
112
|
+
exit unless yesno
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
require 'rsence/default_config'
|
117
|
+
default_config = Configuration.new(@args,true).config
|
118
|
+
|
119
|
+
config = {
|
120
|
+
:base_url => (@args[:base_url] or default_config[:base_url]),
|
121
|
+
:http_server => {
|
122
|
+
:port => (@args[:port] or default_config[:http_server][:port]),
|
123
|
+
:bind_address => (@args[:addr] or default_config[:http_server][:bind_address]),
|
124
|
+
:rack_require => (@args[:server] or default_config[:http_server][:rack_require])
|
125
|
+
},
|
126
|
+
:index_html => {
|
127
|
+
:title => (@args[:title] or default_config[:index_html][:title])
|
128
|
+
},
|
129
|
+
:database => {
|
130
|
+
:ses_db => (@args[:db] or default_config[:database][:ses_db])
|
131
|
+
}
|
132
|
+
}
|
133
|
+
Signal.trap 'INT' do
|
134
|
+
puts
|
135
|
+
puts "Configuration aborted."
|
136
|
+
exit
|
137
|
+
end
|
138
|
+
if interactive
|
139
|
+
answers_ok = false
|
140
|
+
until answers_ok
|
141
|
+
puts ERB.new( @strs[:initenv][:creating_env] ).result( binding )
|
142
|
+
|
143
|
+
require 'highline/import'
|
144
|
+
|
145
|
+
say @strs[:initenv][:enter_title]
|
146
|
+
str_project_title = @strs[:initenv][:project_title]
|
147
|
+
config[:index_html][:title] = ask( str_project_title ) do |q|
|
148
|
+
q.default = config[:index_html][:title]
|
149
|
+
end
|
150
|
+
|
151
|
+
say @strs[:initenv][:enter_db_url]
|
152
|
+
str_db_url = @strs[:initenv][:db_url]
|
153
|
+
config[:database][:ses_db] = ask(str_db_url) do |q|
|
154
|
+
q.default = config[:database][:ses_db]
|
155
|
+
end
|
156
|
+
|
157
|
+
say @strs[:initenv][:enter_http_port]
|
158
|
+
str_http_port = @strs[:initenv][:http_port]
|
159
|
+
config[:http_server][:port] = ask(str_http_port) do |q|
|
160
|
+
q.default = config[:http_server][:port]
|
161
|
+
end
|
162
|
+
|
163
|
+
say @strs[:initenv][:enter_tcp_ip]
|
164
|
+
str_tcp_ip = @strs[:initenv][:tcp_ip]
|
165
|
+
config[:http_server][:bind_address] = ask(str_tcp_ip) do |q|
|
166
|
+
q.default = config[:http_server][:bind_address]
|
167
|
+
end
|
168
|
+
|
169
|
+
say @strs[:initenv][:enter_root_dir]
|
170
|
+
str_root_dir = @strs[:initenv][:root_dir]
|
171
|
+
config[:base_url] = ask(str_root_dir) do |q|
|
172
|
+
q.default = config[:base_url]
|
173
|
+
end
|
174
|
+
|
175
|
+
test_url = "http://#{config[:http_server][:bind_address]}:#{config[:http_server][:port]}#{config[:base_url]}"
|
176
|
+
say ERB.new( @strs[:initenv][:config_summary] ).result( binding )
|
177
|
+
print @strs[:initenv][:confirm_config]
|
178
|
+
answers_ok = yesno(true)
|
179
|
+
end
|
180
|
+
else
|
181
|
+
test_url = "http://#{config[:http_server][:bind_address]}:#{config[:http_server][:port]}#{config[:base_url]}"
|
182
|
+
end
|
183
|
+
|
184
|
+
puts @strs[:initenv][:creating_dirs]
|
185
|
+
env_dir = @args[:env_path]
|
186
|
+
require 'fileutils'
|
187
|
+
FileUtils.mkdir_p( env_dir ) unless File.exists?( env_dir )
|
188
|
+
conf_dir = File.expand_path( 'conf', env_dir )
|
189
|
+
Dir.mkdir( conf_dir )
|
190
|
+
db_dir = File.expand_path( 'db', env_dir )
|
191
|
+
Dir.mkdir( db_dir )
|
192
|
+
log_dir = File.expand_path( 'log', env_dir )
|
193
|
+
Dir.mkdir( log_dir )
|
194
|
+
plugins_dir = File.expand_path( 'plugins', env_dir )
|
195
|
+
Dir.mkdir( plugins_dir )
|
196
|
+
run_dir = File.expand_path( 'run', env_dir )
|
197
|
+
Dir.mkdir( run_dir )
|
198
|
+
unless create_blank
|
199
|
+
print @strs[:initenv][:install_welcome]
|
200
|
+
if yesno
|
201
|
+
welcome_plugin_dir = File.join( SERVER_PATH, 'setup', 'welcome' )
|
202
|
+
welcome_plugin_dst = File.join( plugins_dir, 'welcome' )
|
203
|
+
puts ERB.new( @strs[:initenv][:installing_welcome_plugin] ).result( binding )
|
204
|
+
FileUtils.cp_r( welcome_plugin_dir, welcome_plugin_dst )
|
205
|
+
end
|
206
|
+
end
|
207
|
+
puts @strs[:initenv][:creating_files]
|
208
|
+
conf_file = File.join( conf_dir, 'config.yaml' )
|
209
|
+
File.open( conf_file, 'w' ) {|f| f.write( YAML.dump( config ) ) }
|
210
|
+
readme_file = File.join( env_dir, 'README' )
|
211
|
+
File.open( readme_file, 'w' ) {|f| f.write( ERB.new( @strs[:initenv][:readme] ).result( binding ) ) }
|
212
|
+
version_file = File.join( env_dir, 'VERSION' )
|
213
|
+
File.open( version_file, 'w' ) {|f| f.write( "RSence Environment Version #{version.to_f}" ) }
|
214
|
+
puts ERB.new( @strs[:initenv][:congratulations] ).result( binding )
|
215
|
+
exit
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module RSence
|
2
|
+
module ArgvUtil
|
3
|
+
# Main argument parser for the save command. Sends the USR1 POSIX signal to the process, if running.
|
4
|
+
def parse_save_argv
|
5
|
+
init_args
|
6
|
+
expect_option = false
|
7
|
+
option_name = false
|
8
|
+
if @argv.length >= 2
|
9
|
+
@argv[1..-1].each_with_index do |arg,i|
|
10
|
+
if expect_option
|
11
|
+
if option_name == :conf_files
|
12
|
+
if not File.exists?( arg ) or not File.file?( arg )
|
13
|
+
puts ERB.new( @strs[:messages][:no_such_configuration_file] ).result( binding )
|
14
|
+
exit
|
15
|
+
else
|
16
|
+
@args[:conf_files].push( arg )
|
17
|
+
end
|
18
|
+
else
|
19
|
+
@args[option_name] = arg
|
20
|
+
end
|
21
|
+
expect_option = false
|
22
|
+
else
|
23
|
+
if arg.start_with?('--')
|
24
|
+
if arg == '--debug'
|
25
|
+
set_debug
|
26
|
+
elsif arg == '--verbose'
|
27
|
+
set_verbose
|
28
|
+
elsif arg == '--conf' or arg == '--config'
|
29
|
+
expect_option = true
|
30
|
+
option_name = :conf_files
|
31
|
+
else
|
32
|
+
invalid_option(arg)
|
33
|
+
end
|
34
|
+
elsif arg.start_with?('-')
|
35
|
+
arg.split('')[1..-1].each do |chr|
|
36
|
+
if chr == 'd'
|
37
|
+
set_debug
|
38
|
+
elsif chr == 'v'
|
39
|
+
set_verbose
|
40
|
+
else
|
41
|
+
invalid_option(arg,chr)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
elsif valid_env?(arg)
|
45
|
+
@args[:env_path] = File.expand_path(arg)
|
46
|
+
@args[:conf_files].unshift( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
47
|
+
else
|
48
|
+
invalid_env( arg )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if expect_option
|
53
|
+
puts ERB.new( @strs[:messages][:no_value_for_option] ).result( binding )
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
end
|
57
|
+
if valid_env?(@args[:env_path])
|
58
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
59
|
+
@args[:conf_files].unshift( conf_file ) unless @args[:conf_files].include?( conf_file )
|
60
|
+
else
|
61
|
+
invalid_env
|
62
|
+
end
|
63
|
+
require 'rsence/default_config'
|
64
|
+
config = Configuration.new(@args).config
|
65
|
+
if RSence.pid_support?
|
66
|
+
pid_fn = config[:daemon][:pid_fn]
|
67
|
+
if File.exists?( pid_fn )
|
68
|
+
pid = File.read( pid_fn ).to_i
|
69
|
+
saving_message = @strs[:messages][:saving_message]
|
70
|
+
pid_status = RSence::SIGComm.wait_signal_response(
|
71
|
+
pid, pid_fn, 'USR2', 30, saving_message, '.', 0.1, true
|
72
|
+
)
|
73
|
+
else
|
74
|
+
warn @strs[:messages][:no_pid_file] if @args[:verbose]
|
75
|
+
pid_status = nil
|
76
|
+
end
|
77
|
+
else
|
78
|
+
warn @strs[:messages][:no_pid_support] if @args[:verbose]
|
79
|
+
pid_status = nil
|
80
|
+
end
|
81
|
+
if RSence.pid_support?
|
82
|
+
if pid_status == nil
|
83
|
+
puts @strs[:messages][:no_pid_unable_to_save]
|
84
|
+
elsif pid_status == false
|
85
|
+
puts @strs[:messages][:no_process_running]
|
86
|
+
else
|
87
|
+
puts @strs[:messages][:session_data_saved]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module RSence
|
2
|
+
module ArgvUtil
|
3
|
+
|
4
|
+
# Main argument parser for all 'start' -type commands.
|
5
|
+
def parse_startup_argv
|
6
|
+
init_args
|
7
|
+
expect_option = false
|
8
|
+
option_name = false
|
9
|
+
if @argv.length >= 2
|
10
|
+
@argv[1..-1].each_with_index do |arg,i|
|
11
|
+
if expect_option
|
12
|
+
if [ :port, :latency, :http_delayed_start ].include?(option_name) and arg.to_i.to_s != arg
|
13
|
+
puts ERB.new( @strs[:messages][:invalid_option_expected_number] ).result( binding )
|
14
|
+
exit
|
15
|
+
elsif option_name == :conf_files
|
16
|
+
if not File.exists?( arg ) or not File.file?( arg )
|
17
|
+
puts ERB.new( @strs[:messages][:no_such_configuration_file] ).result( binding )
|
18
|
+
exit
|
19
|
+
else
|
20
|
+
@args[:conf_files].push( arg )
|
21
|
+
end
|
22
|
+
elsif option_name == :http_delayed_start
|
23
|
+
@args[:http_delayed_start] = arg.to_i
|
24
|
+
else
|
25
|
+
arg = arg.to_i if option_name == :latency
|
26
|
+
@args[option_name] = arg
|
27
|
+
end
|
28
|
+
expect_option = false
|
29
|
+
else
|
30
|
+
if arg.start_with?('--')
|
31
|
+
if arg == '--profile'
|
32
|
+
true
|
33
|
+
elsif arg == '--debug'
|
34
|
+
set_debug
|
35
|
+
elsif arg == '--verbose'
|
36
|
+
set_verbose
|
37
|
+
elsif arg == '--log-fg'
|
38
|
+
set_log_fg
|
39
|
+
elsif arg == '--trace-js'
|
40
|
+
@args[:trace_js] = true
|
41
|
+
elsif arg == '--trace-delegate'
|
42
|
+
@args[:trace_delegate] = true
|
43
|
+
elsif arg == '--port'
|
44
|
+
expect_option = true
|
45
|
+
option_name = :port
|
46
|
+
elsif arg == '--addr' or arg == '--bind'
|
47
|
+
expect_option = true
|
48
|
+
option_name = :addr
|
49
|
+
elsif arg == '--http-delayed-start' or arg == '--delayed-start'
|
50
|
+
expect_option = true
|
51
|
+
option_name = :http_delayed_start
|
52
|
+
elsif arg == '--server'
|
53
|
+
expect_option = true
|
54
|
+
option_name = :server
|
55
|
+
elsif arg == '--conf' or arg == '--config'
|
56
|
+
expect_option = true
|
57
|
+
option_name = :conf_files
|
58
|
+
elsif arg == '--reset-sessions'
|
59
|
+
set_reset_ses
|
60
|
+
elsif arg == '--auto-update'
|
61
|
+
set_autoupdate
|
62
|
+
elsif arg == '--latency'
|
63
|
+
expect_option = true
|
64
|
+
option_name = :latency
|
65
|
+
elsif arg == '--say'
|
66
|
+
set_say
|
67
|
+
elsif arg == '--disable-gzip'
|
68
|
+
@args[:client_pkg_no_gzip] = true
|
69
|
+
elsif arg == '--disable-obfuscation'
|
70
|
+
@args[:client_pkg_no_obfuscation] = true
|
71
|
+
elsif arg == '--disable-jsmin'
|
72
|
+
@args[:client_pkg_no_whitespace_removel] = true
|
73
|
+
elsif arg == '--build-report'
|
74
|
+
@args[:suppress_build_messages] = false
|
75
|
+
else
|
76
|
+
invalid_option(arg)
|
77
|
+
end
|
78
|
+
elsif arg.start_with?('-')
|
79
|
+
arg.split('')[1..-1].each do |chr|
|
80
|
+
if chr == 'd'
|
81
|
+
set_debug
|
82
|
+
elsif chr == 'v'
|
83
|
+
set_verbose
|
84
|
+
elsif chr == 'f'
|
85
|
+
set_log_fg
|
86
|
+
elsif chr == 'r'
|
87
|
+
set_reset_ses
|
88
|
+
elsif chr == 'a'
|
89
|
+
set_autoupdate
|
90
|
+
elsif chr == 'S'
|
91
|
+
set_say
|
92
|
+
else
|
93
|
+
invalid_option(arg,chr)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
elsif valid_env?(arg)
|
97
|
+
@args[:env_path] = File.expand_path(arg)
|
98
|
+
@args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
99
|
+
else
|
100
|
+
invalid_env( arg )
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
if expect_option
|
105
|
+
puts ERB.new( @strs[:messages][:no_value_for_option] ).result( binding )
|
106
|
+
exit
|
107
|
+
end
|
108
|
+
end
|
109
|
+
if valid_env?(@args[:env_path])
|
110
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
111
|
+
@args[:conf_files].unshift( conf_file ) unless @args[:conf_files].include?( conf_file )
|
112
|
+
else
|
113
|
+
invalid_env
|
114
|
+
end
|
115
|
+
@startable = true
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module RSence
|
2
|
+
module ArgvUtil
|
3
|
+
# Main argument parser for the status command, sends the INFO (or PWR on linux) POSIX signal to
|
4
|
+
# the process, if running.
|
5
|
+
# Checks if the process responds on the port and address it's configured for.
|
6
|
+
def parse_status_argv
|
7
|
+
init_args
|
8
|
+
expect_option = false
|
9
|
+
option_name = false
|
10
|
+
if @argv.length >= 2
|
11
|
+
@argv[1..-1].each_with_index do |arg,i|
|
12
|
+
if expect_option
|
13
|
+
if [:port].include?(option_name) and arg.to_i.to_s != arg
|
14
|
+
puts ERB.new( @strs[:messages][:invalid_option_expected_number] ).result( binding )
|
15
|
+
exit
|
16
|
+
elsif option_name == :conf_files
|
17
|
+
if not File.exists?( arg ) or not File.file?( arg )
|
18
|
+
puts ERB.new( @strs[:messages][:no_such_configuration_file] ).result( binding )
|
19
|
+
exit
|
20
|
+
else
|
21
|
+
@args[:conf_files].push( arg )
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@args[option_name] = arg
|
25
|
+
end
|
26
|
+
expect_option = false
|
27
|
+
else
|
28
|
+
if arg.start_with?('--')
|
29
|
+
if arg == '--debug'
|
30
|
+
set_debug
|
31
|
+
elsif arg == '--verbose'
|
32
|
+
set_verbose
|
33
|
+
elsif arg == '--port'
|
34
|
+
expect_option = true
|
35
|
+
option_name = :port
|
36
|
+
elsif arg == '--addr'
|
37
|
+
expect_option = true
|
38
|
+
option_name = :addr
|
39
|
+
elsif arg == '--conf' or arg == '--config'
|
40
|
+
expect_option = true
|
41
|
+
option_name = :conf_files
|
42
|
+
else
|
43
|
+
invalid_option(arg)
|
44
|
+
end
|
45
|
+
elsif arg.start_with?('-')
|
46
|
+
arg.split('')[1..-1].each do |chr|
|
47
|
+
if chr == 'd'
|
48
|
+
set_debug
|
49
|
+
elsif chr == 'v'
|
50
|
+
set_verbose
|
51
|
+
else
|
52
|
+
invalid_option(arg,chr)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
elsif valid_env?(arg)
|
56
|
+
@args[:env_path] = File.expand_path(arg)
|
57
|
+
@args[:conf_files].unshift( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
58
|
+
else
|
59
|
+
invalid_env( arg )
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
if expect_option
|
64
|
+
puts ERB.new( @strs[:messages][:no_value_for_option] ).result( binding )
|
65
|
+
exit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
if valid_env?(@args[:env_path])
|
69
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
70
|
+
@args[:conf_files].unshift( conf_file ) unless @args[:conf_files].include?( conf_file )
|
71
|
+
else
|
72
|
+
invalid_env
|
73
|
+
end
|
74
|
+
require 'rsence/default_config'
|
75
|
+
require 'socket'
|
76
|
+
config = Configuration.new(@args).config
|
77
|
+
port = config[:http_server][:port]
|
78
|
+
addr = config[:http_server][:bind_address]
|
79
|
+
port_status = []
|
80
|
+
if addr == '0.0.0.0' and Socket.respond_to?(:ip_address_list)
|
81
|
+
Socket.ip_address_list.each do |if_addr|
|
82
|
+
if test_port( port, if_addr.ip_address )
|
83
|
+
port_status.push( if_addr.ip_address )
|
84
|
+
end
|
85
|
+
end
|
86
|
+
else
|
87
|
+
port_status.push( addr )
|
88
|
+
end
|
89
|
+
addr_descr = port_status.join(":#{port}, ")+":#{port}"
|
90
|
+
if RSence.pid_support?
|
91
|
+
pid_fn = config[:daemon][:pid_fn]
|
92
|
+
if File.exists?( pid_fn )
|
93
|
+
pid = File.read( pid_fn ).to_i
|
94
|
+
sig_name = RSence.info_signal_name
|
95
|
+
pid_status = RSence::SIGComm.wait_signal_response(
|
96
|
+
pid, pid_fn, sig_name, 3
|
97
|
+
)
|
98
|
+
else
|
99
|
+
warn @strs[:messages][:no_pid_file] if @args[:verbose]
|
100
|
+
pid_status = nil
|
101
|
+
end
|
102
|
+
else
|
103
|
+
warn @strs[:messages][:no_pid_support] if @args[:verbose]
|
104
|
+
pid_status = nil
|
105
|
+
end
|
106
|
+
addr_descr = port_status.join(":#{port} and ")+":#{port}" unless port_status.empty?
|
107
|
+
if not RSence.pid_support? or pid_status == nil
|
108
|
+
if RSence.pid_support?
|
109
|
+
puts @strs[:messages][:no_pid]
|
110
|
+
else
|
111
|
+
puts @strs[:messages][:no_pid_support]
|
112
|
+
end
|
113
|
+
unless port_status.empty?
|
114
|
+
puts ERB.new( @strs[:messages][:something_responds] ).result( binding )
|
115
|
+
end
|
116
|
+
elsif pid_status == false
|
117
|
+
if port_status.empty?
|
118
|
+
puts ERB.new( @strs[:messages][:no_process_running_and_nothing_responds] ).result( binding )
|
119
|
+
else
|
120
|
+
puts ERB.new( @strs[:messages][:no_process_running_but_something_responds] ).result( binding )
|
121
|
+
end
|
122
|
+
else
|
123
|
+
if port_status.empty?
|
124
|
+
puts ERB.new( @strs[:messages][:process_running_but_nothing_responds] ).result( binding )
|
125
|
+
else
|
126
|
+
addr_descr = port_status.join(":#{port} and ")+":#{port}"
|
127
|
+
puts ERB.new( @strs[:messages][:process_running_and_responds] ).result( binding )
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|