# class Chef::Provider::Service::Windows

### Constants

AUTO_START
DISABLED
RUNNING
STOPPED

### Public Instance Methods

disable_service() click to toggle source

    # File lib/chef/provider/service/windows.rb, line 123
    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 107
    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 40
    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 92
    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 50
    def start_service
      if Win32::Service.exists?(@new_resource.service_name)
        if current_state == RUNNING
          Chef::Log.debug "#{@new_resource} already started - nothing to do"
        else
          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)
              wait_for_state(RUNNING)
            end
          end
          @new_resource.updated_by_last_action(true)
        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 71
    def stop_service
      if Win32::Service.exists?(@new_resource.service_name)
        if current_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)
              wait_for_state(STOPPED)
            end
          end
          @new_resource.updated_by_last_action(true)
        else
          Chef::Log.debug "#{@new_resource} already stopped - nothing to do"
        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 36
    def whyrun_supported?
      false
    end