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 40
def initialize(name, run_context = nil)
  super
  @service_name = name
  @enabled = nil
  @running = nil
  @masked = nil
  @options = 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
  @timeout = nil
  @run_levels = nil
  @user = nil
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 136
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 127
def init_command(arg = nil)
  set_or_return(
    :init_command,
    arg,
    :kind_of => [ String ]
  )
end
masked(arg = nil) click to toggle source

if the service is masked or not

# File lib/chef/resource/service.rb, line 154
def masked(arg = nil)
  set_or_return(
    :masked,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end
options(arg = nil) click to toggle source
# File lib/chef/resource/service.rb, line 162
def options(arg = nil)
  set_or_return(
    :options,
    arg.respond_to?(:split) ? arg.shellsplit : arg,
    :kind_of => [ Array, String ]
  )
end
parameters(arg = nil) click to toggle source
# File lib/chef/resource/service.rb, line 197
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 70
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 180
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 114
def reload_command(arg = nil)
  set_or_return(
    :reload_command,
    arg,
    :kind_of => [ String, NilClass, FalseClass ]
  )
end
restart_command(arg = nil) click to toggle source

command to call to restart service

# File lib/chef/resource/service.rb, line 106
def restart_command(arg = nil)
  set_or_return(
    :restart_command,
    arg,
    :kind_of => [ String, NilClass, FalseClass ]
  )
end
run_levels(arg = nil) click to toggle source
# File lib/chef/resource/service.rb, line 205
def run_levels(arg = nil)
  set_or_return(
    :run_levels,
    arg,
    :kind_of => [ Array ] )
end
running(arg = nil) click to toggle source

if the service is running or not

# File lib/chef/resource/service.rb, line 145
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 61
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 79
def start_command(arg = nil)
  set_or_return(
    :start_command,
    arg,
    :kind_of => [ String, NilClass, FalseClass ]
  )
end
status_command(arg = nil) click to toggle source

command to call to get status of service

# File lib/chef/resource/service.rb, line 97
def status_command(arg = nil)
  set_or_return(
    :status_command,
    arg,
    :kind_of => [ String, NilClass, FalseClass ]
  )
end
stop_command(arg = nil) click to toggle source

command to call to stop service

# File lib/chef/resource/service.rb, line 88
def stop_command(arg = nil)
  set_or_return(
    :stop_command,
    arg,
    :kind_of => [ String, NilClass, FalseClass ]
  )
end
timeout(arg = nil) click to toggle source

timeout only applies to the windows service manager

# File lib/chef/resource/service.rb, line 189
def timeout(arg = nil)
  set_or_return(
    :timeout,
    arg,
    :kind_of => Integer
  )
end
user(arg = nil) click to toggle source
# File lib/chef/resource/service.rb, line 212
def user(arg = nil)
  set_or_return(
    :user,
    arg,
    :kind_of => [ String ]
  )
end