Sha256: 7d983898b7d03a6c15e991935cac939535a1c53008e92c06ee729283a72919b8

Contents?: true

Size: 1.35 KB

Versions: 31

Compression:

Stored size: 1.35 KB

Contents

# == ServiceManager::Chkconfig
#
# The Chkconfig driver implements the ServiceManager methods for #enabled?,
# #enable and #disable on RedHat-like platforms. It uses the SYSV driver
# for handling the methods #running?, #start and #stop.
class AutomateIt::ServiceManager::Chkconfig < AutomateIt::ServiceManager::SYSV
  depends_on :programs => %w(chkconfig)

  def suitability(method, *args) # :nodoc:
    return available? ? 2 : 0
  end

  # See ServiceManager#enabled?
  def enabled?(service)
    _raise_unless_available
    # "chkconfig --list service" may produce output like the below:
    # service httpd supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add automateit_service_sysv_test')
    # => httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
    if matcher = `chkconfig --list #{service} < /dev/null 2>&1` \
        .match(/^(#{service}).+?(\d+:(on|off).+?)$/)
      return true if matcher[2].match(/\b\d+:on\b/)
    end
    return false
  end

  # See ServiceManager#enable
  def enable(service, opts={})
    _raise_unless_available
    return false if enabled?(service)
    interpreter.sh("chkconfig --add #{service}")
  end

  # See ServiceManager#disable
  def disable(service, opts={})
    _raise_unless_available
    return false unless enabled?(service)
    interpreter.sh("chkconfig --del #{service}")
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
automate-it-0.9.2 lib/automateit/service_manager/chkconfig.rb
automate-it-0.9.1 lib/automateit/service_manager/chkconfig.rb
automate-it-0.9.0 lib/automateit/service_manager/chkconfig.rb
automateit-0.70928 lib/automateit/service_manager/chkconfig.rb
automateit-0.70930 lib/automateit/service_manager/chkconfig.rb
automateit-0.71003 lib/automateit/service_manager/chkconfig.rb
automateit-0.70923 lib/automateit/service_manager/chkconfig.rb
automateit-0.71030 lib/automateit/service_manager/chkconfig.rb
automateit-0.71031.1 lib/automateit/service_manager/chkconfig.rb
automateit-0.71006 lib/automateit/service_manager/chkconfig.rb
automateit-0.71031.2 lib/automateit/service_manager/chkconfig.rb
automateit-0.71017 lib/automateit/service_manager/chkconfig.rb
automateit-0.71012 lib/automateit/service_manager/chkconfig.rb
automateit-0.71021 lib/automateit/service_manager/chkconfig.rb
automateit-0.71103 lib/automateit/service_manager/chkconfig.rb
automateit-0.71031 lib/automateit/service_manager/chkconfig.rb
automateit-0.71101 lib/automateit/service_manager/chkconfig.rb
automateit-0.71101.1 lib/automateit/service_manager/chkconfig.rb
automateit-0.71101.2 lib/automateit/service_manager/chkconfig.rb
automateit-0.71102 lib/automateit/service_manager/chkconfig.rb