Class: Thin::Controllers::Service

Inherits:
Controller show all
Defined in:
lib/thin/controllers/service.rb

Overview

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

Constant Summary collapse

INITD_PATH =
File.directory?('/etc/rc.d') ? '/etc/rc.d/thin' : '/etc/init.d/thin'
DEFAULT_CONFIG_PATH =
'/etc/thin'
TEMPLATE =
File.dirname(__FILE__) + '/service.sh.erb'

Instance Attribute Summary

Attributes inherited from Controller

#options

Instance Method Summary collapse

Methods inherited from Controller

#config

Methods included from Logging

debug=, debug?, level, level=, #log, log_debug, #log_debug, log_error, #log_error, #log_info, log_info, log_msg, #silent, #silent=, silent=, silent?, #trace, trace, trace=, trace?, trace_msg

Constructor Details

#initialize(options) ⇒ Service

Returns a new instance of Service.



12
13
14
15
16
# 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

Instance Method Details

#config_pathObject



18
19
20
# File 'lib/thin/controllers/service.rb', line 18

def config_path
  @options[:all] || DEFAULT_CONFIG_PATH
end

#install(config_files_path = DEFAULT_CONFIG_PATH) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/thin/controllers/service.rb', line 34

def install(config_files_path=DEFAULT_CONFIG_PATH)
  if File.exist?(INITD_PATH)
    log_info "Thin service already installed at #{INITD_PATH}"
  else
    log_info "Installing thin service at #{INITD_PATH} ..."
    sh "mkdir -p #{File.dirname(INITD_PATH)}"
    log_info "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_info ''
  log_info "To configure thin to start at system boot:"
  log_info "on RedHat like systems:"
  log_info "  sudo /sbin/chkconfig --level 345 #{NAME} on"
  log_info "on Debian-like systems (Ubuntu):"
  log_info "  sudo /usr/sbin/update-rc.d -f #{NAME} defaults"
  log_info "on Gentoo:"
  log_info "  sudo rc-update add #{NAME} default"
  log_info ''
  log_info "Then put your config files in #{config_files_path}"
end

#restartObject



30
31
32
# File 'lib/thin/controllers/service.rb', line 30

def restart
  run :restart
end

#startObject



22
23
24
# File 'lib/thin/controllers/service.rb', line 22

def start
  run :start
end

#stopObject



26
27
28
# File 'lib/thin/controllers/service.rb', line 26

def stop
  run :stop
end