lib/conf/argv.rb in rsence-2.0.0.2.pre vs lib/conf/argv.rb in rsence-2.0.0.3.pre
- old
+ new
@@ -221,10 +221,17 @@
#{@@cmd_help[:path]}
EOF
+@@cmd_help[:version] = <<-EOF
+usage: 'rsence version'
+
+The 'version' command simply outputs the version number of RSence.
+
+EOF
+
@@cmd_help[:tail] = <<-EOF
RSence is a self-contained rich internet application client-server framework.
For further information, see http://rsence.org/
EOF
@@ -272,11 +279,11 @@
option_name = false
if @argv.length >= 2
@argv[1..-1].each_with_index do |arg,i|
if expect_option
if [:port,:latency].include?(option_name) and arg.to_i.to_s != arg
- puts "invalid #{option_nam.to_s}, expected number: #{arg.inspect}"
+ puts "invalid #{option_name.to_s}, expected number: #{arg.inspect}"
puts "Type 'rsence help #{@cmd.to_s}' for usage."
exit
elsif option_name == :conf_files
if not File.exists?( arg ) or not File.file?( arg )
puts "no such configuration file: #{arg.inspect}"
@@ -472,12 +479,12 @@
expect_option = false
option_name = false
if @argv.length >= 2
@argv[1..-1].each_with_index do |arg,i|
if expect_option
- if [:port,:latency].include?(option_name) and arg.to_i.to_s != arg
- puts "invalid #{option_nam.to_s}, expected number: #{arg.inspect}"
+ if [:port].include?(option_name) and arg.to_i.to_s != arg
+ puts "invalid #{option_name.to_s}, expected number: #{arg.inspect}"
puts "Type 'rsence help #{@cmd.to_s}' for usage."
exit
elsif option_name == :conf_files
if not File.exists?( arg ) or not File.file?( arg )
puts "no such configuration file: #{arg.inspect}"
@@ -500,13 +507,10 @@
expect_option = true
option_name = :port
elsif arg == '--addr'
expect_option = true
option_name = :addr
- elsif arg == '--server'
- expect_option = true
- option_name = :server
elsif arg == '--conf' or arg == '--config'
expect_option = true
option_name = :conf_files
else
invalid_option(arg)
@@ -578,15 +582,11 @@
expect_option = false
option_name = false
if @argv.length >= 2
@argv[1..-1].each_with_index do |arg,i|
if expect_option
- if [:port,:latency].include?(option_name) and arg.to_i.to_s != arg
- puts "invalid #{option_nam.to_s}, expected number: #{arg.inspect}"
- puts "Type 'rsence help #{@cmd.to_s}' for usage."
- exit
- elsif option_name == :conf_files
+ if option_name == :conf_files
if not File.exists?( arg ) or not File.file?( arg )
puts "no such configuration file: #{arg.inspect}"
puts "Type 'rsence help #{@cmd.to_s}' for usage."
exit
else
@@ -670,11 +670,89 @@
def parse_setup_argv
throw "parse_setup_argv not implemented!"
end
def parse_initenv_argv
- throw "parse_initenv_argv not implemented!"
+ init_args
+ expect_option = false
+ option_name = false
+ valid_env
+ if @argv.length >= 2
+ @argv[1..-1].each_with_index do |arg,i|
+ if expect_option
+ if [:port].include?(option_name) and arg.to_i.to_s != arg
+ puts "invalid #{option_name.to_s}, expected number: #{arg.inspect}"
+ puts "Type 'rsence help #{@cmd.to_s}' for usage."
+ exit
+ else
+ @args[option_name] = arg
+ end
+ expect_option = false
+ else
+ if arg.start_with?('--')
+ if arg == '--port'
+ expect_option = true
+ option_name = :port
+ elsif arg == '--addr'
+ expect_option = true
+ option_name = :addr
+ elsif arg == '--server'
+ expect_option = true
+ option_name = :server
+ elsif arg == '--title'
+ expect_option = true
+ option_name = :title
+ else
+ invalid_option(arg)
+ end
+ elsif valid_env?(arg)
+ @args[:env_path] = File.expand_path(arg)
+ end
+ end
+ end
+ if expect_option
+ puts "no value for option #{option_name.to_s.inspect}"
+ puts "Type 'rsence help #{@cmd.to_s} for usage."
+ exit
+ end
+ end
+ if valid_env?(@args[:env_path])
+ conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
+ @args[:conf_files].push( conf_file ) unless @args[:conf_files].include?( conf_file )
+ else
+ puts "invalid environment."
+ exit
+ end
+ require 'conf/default'
+ config = Configuration.new(@args).config
+ port = config[:http_server][:port]
+ addr = config[:http_server][:bind_address]
+ port_status = test_port( port, addr )
+ if RSence.pid_support?
+ pid_fn = config[:daemon][:pid_fn]
+ if File.exists?( pid_fn )
+ pid = File.read( pid_fn ).to_i
+ pid_status = RSence::SIGComm.wait_signal_response(
+ pid, pid_fn, 'USR2', 3
+ )
+ else
+ puts "no PID file, unable to check process status" if @args[:verbose]
+ pid_status = nil
+ end
+ else
+ puts "no PID support, unable to check process status" if @args[:verbose]
+ pid_status = nil
+ end
+ if RSence.pid_support?
+ if pid_status == nil
+ puts "No process id, unable to check process status."
+ elsif pid_status == false
+ puts "No process running#{port_status ? ' but something responds on ' : ' and nothing responds on ' }#{addr}:#{port}."
+ else
+ puts "Process id #{pid} is running#{port_status ? ' and responds on ' : ', but does not respond on '}#{addr}:#{port}."
+ end
+ end
end
def help( cmd )
cmd.to_sym! if cmd.class != Symbol
puts @@cmd_help[:head]
@@ -709,10 +787,10 @@
if @@cmds.include?(cmd)
@cmd = cmd
if cmd == :help
parse_help_argv
elsif cmd == :version
- version
+ puts version
exit
elsif [:run,:start,:stop,:restart].include? cmd
parse_startup_argv
elsif cmd == :status
parse_status_argv