Class: Chef::Provider::Service::ChefContainer
- Inherits:
-
Chef::Provider::Service
- Object
- Chef::Provider::Service
- Chef::Provider::Service::ChefContainer
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/chef/provider/service/container.rb
Overview
container_service
Instance Method Summary collapse
- #disable_service ⇒ Object
-
#enable_service ⇒ Object
Override Service Actions.
- #enabled? ⇒ Boolean
-
#initialize(*args) ⇒ ChefContainer
constructor
A new instance of ChefContainer.
- #load_current_resource ⇒ Object
- #reload_service ⇒ Object
- #restart_service ⇒ Object
- #running? ⇒ Boolean
- #service_dir_name ⇒ Object
-
#service_link ⇒ Object
Helper Resources.
- #start_service ⇒ Object
- #stop_service ⇒ Object
-
#sv_dir_name ⇒ Object
Helper Resource Methods.
Constructor Details
#initialize(*args) ⇒ ChefContainer
Returns a new instance of ChefContainer.
33 34 35 36 37 38 |
# File 'lib/chef/provider/service/container.rb', line 33 def initialize(*args) super @service_link = nil @service_endpoint = sv_dir_name @new_resource.supports[:status] = true end |
Instance Method Details
#disable_service ⇒ Object
79 80 81 82 83 84 |
# File 'lib/chef/provider/service/container.rb', line 79 def disable_service shell_out("#{Chef::Container::Runit::SV_BIN} down #{service_dir_name}") Chef::Log.debug("#{new_resource} down") FileUtils.rm(service_dir_name) Chef::Log.debug("#{new_resource} service symlink removed") end |
#enable_service ⇒ Object
Override Service Actions
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/chef/provider/service/container.rb', line 61 def enable_service Chef::Log.debug("Creating symlink in service_dir for #{new_resource.service_name}") service_link.run_action(:create) @service_endpoint = service_dir_name Chef::Log.debug("waiting until named pipe #{service_dir_name}/supervise/ok exists.") until ::FileTest.pipe?("#{service_dir_name}/supervise/ok") sleep 1 Chef::Log.debug('.') end Chef::Log.debug("waiting until named pipe #{service_dir_name}/log/supervise/ok exists.") until ::FileTest.pipe?("#{service_dir_name}/log/supervise/ok") sleep 1 Chef::Log.debug('.') end end |
#enabled? ⇒ Boolean
111 112 113 |
# File 'lib/chef/provider/service/container.rb', line 111 def enabled? ::File.exists?(::File.join(service_dir_name, 'run')) end |
#load_current_resource ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chef/provider/service/container.rb', line 40 def load_current_resource @current_resource = Chef::Resource::RunitService.new(new_resource.name) @current_resource.service_name(new_resource.service_name) Chef::Log.debug("Checking status of service #{new_resource.service_name}") # verify Runit was installed properly unless ::File.exist?(Chef::Container::Runit::SV_BIN) && ::File.executable?(Chef::Container::Runit::SV_BIN) = "Could not locate main runit sv_bin at \"#{Chef::Container::Runit::SV_BIN}\"." fail end @current_resource.running(running?) @current_resource.enabled(enabled?) @current_resource end |
#reload_service ⇒ Object
102 103 104 |
# File 'lib/chef/provider/service/container.rb', line 102 def reload_service shell_out!("#{Chef::Container::Runit::SV_BIN} force-reload #{@service_endpoint}") end |
#restart_service ⇒ Object
98 99 100 |
# File 'lib/chef/provider/service/container.rb', line 98 def restart_service shell_out!("#{Chef::Container::Runit::SV_BIN} restart #{@service_endpoint}") end |
#running? ⇒ Boolean
106 107 108 109 |
# File 'lib/chef/provider/service/container.rb', line 106 def running? cmd = shell_out("#{Chef::Container::Runit::SV_BIN} status #{@service_endpoint}") (cmd.stdout =~ /^run:/ && cmd.exitstatus == 0) end |
#service_dir_name ⇒ Object
122 123 124 |
# File 'lib/chef/provider/service/container.rb', line 122 def service_dir_name ::File.join(Chef::Container::Runit::SERVICE_DIR, new_resource.service_name) end |
#service_link ⇒ Object
Helper Resources
130 131 132 133 134 135 |
# File 'lib/chef/provider/service/container.rb', line 130 def service_link return @service_link unless @service_link.nil? @service_link = Chef::Resource::Link.new(::File.join(service_dir_name), run_context) @service_link.to(sv_dir_name) @service_link end |
#start_service ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/chef/provider/service/container.rb', line 86 def start_service if enabled? shell_out!("#{Chef::Container::Runit::SV_BIN} start #{@service_endpoint}") else shell_out!("#{Chef::Container::Runit::RUNSV_BIN} #{@service_endpoint} &") end end |