Class: Chef::Resource::Service

Inherits:
Chef::Resource show all
Defined in:
lib/chef/resource/service.rb

Direct Known Subclasses

MacosxService, WindowsService

Constant Summary

Constants inherited from Chef::Resource

FORBIDDEN_IVARS, HIDDEN_IVARS

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Attribute Summary

Attributes inherited from Chef::Resource

#allowed_actions, #cookbook_name, #declared_type, #default_guard_interpreter, #elapsed_time, #enclosing_provider, #ignore_failure, #not_if_args, #only_if_args, #params, #recipe_name, #resource_initializing, #retries, #retry_delay, #run_context, #sensitive, #source_line, #updated

Instance Method Summary collapse

Methods inherited from Chef::Resource

action, #action, #action=, action_class, #after_created, allowed_actions, allowed_actions=, #as_json, #before_notifications, #cookbook_version, #current_value, #current_value_does_not_exist!, #custom_exception_message, #customize_exception, declare_action_class, #declared_key, default_action, default_action=, #defined_at, #delayed_notifications, dsl_name, #events, #guard_interpreter, #identity, identity_attr, identity_property, #immediate_notifications, inherited, #inspect, #is, json_create, load_current_value, #load_from, #lookup_provider_constant, #method_missing, #name, #node, #noop, #not_if, #notifies, #notifies_before, #notifies_delayed, #notifies_immediately, #only_if, #provider, #provider=, provider_base, #provider_for_action, provides, provides?, #resolve_notification_references, resource_for_node, resource_matching_short_name, #resource_name, resource_name, resource_name=, #resources, #run_action, #should_skip?, sorted_descendants, #source_line_file, #source_line_number, state_attrs, #state_for_resource_reporter, #subscribes, #supports=, #to_hash, #to_json, #to_s, #to_text, #updated?, #updated_by_last_action, #updated_by_last_action?, use_automatic_resource_name, #validate_action, #validate_resource_spec!

Methods included from Mixin::Provides

#provided_as, #provides, #provides?

Methods included from Mixin::DescendantsTracker

#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited

Methods included from Mixin::ConvertToClassName

#constantize, #convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #normalize_snake_case_name, #snake_case_basename

Methods included from DeprecatedLWRPClass

#deprecated_constants, #register_deprecated_lwrp_class

Methods included from Mixin::Deprecation

#deprecated_attr, #deprecated_attr_reader, #deprecated_attr_writer, #deprecated_ivar

Methods included from Mixin::Properties

included, #property_is_set?, #reset_property

Methods included from Mixin::ParamsValidate

#lazy, #set_or_return, #validate

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!

Methods included from Mixin::PowershellOut

#powershell_out, #powershell_out!

Methods included from Mixin::WindowsArchitectureHelper

#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory

Methods included from DSL::PlatformIntrospection

#docker?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Methods included from DSL::RebootPending

#reboot_pending?

Methods included from DSL::RegistryHelper

#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?

Methods included from DSL::DataQuery

#data_bag, #data_bag_item, #search

Methods included from EncryptedDataBagItem::CheckEncrypted

#encrypted?

Constructor Details

#initialize(name, run_context = nil) ⇒ Service

Returns a new instance of Service.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef/resource/service.rb', line 33

def initialize(name, run_context = nil)
  super
  @service_name = name
  @enabled = nil
  @running = nil
  @masked = 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
  @supports = { :restart => nil, :reload => nil, :status => nil }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Resource

Instance Method Details

#enabled(arg = nil) ⇒ Object

if the service is enabled or not



129
130
131
132
133
134
135
# File 'lib/chef/resource/service.rb', line 129

