Class: AutomateIt::ServiceManager::SYSV

Inherits:
BaseDriver show all
Defined in:
lib/automateit/service_manager/sysv.rb

Overview

ServiceManager::SYSV

The SYSV driver implements the ServiceManager methods for #running?, #start and #stop on Unix-like platforms that use the System V init process using a /etc/init.d directory.

It also implements a basic #enabled? method that’s very fast but may not work correctly on all SysV platforms. This method should be overridden by more specific drivers when reasonable.

It does not implement the #enable and #disable methods because these are not standardized and must be implemented using platform-specific drivers, e.g., Chkconfig on RedHat-like platforms.

Direct Known Subclasses

Chkconfig, RC_Update, UpdateRCD

Constant Summary collapse

ETC_INITD =
"/etc/init.d"

Constants inherited from Plugin::Driver

Plugin::Driver::BASE_DRIVER_NAME

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from Plugin::Driver

#manager

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from BaseDriver

#start_and_enable, #start_or_restart

Methods inherited from Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup

Methods inherited from Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Instance Method Details

#enabled?(service) ⇒ Boolean

See ServiceManager#enabled?

Returns:

  • (Boolean)


135
136
137
# File 'lib/automateit/service_manager/sysv.rb', line 135

def enabled?(service)
  return ! Dir["/etc/rc*.d/*"].grep(/\/S\d{2}#{service}$/).empty?
end

#restart(service, opts = {}) ⇒ Object

See ServiceManager#restart



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/automateit/service_manager/sysv.rb', line 120

def restart(service, opts={})
  if started?(service, :wait => opts[:pause])
    # We're certain that service is started
    stop_opts = opts.clone
    stop_opts[:force] = true # Don't check again
    stop(service, stop_opts)
  end

  # We're certain that service is stopped
  start_opts = opts.clone
  start_opts[:force] = true # Don't check again
  return start(service, start_opts)
end

#running?(service, opts = {}) ⇒ Boolean

See ServiceManager#running?

Returns:

  • (Boolean)


50
51
52
# File 'lib/automateit/service_manager/sysv.rb', line 50

def running?(service, opts={})
  return started?(service, opts)
end

#start(service, opts = {}) ⇒ Object

See ServiceManager#start



96
97
98
99
100
101
102
103
104
105
# File 'lib/automateit/service_manager/sysv.rb', line 96

def start(service, opts={})
  if not opts[:force] and started?(service, :wait => opts[:wait])
    # Already started
    return false
  else
    # Needs starting or forced
    tell(service, :start, opts)
    return true
  end
end

#started?(service, opts = {}) ⇒ Boolean

See ServiceManager#started?

Returns:

  • (Boolean)


86
87
88
# File 'lib/automateit/service_manager/sysv.rb', line 86

def started?(service, opts={})
  return _started_and_stopped_helper(:started?, service, opts)
end

#stop(service, opts = {}) ⇒ Object

See ServiceManager#stop



108
109
110
111
112
113
114
115
116
117
# File 'lib/automateit/service_manager/sysv.rb', line 108

def stop(service, opts={})
  if not opts[:force] and stopped?(service, :wait => opts[:wait])
    # Already stopped
    return false
  else
    # Needs stopping or forced
    tell(service, :stop, opts)
    return true
  end
end

#stopped?(service, opts = {}) ⇒ Boolean

See ServiceManager#stopped?

Returns:

  • (Boolean)


91
92
93
# File 'lib/automateit/service_manager/sysv.rb', line 91

def stopped?(service, opts={})
  return ! _started_and_stopped_helper(:stopped?, service, opts)
end

#suitability(method, *args) ⇒ Object

:nodoc:



19
20
21
22
# File 'lib/automateit/service_manager/sysv.rb', line 19

def suitability(method, *args) # :nodoc:
  return 0 if %w(enabled? enable disable).include?(method.to_s)
  return available? ? 1 : 0
end

#tell(service, action, opts = {}) ⇒ Object

See ServiceManager#tell



45
46
47
# File 'lib/automateit/service_manager/sysv.rb', line 45

def tell(service, action, opts={})
  return _run_command(["#{ETC_INITD}/#{service}", action.to_s], opts)
end