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
# File 'lib/chef/provider/service/container.rb', line 33

def initialize(*args)
  super
  @service_link = nil
  @new_resource.supports[:status] = true
end

Instance Method Details

#disable_serviceObject



77
78
79
80
81
82
# File 'lib/chef/provider/service/container.rb', line 77

def disable_service
  shell_out("#{Chef::Container::Runit::SV_BIN} down #{sv_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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/chef/provider/service/container.rb', line 60

def enable_service
  Chef::Log.debug("Creating symlink in service_dir for #{new_resource.service_name}")
  service_link.run_action(:create)

  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)


110
111
112
# File 'lib/chef/provider/service/container.rb', line 110

def enabled?
  ::File.exists?(::File.join(service_dir_name, 'run'))
end

#load_current_resourceObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/provider/service/container.rb', line 39

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



101
102
103
# File 'lib/chef/provider/service/container.rb', line 101

def reload_service
  shell_out!("#{Chef::Container::Runit::SV_BIN} force-reload #{service_dir_name}")
end

#restart_serviceObject



97
98
99
# File 'lib/chef/provider/service/container.rb', line 97

def restart_service
  shell_out!("#{Chef::Container::Runit::SV_BIN} restart #{service_dir_name}")
end

#running?Boolean

Returns:

  • (Boolean)


105
106
107
108
# File 'lib/chef/provider/service/container.rb', line 105

def running?
  cmd = shell_out("#{Chef::Container::Runit::SV_BIN} status #{service_dir_name}")
  (cmd.stdout =~ /^run:/ && cmd.exitstatus == 0)
end

#service_dir_nameObject



121
122
123
# File 'lib/chef/provider/service/container.rb', line 121

def service_dir_name 
  ::File.join(Chef::Container::Runit::SERVICE_DIR, new_resource.service_name)
end

Helper Resources



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

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



84
85
86
87
88
89
90
91
# File 'lib/chef/provider/service/container.rb', line 84

def start_service
  if ::File.exists?(service_dir_name)
    shell_out!("#{Chef::Container::Runit::SV_BIN} start #{service_dir_name}")
  else
    service_link.run_action(:create)
    shell_out!("#{Chef::Container::Runit::RUNSV_BIN} #{service_dir_name} &")
  end
end

#stop_serviceObject



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

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

#sv_dir_nameObject

Helper Resource Methods



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

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