Class: Chef::Provider::Service::ChefContainer

Inherits:
Chef::Provider::Service show all
Includes:
Mixin::ShellOut
Defined in:
lib/chef/provider/service/container.rb

Overview

container_service

Instance Method Summary collapse

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_serviceObject



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_serviceObject

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

Returns:

  • (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_resourceObject



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)
    no_runit_message = "Could not locate main runit sv_bin at \"#{Chef::Container::Runit::SV_BIN}\"."
    fail no_runit_message
  end

  @current_resource.running(running?)
  @current_resource.enabled(enabled?)
  @current_resource
end

#reload_serviceObject



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_serviceObject



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

Returns:

  • (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_nameObject



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

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_serviceObject



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

#stop_serviceObject



94
95
96
# File 'lib/chef/provider/service/container.rb', line 94

def stop_service
  shell_out!("#{Chef::Container::Runit::SV_BIN} stop #{@service_endpoint}")
end

#sv_dir_nameObject

Helper Resource Methods



118
119
120
# File 'lib/chef/provider/service/container.rb', line 118

def sv_dir_name
  ::File.join(Chef::Container::Runit::SV_DIR, new_resource.service_name)
end