bin/rflow in rflow-0.0.5 vs bin/rflow in rflow-1.0.0a1

- old
+ new

@@ -25,15 +25,15 @@ end opts.on("-e", "--extensions FILE1[,FILE_N]", Array, "Extension file paths (will load)") do |extensions| options[:extensions_file_paths] += extensions.map {|extension| File.expand_path(extension)} end - + opts.on("-g", "--gems GEM1[,GEM_N]", Array, "Extension gems (will require)") do |gems| options[:gems] += gems end - + opts.on("-l", "--log LOGFILE", "Initial startup log file (in addition to stdout)") do |log| options[:startup_log_file_path] = File.expand_path(log) end opts.on("-v", "--verbose [LEVEL]", [:DEBUG, :INFO, :WARN], "Control the startup log (and stdout) verbosity (DEBUG, INFO, WARN) defaults to INFO") do |level| @@ -47,16 +47,16 @@ opts.on_tail("--version", "Show RFlow version and exit") do require 'rflow/version' puts RFlow::VERSION exit 0 end - + opts.on_tail("-h", "--help", "Show this message and exit") do puts opts exit 0 end - + end begin option_parser.parse! rescue Exception => e @@ -71,16 +71,17 @@ # Set up the startup logging, which is distinct from the runtime # logging that is defined in the config database. The startup logging # will always go to STDOUT, as well as to the file specified with the # '-l' parameter startup_logger = Log4r::Logger.new 'startup' -startup_logger.add Log4r::StdoutOutputter.new('startup_stdout', :formatter => RFlow::LOG_PATTERN_FORMATTER) +startup_logger.add Log4r::StdoutOutputter.new('startup_stdout', :formatter => RFlow::Logger::LOG_PATTERN_FORMATTER) startup_logger.level = Log4r::LNAMES.index options[:startup_log_level].to_s +Log4r::NDC.push('startup') if options[:startup_log_file_path] begin - startup_logger.add Log4r::FileOutputter.new('startup_file', :filename => options[:startup_log_file_path], :formatter => RFlow::LOG_PATTERN_FORMATTER) + startup_logger.add Log4r::FileOutputter.new('startup_file', :filename => options[:startup_log_file_path], :formatter => RFlow::Logger::LOG_PATTERN_FORMATTER) rescue Exception => e startup_logger.fatal "Log file '#{options[:startup_log_file_path]}' problem: #{e.message}" exit 1 end end @@ -118,31 +119,32 @@ if options[:config_file_path] unless File.exist? options[:config_file_path] startup_logger.fatal "Config file '#{options[:config_file_path]}' not found\n#{option_parser.help}" exit 1 end - + unless File.readable? options[:config_file_path] startup_logger.fatal "Config file '#{options[:config_file_path]}' not readable\n#{option_parser.help}" exit 1 end end - + if File.exist? options[:config_database_path] startup_logger.fatal "Config database '#{options[:config_database_path]}' exists, exiting to prevent accidental overwrite from config file '#{options[:config_file_path]}'" exit 1 end - + startup_logger.warn "Config database '#{options[:config_database_path]}' not found, creating" begin - RFlow::Configuration::initialize_database(options[:config_database_path], options[:config_file_path]) + config = RFlow::Configuration::initialize_database(options[:config_database_path], options[:config_file_path]) rescue Exception => e startup_logger.fatal "Error initializing configuration database: #{e.message}: #{e.backtrace.join "\n"}" exit 1 end startup_logger.warn "Successfully initialized database '#{options[:config_database_path]}' with '#{options[:config_file_path]}'" + startup_logger.debug config.to_s exit 0 end # Load the database config and start setting up environment @@ -153,34 +155,35 @@ exit 1 end Dir.chdir(File.dirname(options[:config_database_path])) Dir.chdir(config['rflow.application_directory_path']) -pid = RFlow.running_pid_file_path?(config['rflow.pid_file_path']) +pid_file = RFlow::PIDFile.new(config['rflow.pid_file_path']) + case command when 'stop' - if pid - startup_logger.info "#{config['rflow.application_name']} running, process #{pid} found in #{File.expand_path(config['rflow.pid_file_path'])}, terminating" + if pid_file.running? + startup_logger.info "#{config['rflow.application_name']} running, process #{pid_file.read} found in #{pid_file.to_s}, terminating" # TODO: check if it actually shut down - Process.kill 'INT', pid + pid_file.signal(:INT) else - startup_logger.warn "#{config['rflow.application_name']} process not found in #{File.expand_path(config['rflow.pid_file_path'])}" + startup_logger.warn "#{config['rflow.application_name']} process not found in #{pid_file.to_s}" exit 1 end exit 0 when 'status' - unless pid - startup_logger.error "#{config['rflow.application_name']} process not found in #{File.expand_path(config['rflow.pid_file_path'])}" + unless pid_file.running? + startup_logger.error "#{config['rflow.application_name']} process not found in #{pid_file.to_s}" exit 1 end - startup_logger.info "#{config['rflow.application_name']} running, process #{pid} found in #{File.expand_path(config['rflow.pid_file_path'])}" + startup_logger.info "#{config['rflow.application_name']} running, process #{pid_file.read} found in #{pid_file.to_s}" exit 0 when 'start' - if pid - startup_logger.error "#{config['rflow.application_name']} already running, process #{pid} found in #{File.expand_path(config['rflow.pid_file_path'])}" + if pid_file.running? + startup_logger.error "#{config['rflow.application_name']} already running, process #{pid_file.read} found in #{pid_file.to_s}" exit 1 end end