class Thin::Controllers::Service

System service controller to launch all servers which config files are in a directory.

Constants

DEFAULT_CONFIG_PATH
INITD_PATH
TEMPLATE

Public Class Methods

new(options) click to toggle source
Calls superclass method Thin::Controllers::Controller.new
# File lib/thin/controllers/service.rb, line 12
def initialize(options)
  super

  raise PlatformNotSupported, 'Running as a service only supported on Linux' unless Thin.linux?
end

Public Instance Methods

config_path() click to toggle source
# File lib/thin/controllers/service.rb, line 18
def config_path
  @options[:all] || DEFAULT_CONFIG_PATH
end
install(config_files_path=DEFAULT_CONFIG_PATH) click to toggle source
# File lib/thin/controllers/service.rb, line 34
def install(config_files_path=DEFAULT_CONFIG_PATH)
  if File.exist?(INITD_PATH)
    log ">> Thin service already installed at #{INITD_PATH}"
  else
    log ">> Installing thin service at #{INITD_PATH} ..."
    sh "mkdir -p #{File.dirname(INITD_PATH)}"
    log "writing #{INITD_PATH}"        
    File.open(INITD_PATH, 'w') do |f|
      f << ERB.new(File.read(TEMPLATE)).result(binding)
    end
    sh "chmod +x #{INITD_PATH}" # Make executable
  end

  sh "mkdir -p #{config_files_path}"

  log ''
  log "To configure thin to start at system boot:"
  log "on RedHat like systems:"
  log "  sudo /sbin/chkconfig --level 345 #{NAME} on"
  log "on Debian-like systems (Ubuntu):"
  log "  sudo /usr/sbin/update-rc.d -f #{NAME} defaults"
  log "on Gentoo:"
  log "  sudo rc-update add #{NAME} default"
  log ''
  log "Then put your config files in #{config_files_path}"
end
restart() click to toggle source
# File lib/thin/controllers/service.rb, line 30
def restart
  run :restart
end
start() click to toggle source
# File lib/thin/controllers/service.rb, line 22
def start
  run :start
end
stop() click to toggle source
# File lib/thin/controllers/service.rb, line 26
def stop
  run :stop
end

Private Instance Methods

run(command) click to toggle source
# File lib/thin/controllers/service.rb, line 62
def run(command)
  Dir[config_path + '/*'].each do |config|
    log "[#{command}] #{config} ..."
    Command.run(command, :config => config, :daemonize => true)
  end
end
sh(cmd) click to toggle source
# File lib/thin/controllers/service.rb, line 69
def sh(cmd)
  log cmd
  system(cmd)
end