### Home Classes Methods

### In Files

- lib/phusion_passenger/admin_tools/server_instance.rb

### Parent

Object

### Namespace

- CLASS PhusionPassenger::AdminTools::ServerInstance::CorruptedDirectoryError
- CLASS PhusionPassenger::AdminTools::ServerInstance::GenerationsAbsentError
- CLASS PhusionPassenger::AdminTools::ServerInstance::Group
- CLASS PhusionPassenger::AdminTools::ServerInstance::Process
- CLASS PhusionPassenger::AdminTools::ServerInstance::RoleDeniedError
- CLASS PhusionPassenger::AdminTools::ServerInstance::StaleDirectoryError
- CLASS PhusionPassenger::AdminTools::ServerInstance::Stats
- CLASS PhusionPassenger::AdminTools::ServerInstance::UnsupportedGenerationStructureVersionError

### Methods

- ::for_pid
- ::list
- ::new
- #analytics_log_dir
- #backtraces
- #connect
- #get_wait_list_size
- #groups
- #helper_agent_pid
- #processes
- #stats
- #status
- #web_server_config_files
- #web_server_description
- #xml

### Class/Module Index

Quicksearch

- PhusionPassenger
- PhusionPassenger::AbstractInstaller
- PhusionPassenger::AbstractInstaller::Abort
- PhusionPassenger::AbstractInstaller::CommandError
- PhusionPassenger::AdminTools
- PhusionPassenger::AdminTools::MemoryStats
- PhusionPassenger::AdminTools::MemoryStats::Process
- PhusionPassenger::AdminTools::ServerInstance
- PhusionPassenger::AdminTools::ServerInstance::CorruptedDirectoryError
- PhusionPassenger::AdminTools::ServerInstance::GenerationsAbsentError
- PhusionPassenger::AdminTools::ServerInstance::Group
- PhusionPassenger::AdminTools::ServerInstance::Process
- PhusionPassenger::AdminTools::ServerInstance::RoleDeniedError
- PhusionPassenger::AdminTools::ServerInstance::StaleDirectoryError
- PhusionPassenger::AdminTools::ServerInstance::Stats
- PhusionPassenger::AdminTools::ServerInstance::UnsupportedGenerationStructureVersionError
- PhusionPassenger::AnalyticsLogger
- PhusionPassenger::AnalyticsLogger::Connection
- PhusionPassenger::AnalyticsLogger::Lock
- PhusionPassenger::AnalyticsLogger::Log
- PhusionPassenger::ClassicRails
- PhusionPassenger::ClassicRails::CGIFixed
- PhusionPassenger::ClassicRails::ThreadHandlerExtension
- PhusionPassenger::ConsoleTextTemplate
- PhusionPassenger::DebugLogging
- PhusionPassenger::LoaderSharedHelpers
- PhusionPassenger::MessageChannel
- PhusionPassenger::MessageChannel::InvalidHashError
- PhusionPassenger::MessageClient
- PhusionPassenger::NativeSupportLoader
- PhusionPassenger::Packaging
- PhusionPassenger::PlatformInfo
- PhusionPassenger::PlatformInfo::Depcheck
- PhusionPassenger::PlatformInfo::Depcheck::ConsoleRunner
- PhusionPassenger::PlatformInfo::Depcheck::Dependency
- PhusionPassenger::PlatformInfo::RuntimeError
- PhusionPassenger::Plugin
- PhusionPassenger::PreloaderSharedHelpers
- PhusionPassenger::Rack
- PhusionPassenger::Rack::OutOfBandGc
- PhusionPassenger::Rack::ThreadHandlerExtension
- PhusionPassenger::Rails3Extensions
- PhusionPassenger::Rails3Extensions::AnalyticsLogging
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ACExtension
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ASBenchmarkableExtension
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ExceptionLogger
- PhusionPassenger::RequestHandler
- PhusionPassenger::RequestHandler::ThreadHandler
- PhusionPassenger::RequestHandler::ThreadHandler::Interrupted
- PhusionPassenger::SharedConstants
- PhusionPassenger::Standalone
- PhusionPassenger::Standalone::AppFinder
- PhusionPassenger::Standalone::Command
- PhusionPassenger::Standalone::ConfigFile
- PhusionPassenger::Standalone::ConfigFile::DisallowedContextError
- PhusionPassenger::Standalone::HelpCommand
- PhusionPassenger::Standalone::Main
- PhusionPassenger::Standalone::PackageRuntimeCommand
- PhusionPassenger::Standalone::RuntimeInstaller
- PhusionPassenger::Standalone::StartCommand
- PhusionPassenger::Standalone::StatusCommand
- PhusionPassenger::Standalone::StopCommand
- PhusionPassenger::Standalone::Utils
- PhusionPassenger::Standalone::VersionCommand
- PhusionPassenger::Utils
- PhusionPassenger::Utils::AnsiColors
- PhusionPassenger::Utils::FileSystemWatcher
- PhusionPassenger::Utils::FileSystemWatcher::DirInfo
- PhusionPassenger::Utils::FileSystemWatcher::FileInfo
- PhusionPassenger::Utils::HostsFileParser
- PhusionPassenger::Utils::TeeInput
- PhusionPassenger::Utils::TmpIO
- PhusionPassenger::Utils::UnseekableSocket
- CommonLibraryBuilder
- Exception
- GC
- IO
- Object
- Signal

