class Chef::Provider::Service::Init

Attributes

init_command[RW]

Public Class Methods

new(new_resource, run_context) click to toggle source
Calls superclass method Chef::Provider::Service::new
# File lib/chef/provider/service/init.rb, line 35
def initialize(new_resource, run_context)
  super
  @init_command = "/etc/init.d/#{@new_resource.service_name}"
end
supports?(resource, action) click to toggle source
# File lib/chef/provider/service/init.rb, line 31
def self.supports?(resource, action)
  Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd)
end

Public Instance Methods

define_resource_requirements() click to toggle source
# File lib/chef/provider/service/init.rb, line 40
def define_resource_requirements
  # do not call super here, inherit only shared_requirements
  shared_resource_requirements
  requirements.assert(:start, :stop, :restart, :reload) do |a|
    a.assertion do
      custom_command_for_action?(action) || ::File.exist?(default_init_command)
    end
    a.failure_message(Chef::Exceptions::Service, "#{default_init_command} does not exist!")
    a.whyrun("Init script '#{default_init_command}' doesn't exist, assuming a prior action would have created it.") do
      # blindly assume that the service exists but is stopped in why run mode:
      @status_load_success = false
    end
  end
end
reload_service() click to toggle source
# File lib/chef/provider/service/init.rb, line 83
def reload_service
  if @new_resource.reload_command
    super
  elsif supports[:reload]
    shell_out!("#{default_init_command} reload", default_env: false)
  end
end
restart_service() click to toggle source
# File lib/chef/provider/service/init.rb, line 71
def restart_service
  if @new_resource.restart_command
    super
  elsif supports[:restart]
    shell_out!("#{default_init_command} restart", default_env: false)
  else
    stop_service
    sleep 1
    start_service
  end
end
start_service() click to toggle source
# File lib/chef/provider/service/init.rb, line 55
def start_service
  if @new_resource.start_command
    super
  else
    shell_out!("#{default_init_command} start", default_env: false)
  end
end
stop_service() click to toggle source
# File lib/chef/provider/service/init.rb, line 63
def stop_service
  if @new_resource.stop_command
    super
  else
    shell_out!("#{default_init_command} stop", default_env: false)
  end
end