Module: Thin::Daemonizable::ClassMethods

### Home Classes Methods

### In Files

- lib/thin/daemonizing.rb

### Methods

- #force_kill
- #kill
- #read_pid_file
- #restart
- #send_signal

### Class/Module Index

Quicksearch

- Thin
- Thin::Backends
- Thin::Backends::Base
- Thin::Backends::SwiftiplyClient
- Thin::Backends::TcpServer
- Thin::Backends::UnixServer
- Thin::Command
- Thin::Connection
- Thin::Controllers
- Thin::Controllers::Cluster
- Thin::Controllers::Controller
- Thin::Controllers::Service
- Thin::Daemonizable
- Thin::Daemonizable::ClassMethods
- Thin::Headers
- Thin::InvalidOption
- Thin::InvalidRequest
- Thin::Logging
- Thin::Logging::SimpleFormatter
- Thin::OptionRequired
- Thin::PidFileExist
- Thin::PidFileNotFound
- Thin::PlatformNotSupported
- Thin::Request
- Thin::Response
- Thin::RestartTimeout
- Thin::Runner
- Thin::RunnerError
- Thin::Server
- Thin::Stats
- Thin::Stats::Adapter
- Thin::SwiftiplyConnection
- Thin::UnixConnection
- Rack
- Rack::Adapter
- Rack::Adapter::Rails
- Rack::Adapter::Rails::CGIWrapper
- Rack::Adapter::Rails::CgiApp
- Rack::AdapterNotFound
- Process

No matching classes.

# Thin::Daemonizable::ClassMethods

### Public Instance Methods

force_kill(pid, pid_file) click to toggle source

    # File lib/thin/daemonizing.rb, line 141
    def force_kill(pid, pid_file)
      Logging.log_info "Sending KILL signal to process #{pid} ... "
      Process.kill("KILL", pid)
      File.delete(pid_file) if File.exist?(pid_file)
    end

kill(pid_file, timeout=60) click to toggle source

Send a QUIT or INT (if timeout is `0`) signal the process which PID is stored in `pid_file`. If the process is still running after `timeout`, KILL signal is sent.

    # File lib/thin/daemonizing.rb, line 107
    def kill(pid_file, timeout=60)
      if timeout == 0
        send_signal('INT', pid_file, timeout)
      else
        send_signal('QUIT', pid_file, timeout)
      end
    end

read_pid_file(file) click to toggle source

    # File lib/thin/daemonizing.rb, line 147
    def read_pid_file(file)
      if File.file?(file) && pid = File.read(file)
        pid.to_i
      else
        nil
      end
    end

restart(pid_file) click to toggle source

Restart the server by sending HUP signal.

    # File lib/thin/daemonizing.rb, line 116
    def restart(pid_file)
      send_signal('HUP', pid_file)
    end

send_signal(signal, pid_file, timeout=60) click to toggle source

Send a `signal` to the process which PID is stored in `pid_file`.

    # File lib/thin/daemonizing.rb, line 121
    def send_signal(signal, pid_file, timeout=60)
      if pid = read_pid_file(pid_file)
        Logging.log_info "Sending #{signal} signal to process #{pid} ... "
        Process.kill(signal, pid)
        Timeout.timeout(timeout) do
          sleep 0.1 while Process.running?(pid)
        end
      else
        raise PidFileNotFound, "Can't stop process, no PID found in #{pid_file}"
      end
    rescue Timeout::Error
      Logging.log_info "Timeout!"
      force_kill(pid, pid_file)
    rescue Interrupt
      force_kill(pid, pid_file)
    rescue Errno::ESRCH # No such process
      Logging.log_info "process not found!"
      force_kill(pid, pid_file)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.