Included Modules

Files

Class/Module Index [+]

Quicksearch

Chef::Provider::Service::Windows

Constants

AUTO_START

Win32::Service.get_start_type

CONTINUE_PENDING
DISABLED
PAUSED
PAUSE_PENDING
RUNNING

Win32::Service.get_current_state

START_PENDING
STOPPED
STOP_PENDING
TIMEOUT

Public Instance Methods

disable_service() click to toggle source
# File lib/chef/provider/service/windows.rb, line 145
def disable_service
  if Win32::Service.exists?(@new_resource.service_name)
    if start_type == AUTO_START
      Win32::Service.configure(
        :service_name => @new_resource.service_name,
        :start_type => Win32::Service::DISABLED
      )
      @new_resource.updated_by_last_action(true)
    else
      Chef::Log.debug "#{@new_resource} already disabled - nothing to do"
    end
  else
    Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
  end
end
enable_service() click to toggle source
# File lib/chef/provider/service/windows.rb, line 129
def enable_service
  if Win32::Service.exists?(@new_resource.service_name)
    if start_type == AUTO_START
      Chef::Log.debug "#{@new_resource} already enabled - nothing to do"
    else
      Win32::Service.configure(
        :service_name => @new_resource.service_name,
        :start_type => Win32::Service::AUTO_START
      )
      @new_resource.updated_by_last_action(true)
    end
  else
    Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
  end
end
load_current_resource() click to toggle source
# File lib/chef/provider/service/windows.rb, line 50
def load_current_resource
  @current_resource = Chef::Resource::Service.new(@new_resource.name)
  @current_resource.service_name(@new_resource.service_name)
  @current_resource.running(current_state == RUNNING)
  Chef::Log.debug "#{@new_resource} running: #{@current_resource.running}"
  @current_resource.enabled(start_type == AUTO_START)
  Chef::Log.debug "#{@new_resource} enabled: #{@current_resource.enabled}"
  @current_resource
end
restart_service() click to toggle source
# File lib/chef/provider/service/windows.rb, line 114
def restart_service
  if Win32::Service.exists?(@new_resource.service_name)
    if @new_resource.restart_command
      Chef::Log.debug "#{@new_resource} restarting service using the given restart_command"
      shell_out!(@new_resource.restart_command)
    else
      stop_service
      start_service
    end
    @new_resource.updated_by_last_action(true)
  else
    Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
  end
end
start_service() click to toggle source
# File lib/chef/provider/service/windows.rb, line 60
def start_service
  if Win32::Service.exists?(@new_resource.service_name)
    state = current_state
    if state == RUNNING
      Chef::Log.debug "#{@new_resource} already started - nothing to do"
    elsif state == START_PENDING
      Chef::Log.debug "#{@new_resource} already sent start signal - waiting for start"
      wait_for_state(RUNNING)
    elsif state == STOPPED
      if @new_resource.start_command
        Chef::Log.debug "#{@new_resource} starting service using the given start_command"
        shell_out!(@new_resource.start_command)
      else
        spawn_command_thread do
          Win32::Service.start(@new_resource.service_name)
        end
        wait_for_state(RUNNING)
      end
      @new_resource.updated_by_last_action(true)
    else
      raise Chef::Exceptions::Service, "Service #{@new_resource} can't be started from state [#{state}]"
    end
  else
    Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
  end
end
stop_service() click to toggle source
# File lib/chef/provider/service/windows.rb, line 87
def stop_service
  if Win32::Service.exists?(@new_resource.service_name)
    state = current_state
    if state == RUNNING
      if @new_resource.stop_command
        Chef::Log.debug "#{@new_resource} stopping service using the given stop_command"
        shell_out!(@new_resource.stop_command)
      else
        spawn_command_thread do
          Win32::Service.stop(@new_resource.service_name)
        end
        wait_for_state(STOPPED)
      end
      @new_resource.updated_by_last_action(true)
    elsif state == STOPPED
      Chef::Log.debug "#{@new_resource} already stopped - nothing to do"
    elsif state == STOP_PENDING
      Chef::Log.debug "#{@new_resource} already sent stop signal - waiting for stop"
      wait_for_state(STOPPED)
    else
      raise Chef::Exceptions::Service, "Service #{@new_resource} can't be stopped from state [#{state}]"
    end
  else
    Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
  end
end
whyrun_supported?() click to toggle source
# File lib/chef/provider/service/windows.rb, line 46
def whyrun_supported?
  false
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.