No matching classes.

# PhusionPassenger::AdminTools::ServerInstance

### Constants

STALE_TIME_THRESHOLD

### Attributes

generation_path[R]
path[R]
pid[R]

### Public Class Methods

for_pid(pid, options = {}) click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 134
    def self.for_pid(pid, options = {})
            return list(options).find { |c| c.pid == pid }
    end

list(options = {}) click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 107
    def self.list(options = {})
            options = {
                    :clean_stale_or_corrupted => true
            }.merge(options)
            instances = []

            Dir["#{AdminTools.tmpdir}/passenger.*"].each do |dir|
                    next if File.basename(dir) !~ /passenger\.#{PhusionPassenger::SERVER_INSTANCE_DIR_STRUCTURE_MAJOR_VERSION}\.(\d+)\.(.+)\Z/
                    minor = $1
                    next if minor.to_i > PhusionPassenger::SERVER_INSTANCE_DIR_STRUCTURE_MINOR_VERSION

                    begin
                            instances << ServerInstance.new(dir)
                    rescue StaleDirectoryError, CorruptedDirectoryError
                            if options[:clean_stale_or_corrupted] &&
                               File.stat(dir).mtime < current_time - STALE_TIME_THRESHOLD
                                    log_cleaning_action(dir)
                                    FileUtils.chmod_R(0700, dir) rescue nil
                                    FileUtils.rm_rf(dir)
                            end
                    rescue UnsupportedGenerationStructureVersionError, GenerationsAbsentError
                            # Do nothing.
                    end
            end
            return instances
    end

new(path) click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 138
    def initialize(path)
            raise ArgumentError, "Path may not be nil." if path.nil?
            @path = path

            if File.exist?("#{path}/control_process.pid")
                    data = File.read("#{path}/control_process.pid").strip
                    @pid = data.to_i
            else
                    path =~ /passenger\.\d+\.\d+\.(\d+)\Z/
                    @pid = $1.to_i
            end

            generations = Dir["#{path}/generation-*"]
            if generations.empty?
                    raise GenerationsAbsentError, "There are no generation subdirectories in this instance directory."
            end
            highest_generation_number = 0
            generations.each do |generation|
                    File.basename(generation) =~ /(\d+)/
                    generation_number = $1.to_i
                    if generation_number > highest_generation_number
                            highest_generation_number = generation_number
                    end
            end
            @generation_path = "#{path}/generation-#{highest_generation_number}"

            if !File.exist?("#{@generation_path}/structure_version.txt")
                    raise CorruptedDirectoryError, "The generation directory doesn't contain a structure version specification file."
            end
            version_data = File.read("#{@generation_path}/structure_version.txt").strip
            major, minor = version_data.split(".", 2)
            if major.nil? || minor.nil? || major !~ /\A\d+\Z/ || minor !~ /\A\d+\Z/
                    raise CorruptedDirectoryError, "The generation directory doesn't contain a valid structure version specification file."
            end
            major = major.to_i
            minor = minor.to_i
            if major != PhusionPassenger::SERVER_INSTANCE_DIR_GENERATION_STRUCTURE_MAJOR_VERSION ||
               minor > PhusionPassenger::SERVER_INSTANCE_DIR_GENERATION_STRUCTURE_MINOR_VERSION
                    raise UnsupportedGenerationStructureVersionError, "Unsupported generation directory structure version."
            end

            if @pid == 0
                    raise CorruptedDirectoryError, "Instance directory contains corrupted control_process.pid file."
            elsif !AdminTools.process_is_alive?(@pid)
                    raise StaleDirectoryError, "There is no instance with PID #{@pid}."
            end
    end

