# class Chef::Resource::Service

### Public Class Methods

new(name, run_context=nil) click to toggle source
Calls superclass method Chef::Resource.new

    # File lib/chef/resource/service.rb, line 30
    def initialize(name, run_context=nil)
      super
      @resource_name = :service
      @service_name = name
      @enabled = nil
      @running = nil
      @parameters = nil
      @pattern = service_name
      @start_command = nil
      @stop_command = nil
      @status_command = nil
      @restart_command = nil
      @reload_command = nil
      @init_command = nil
      @priority = nil
      @action = "nothing"
      @supports = { :restart => false, :reload => false, :status => false }
      @allowed_actions.push(:enable, :disable, :start, :stop, :restart, :reload)
    end

### Public Instance Methods

enabled(arg=nil) click to toggle source

if the service is enabled or not

    # File lib/chef/resource/service.rb, line 125
    def enabled(arg=nil)
      set_or_return(
        :enabled,
        arg,
        :kind_of => [ TrueClass, FalseClass ]
      )
    end

init_command(arg=nil) click to toggle source

The path to the init script associated with the service. On many distributions this is ‘/etc/init.d/SERVICE_NAME’ by default. In non-standard configurations setting this value will save having to specify overrides for the #start_command, #stop_command and #restart_command attributes.

    # File lib/chef/resource/service.rb, line 116
    def init_command(arg=nil)
      set_or_return(
        :init_command,
        arg,
        :kind_of => [ String ]
      )
    end

parameters(arg=nil) click to toggle source

    # File lib/chef/resource/service.rb, line 158
    def parameters(arg=nil)
      set_or_return(
        :parameters,
        arg,
        :kind_of => [ Hash ] )
    end

pattern(arg=nil) click to toggle source

regex for match against ps -ef when !supports && status == nil

    # File lib/chef/resource/service.rb, line 59
    def pattern(arg=nil)
      set_or_return(
        :pattern,
        arg,
        :kind_of => [ String ]
      )
    end

priority(arg=nil) click to toggle source

Priority arguments can have two forms:

- a simple number, in which the default start runlevels get that as the start value and stop runlevels get 100 - value.

- a hash like { 2 => [:start, 20], 3 => [:stop, 55] }, where the service will be marked as started with priority 20 in runlevel 2, stopped in 3 with priority 55 and no symlinks or similar for other runlevels

    # File lib/chef/resource/service.rb, line 152
    def priority(arg=nil)
      set_or_return(:priority,
                    arg,
                    :kind_of => [ Integer, String, Hash ])
    end

reload_command(arg=nil) click to toggle source

    # File lib/chef/resource/service.rb, line 103
    def reload_command(arg=nil)
      set_or_return(
        :reload_command,
        arg,
        :kind_of => [ String ]
      )
    end

restart_command(arg=nil) click to toggle source

command to call to restart service

    # File lib/chef/resource/service.rb, line 95
    def restart_command(arg=nil)
      set_or_return(
        :restart_command,
        arg,
        :kind_of => [ String ]
      )
    end

running(arg=nil) click to toggle source

if the service is running or not

    # File lib/chef/resource/service.rb, line 134
    def running(arg=nil)
      set_or_return(
        :running,
        arg,
        :kind_of => [ TrueClass, FalseClass ]
      )
    end

service_name(arg=nil) click to toggle source

    # File lib/chef/resource/service.rb, line 50
    def service_name(arg=nil)
      set_or_return(
        :service_name,
        arg,
        :kind_of => [ String ]
      )
    end

start_command(arg=nil) click to toggle source

command to call to start service

    # File lib/chef/resource/service.rb, line 68
    def start_command(arg=nil)
      set_or_return(
        :start_command,
        arg,
        :kind_of => [ String ]
      )
    end

status_command(arg=nil) click to toggle source

command to call to get status of service

    # File lib/chef/resource/service.rb, line 86
    def status_command(arg=nil)
      set_or_return(
        :status_command,
        arg,
        :kind_of => [ String ]
      )
    end

stop_command(arg=nil) click to toggle source

command to call to stop service

    # File lib/chef/resource/service.rb, line 77
    def stop_command(arg=nil)
      set_or_return(
        :stop_command,
        arg,
        :kind_of => [ String ]
      )
    end

supports(args={}) click to toggle source

    # File lib/chef/resource/service.rb, line 165
    def supports(args={})
      if args.is_a? Array
        args.each { |arg| @supports[arg] = true }
      elsif args.any?
        @supports = args
      else
        @supports
      end
    end