def enabled(arg = nil)
  set_or_return(
    :enabled,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#init_command(arg = nil) ⇒ Object

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.



120
121
122
123
124
125
126
# File 'lib/chef/resource/service.rb', line 120

def init_command(arg = nil)
  set_or_return(
    :init_command,
    arg,
    :kind_of => [ String ]
  )
end

#masked(arg = nil) ⇒ Object

if the service is masked or not



147
148
149
150
151
152
153
# File 'lib/chef/resource/service.rb', line 147

def masked(arg = nil)
  set_or_return(
    :masked,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#parameters(arg = nil) ⇒ Object



182
183
184
185
186
187
188
# File 'lib/chef/resource/service.rb', line 182

def parameters(arg = nil)
  set_or_return(
    :parameters,
    arg,
    :kind_of => [ Hash ]
  )
end

#pattern(arg = nil) ⇒ Object

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



63
64
65
66
67
68
69
# File 'lib/chef/resource/service.rb', line 63

def pattern(arg = nil)
  set_or_return(
    :pattern,
    arg,
    :kind_of => [ String ]
  )
end

#priority(arg = nil) ⇒ Object

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



165
166
167
168
169
170
171
# File 'lib/chef/resource/service.rb', line 165

def priority(arg = nil)
  set_or_return(
    :priority,
    arg,
    :kind_of => [ Integer, String, Hash ]
  )
end

#reload_command(arg = nil) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/chef/resource/service.rb', line 107

def reload_command(arg = nil)
  set_or_return(
    :reload_command,
    arg,
    :kind_of => [ String ]
  )
end

#restart_command(arg = nil) ⇒ Object

command to call to restart service



99
100
101
102
103
104
105
# File 'lib/chef/resource/service.rb', line 99

def restart_command(arg = nil)
  set_or_return(
    :restart_command,
    arg,
    :kind_of => [ String ]
  )
end

#run_levels(arg = nil) ⇒ Object



190
191
192
193
194
195
# File 'lib/chef/resource/service.rb', line 190

def run_levels(arg = nil)
  set_or_return(
    :run_levels,
    arg,
    :kind_of => [ Array ] )
end

#running(arg = nil) ⇒ Object

if the service is running or not



138
139
140
141
142
143
144
# File 'lib/chef/resource/service.rb', line 138

def running(arg = nil)
  set_or_return(
    :running,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#service_name(arg = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/chef/resource/service.rb', line 54

def service_name(arg = nil)
  set_or_return(
    :service_name,
    arg,
    :kind_of => [ String ]
  )
end

#start_command(arg = nil) ⇒ Object

command to call to start service



72
73
74
75
76
77
78
# File 'lib/chef/resource/service.rb', line 72

def start_command(arg = nil)
  set_or_return(
    :start_command,
    arg,
    :kind_of => [ String ]
  )
end

#status_command(arg = nil) ⇒ Object

command to call to get status of service



90
91
92
93
94
95
96
# File 'lib/chef/resource/service.rb', line 90

def status_command(arg = nil)
  set_or_return(
    :status_command,
    arg,
    :kind_of => [ String ]
  )
end

#stop_command(arg = nil) ⇒ Object

command to call to stop service



81
82
83
84
85
86
87
# File 'lib/chef/resource/service.rb', line 81

def stop_command(arg = nil)
  set_or_return(
    :stop_command,
    arg,
    :kind_of => [ String ]
  )
end

#supports(args = {}) ⇒ Object



205
206
207
208
209
210
211
212
213
# File 'lib/chef/resource/service.rb', line 205

def supports(args = {})
  if args.is_a? Array
    args.each { |arg| @supports[arg] = true }
  elsif args.any?
    @supports = args
  else
    @supports
  end
end

#timeout(arg = nil) ⇒ Object

timeout only applies to the windows service manager



174
175
176
177
178
179
180
# File 'lib/chef/resource/service.rb', line 174

def timeout(arg = nil)
  set_or_return(
    :timeout,
    arg,
    :kind_of => Integer
  )
end

#user(arg = nil) ⇒ Object



197
198
199
200
201
202
203
# File 'lib/chef/resource/service.rb', line 197

def user(arg = nil)
  set_or_return(
    :user,
    arg,
    :kind_of => [ String ]
  )
end