# class Chef::Provider::Service

### Public Class Methods

new(new_resource, run_context) click to toggle source
Calls superclass method Chef::Provider.new

    # File lib/chef/provider/service.rb, line 28
    def initialize(new_resource, run_context)
      super
      @enabled = nil
    end

### Public Instance Methods

action_disable() click to toggle source

    # File lib/chef/provider/service.rb, line 74
    def action_disable
      if @current_resource.enabled
        converge_by("disable service #{@new_resource}") do
          disable_service
          Chef::Log.info("#{@new_resource} disabled")
        end
      else
        Chef::Log.debug("#{@new_resource} already disabled - nothing to do")
      end
      load_new_resource_state
      @new_resource.enabled(false)
    end

action_enable() click to toggle source

    # File lib/chef/provider/service.rb, line 61
    def action_enable
      if @current_resource.enabled
        Chef::Log.debug("#{@new_resource} already enabled - nothing to do")
      else
        converge_by("enable service #{@new_resource}") do
          enable_service
          Chef::Log.info("#{@new_resource} enabled")
        end
      end
      load_new_resource_state
      @new_resource.enabled(true)
    end

action_reload() click to toggle source

    # File lib/chef/provider/service.rb, line 122
    def action_reload
      if @current_resource.running
        converge_by("reload service #{@new_resource}") do
          reload_service
          Chef::Log.info("#{@new_resource} reloaded")
        end
      end
      load_new_resource_state
    end

action_restart() click to toggle source

    # File lib/chef/provider/service.rb, line 113
    def action_restart
      converge_by("restart service #{@new_resource}") do
        restart_service
        Chef::Log.info("#{@new_resource} restarted")
      end
      load_new_resource_state
      @new_resource.running(true)
    end

action_start() click to toggle source

    # File lib/chef/provider/service.rb, line 87
    def action_start
      unless @current_resource.running
        converge_by("start service #{@new_resource}") do
          start_service
          Chef::Log.info("#{@new_resource} started")
        end
      else
        Chef::Log.debug("#{@new_resource} already running - nothing to do")
      end
      load_new_resource_state
      @new_resource.running(true)
    end

action_stop() click to toggle source

    # File lib/chef/provider/service.rb, line 100
    def action_stop
      if @current_resource.running
        converge_by("stop service #{@new_resource}") do
          stop_service
          Chef::Log.info("#{@new_resource} stopped")
        end
      else
        Chef::Log.debug("#{@new_resource} already stopped - nothing to do")
      end
      load_new_resource_state
      @new_resource.running(false)
    end

define_resource_requirements() click to toggle source

    # File lib/chef/provider/service.rb, line 51
    def define_resource_requirements
     requirements.assert(:reload) do |a|
       a.assertion { @new_resource.supports[:reload] || @new_resource.reload_command }
       a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
       # if a service is not declared to support reload, that won't
       # typically change during the course of a run - so no whyrun
       # alternative here.
     end
    end

disable_service() click to toggle source

    # File lib/chef/provider/service.rb, line 136
    def disable_service
      raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
    end

enable_service() click to toggle source

    # File lib/chef/provider/service.rb, line 132
    def enable_service
      raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
    end

load_new_resource_state() click to toggle source

    # File lib/chef/provider/service.rb, line 37
    def load_new_resource_state
       # If the user didn't specify a change in enabled state,
       # it will be the same as the old resource
      if ( @new_resource.enabled.nil? )
        @new_resource.enabled(@current_resource.enabled)
      end
      if ( @new_resource.running.nil? )
        @new_resource.running(@current_resource.running)
      end
    end

reload_service() click to toggle source

    # File lib/chef/provider/service.rb, line 152
    def reload_service
      raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
    end

restart_service() click to toggle source

    # File lib/chef/provider/service.rb, line 148
    def restart_service
      raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
    end

shared_resource_requirements() click to toggle source

    # File lib/chef/provider/service.rb, line 48
    def shared_resource_requirements
    end

start_service() click to toggle source

    # File lib/chef/provider/service.rb, line 140
    def start_service
      raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :start"
    end

stop_service() click to toggle source

    # File lib/chef/provider/service.rb, line 144
    def stop_service
      raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :stop"
    end

whyrun_supported?() click to toggle source

    # File lib/chef/provider/service.rb, line 33
    def whyrun_supported?
      true
    end

### Protected Instance Methods

custom_command_for_action?(action) click to toggle source

    # File lib/chef/provider/service.rb, line 166
    def custom_command_for_action?(action)
      method_name = "#{action}_command".to_sym
      @new_resource.respond_to?(method_name) &&
        !!@new_resource.send(method_name)
    end

default_init_command() click to toggle source

    # File lib/chef/provider/service.rb, line 158
    def default_init_command
      if @new_resource.init_command
        @new_resource.init_command
      elsif self.instance_variable_defined?(:@init_command)
        @init_command
      end
    end