def handle_cli_input
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} (start|stop|restart) [options]"
opts.banner += "\n#{app} is only usable when using webrick or mongrel"
opts.on("-c", "--config FILE", "Path to #{app} configuration file") { |value| @options[:conf_file] = value }
opts.on("-P", "--pid_file FILE", "Path to #{app} pid file") { |value| @options[:pid_file] = value }
opts.on('-v', '--verbose', "Print debugging information to the console") { |value| @options[:verbose] = value }
if ARGV.empty?
puts opts
exit
else
@cmd = opts.parse!(ARGV)
if @cmd.nil?
puts opts
exit
end
end
end
if !@options[:conf_file].nil? && !File.exists?(@options[:conf_file])
puts "Invalid path to #{app} configuration file: #{@options[:conf_file]}"
exit
end
case @cmd[0]
when "start":
puts "Starting #{app}..."
start
when "stop":
puts "Stopping #{app}..."
stop
when "restart":
puts "Restarting #{app}..."
stop
start
when "status":
puts "Checking status of #{app}..."
status
else
puts "Invalid command. Usage: #{app}-ctl [-cPv] start|stop|restart|status"
end
exit
end