def select_passenger_instance
if name = @options[:instance]
@instance = AdminTools::InstanceRegistry.new.find_by_name_prefix(name)
if !@instance
if @options[:ignore_passenger_not_running]
message_type = "WARNING"
else
message_type = "ERROR"
end
STDERR.puts "*** #{message_type}: there doesn't seem to be a #{PROGRAM_NAME} instance running with the name '#{name}'."
list_all_passenger_instances(AdminTools::InstanceRegistry.new.list)
STDERR.puts
STDERR.puts "Please pass `--instance <NAME>` to select a specific #{PROGRAM_NAME} instance."
if @options[:ignore_passenger_not_running]
exit
else
abort
end
elsif @instance == :ambigious
abort "*** ERROR: there are multiple instances whose name start with '#{name}'. Please specify the full name."
end
else
instances = AdminTools::InstanceRegistry.new.list
if instances.empty?
if @options[:ignore_passenger_not_running]
message_type = "WARNING"
else
message_type = "ERROR"
end
STDERR.puts "*** #{message_type}: #{PROGRAM_NAME} doesn't seem to be running. If you are sure that it"
STDERR.puts "is running, then the causes of this problem could be one of:"
STDERR.puts
STDERR.puts " 1. You customized the instance registry directory using Apache's"
STDERR.puts " PassengerInstanceRegistryDir option, Nginx's"
STDERR.puts " passenger_instance_registry_dir option, or #{PROGRAM_NAME} Standalone's"
STDERR.puts " --instance-registry-dir command line argument. If so, please set the"
STDERR.puts " environment variable PASSENGER_INSTANCE_REGISTRY_DIR to that directory"
STDERR.puts " and run this command again."
STDERR.puts " 2. The instance directory has been removed by an operating system background"
STDERR.puts " service. Please set a different instance registry directory using Apache's"
STDERR.puts " PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir"
STDERR.puts " option, or #{PROGRAM_NAME} Standalone's --instance-registry-dir command"
STDERR.puts " line argument."
if @options[:ignore_passenger_not_running]
exit
else
abort
end
elsif instances.size == 1
@instance = instances.first
else
complain_that_multiple_passenger_instances_are_running(instances)
abort
end
end
end