Class: Chef::Provider::Service::Systemd

Inherits:
Simple show all
Defined in:
lib/chef/provider/service/systemd.rb

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Simple

#ps_cmd

Methods inherited from Chef::Provider::Service

#action_disable, #action_enable, #action_reload, #action_restart, #action_start, #action_stop, #initialize

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Windows

#popen4

Methods included from Mixin::Command::Unix

#popen4

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #initialize, #node, #resource_collection

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

This class inherits a constructor from Chef::Provider::Service

Dynamic Method Handling

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

Instance Method Details

#disable_serviceObject



91
92
93
# File 'lib/chef/provider/service/systemd.rb', line 91

def disable_service
  run_command_with_systems_locale(:command => "/bin/systemctl disable #{@new_resource.service_name}")
end

#enable_serviceObject



87
88
89
# File 'lib/chef/provider/service/systemd.rb', line 87

def enable_service
  run_command_with_systems_locale(:command => "/bin/systemctl enable #{@new_resource.service_name}")
end

#is_active?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/chef/provider/service/systemd.rb', line 95

def is_active?
  run_command_with_systems_locale({:command => "/bin/systemctl is-active #{@new_resource.service_name}", :ignore_failure => true}) == 0
end

#is_enabled?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/chef/provider/service/systemd.rb', line 99

def is_enabled?
  run_command_with_systems_locale({:command => "/bin/systemctl is-enabled #{@new_resource.service_name}", :ignore_failure => true}) == 0
end

#load_current_resourceObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chef/provider/service/systemd.rb', line 24

def load_current_resource
  @current_resource = Chef::Resource::Service.new(@new_resource.name)
  @current_resource.service_name(@new_resource.service_name)

  if @new_resource.status_command
    Chef::Log.debug("#{@new_resource} you have specified a status command, running..")

    begin
      if run_command_with_systems_locale(:command => @new_resource.status_command) == 0
        @current_resource.running(true)
      end
    rescue Chef::Exceptions::Exec
      @current_resource.running(false)
      nil
    end
  else
    @current_resource.running(is_active?)
  end

  @current_resource.enabled(is_enabled?)
  @current_resource
end

#reload_serviceObject



79
80
81
82
83
84
85
# File 'lib/chef/provider/service/systemd.rb', line 79

def reload_service
  if @new_resource.reload_command
    super
  else
    run_command_with_systems_locale(:command => "/bin/systemctl reload #{@new_resource.service_name}")
  end
end

#restart_serviceObject



71
72
73
74
75
76
77
# File 'lib/chef/provider/service/systemd.rb', line 71

def restart_service
  if @new_resource.restart_command
    super
  else
    run_command_with_systems_locale(:command => "/bin/systemctl restart #{@new_resource.service_name}")
  end
end

#start_serviceObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/provider/service/systemd.rb', line 47

def start_service
  if @current_resource.running
    Chef::Log.debug("#{@new_resource} already running, not starting")
  else
    if @new_resource.start_command
      super
    else
      run_command_with_systems_locale(:command => "/bin/systemctl start #{@new_resource.service_name}")
    end
  end
end

#stop_serviceObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef/provider/service/systemd.rb', line 59

def stop_service
  unless @current_resource.running
    Chef::Log.debug("#{@new_resource} not running, not stopping")
  else
    if @new_resource.stop_command
      super
    else
      run_command_with_systems_locale(:command => "/bin/systemctl stop #{@new_resource.service_name}")
    end
  end
end