### Public Instance Methods

analytics_log_dir() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 238
    def analytics_log_dir
            return File.read("#{@generation_path}/analytics_log_dir.txt")
    rescue Errno::ENOENT
            return nil
    end

backtraces() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 248
    def backtraces
            return @client.backtraces
    end

connect(role_or_username, password = nil) click to toggle source

Raises:

- `ArgumentError`: Unsupported role

- `RoleDeniedError`: The user that the current process is as is not authorized to utilize the given role.

- `EOFError`: The server unexpectedly closed the connection during authentication.

- `SecurityError`: The server denied our authentication credentials.

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 191
    def connect(role_or_username, password = nil)
            if role_or_username.is_a?(Symbol)
                    case role_or_username
                    when :passenger_status
                            username = "_passenger-status"
                            begin
                                    filename = "#{@generation_path}/passenger-status-password.txt"
                                    password = File.open(filename, "rb") do |f|
                                            f.read
                                    end
                            rescue Errno::EACCES
                                    raise RoleDeniedError
                            end
                    else
                            raise ArgumentError, "Unsupported role #{role_or_username}"
                    end
            else
                    username = role_or_username
            end

            @client = MessageClient.new(username, password, "unix:#{@generation_path}/helper_admin")
            begin
                    yield self
            ensure
                    @client.close
            end
    end

get_wait_list_size() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 265
    def get_wait_list_size
            return stats.get_wait_list_size
    end

groups() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 269
    def groups
            doc = REXML::Document.new(xml)

            groups = []
            doc.elements.each("info/supergroups/supergroup/group") do |group_xml|
                    group = Group.new(group_xml.elements["app_root"].text,
                            group_xml.elements["name"].text,
                            group_xml.elements["environment"].text,
                            !!group_xml.elements["spawning"])
                    group_xml.elements.each("processes/process") do |process_xml|
                            process = Process.new(group)
                            process_xml.elements.each do |element|
                                    if element.name == "sockets"
                                            element.elements.each("socket") do |server_socket|
                                                    name = server_socket.elements["name"].text.to_sym
                                                    address = server_socket.elements["address"].text
                                                    protocol = server_socket.elements["protocol"].text
                                                    process.server_sockets[name] = OpenStruct.new(
                                                            :name     => name,
                                                            :address  => address,
                                                            :protocol => protocol
                                                    )
                                            end
                                    else
                                            if process.respond_to?("#{element.name}=")
                                                    if Process::INT_PROPERTIES.include?(element.name.to_sym)
                                                            value = element.text.to_i
                                                    elsif Process::BOOL_PROPERTIES.include?(element.name.to_sym)
                                                            value = element.text == "true"
                                                    else
                                                            value = element.text
                                                    end
                                                    process.send("#{element.name}=", value)
                                            end
                                    end
                            end
                            group.processes << process
                    end
                    groups << group
            end
            return groups
    end

helper_agent_pid() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 234
    def helper_agent_pid
            return File.read("#{@generation_path}/helper_agent.pid").strip.to_i
    end

processes() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 312
    def processes
            return groups.map do |group|
                    group.processes
            end.flatten
    end

stats() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 256
    def stats
            doc = REXML::Document.new(xml)
            stats = Stats.new
            stats.max = doc.elements["info/max"].text.to_i
            stats.usage = doc.elements["info/usage"].text.to_i
            stats.get_wait_list_size = doc.elements["info/get_wait_list_size"].text.to_i
            return stats
    end

status(*options) click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 244
    def status(*options)
            return @client.status(*options)
    end

web_server_config_files() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 223
    def web_server_config_files
            config_files = File.read("#{@generation_path}/config_files.txt").split("\n")
            config_files.map! do |filename|
                    filename.strip
            end
            config_files.reject do |filename|
                    filename.empty?
            end
            return config_files
    end

web_server_description() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 219
    def web_server_description
            return File.read("#{@generation_path}/web_server.txt")
    end

xml() click to toggle source

    # File lib/phusion_passenger/admin_tools/server_instance.rb, line 252
    def xml
            return @client.xml
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.