Module: Chef::Container::Runit

Included in:
Provider::Service::ChefContainer
Defined in:
lib/chef/container/runit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#service_dirObject (readonly)

Returns the value of attribute service_dir.



23
24
25
# File 'lib/chef/container/runit.rb', line 23

def service_dir
  @service_dir
end

#sv_binObject (readonly)

Returns the value of attribute sv_bin.



21
22
23
# File 'lib/chef/container/runit.rb', line 21

def sv_bin
  @sv_bin
end

#sv_dirObject (readonly)

Helper Resources



64
65
66
# File 'lib/chef/container/runit.rb', line 64

def sv_dir
  @sv_dir
end

Instance Method Details

#default_log_dirObject



80
81
82
83
84
85
86
# File 'lib/chef/container/runit.rb', line 80

def default_log_dir
  return @default_log_dir unless @default_log_dir.nil?
  @default_log_dir = Chef::Resource::Directory.new(::File.join("/var/log/#{new_resource.service_name}"), run_context)
  @default_log_dir.recursive(true)
  @default_log_dir.mode(00755)
  @default_log_dir
end

#log_dirObject



88
89
90
91
92
93
94
# File 'lib/chef/container/runit.rb', line 88

def log_dir 
  return @log_dir unless @log_dir.nil?
  @log_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log'), run_context)
  @log_dir.recursive(true)
  @log_dir.mode(00755)
  @log_dir
end

#log_run_scriptObject



96
97
98
99
100
101
102
# File 'lib/chef/container/runit.rb', line 96

def log_run_script
  return @log_run_script unless @log_run_script.nil?
  @log_run_script = Chef::Resource::File.new(::File.join(sv_dir_name, 'log', 'run'))
  @log_run_script.content(log_run_script_content)
  @log_run_script.mode(00755)
  @log_run_script
end

#log_run_script_contentObject



57
58
59
# File 'lib/chef/container/runit.rb', line 57

def log_run_script_content
  "#!/bin/sh\nexec svlogd -tt /var/log/#{new_resource.service_name}"
end

#run_scriptObject



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

def run_script
  return @run_script unless @run_script.nil?
  @run_script = Chef::Resource::File.new(::File.join(sv_dir_name, 'run'), run_context)
  @run_script.content(run_script_content(new_resource.command))
  @run_script.mode(00755)
  @run_script
end

#run_script_content(command) ⇒ Object



53
54
55
# File 'lib/chef/container/runit.rb', line 53

def run_script_content(command)
  "#!/bin/sh\n#{command} 2&>1"
end

#service_dir_nameObject



49
50
51
# File 'lib/chef/container/runit.rb', line 49

def service_dir_name
  ::File.join(new_resource.service_dir, new_resource.service_name)
end

#setupObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/container/runit.rb', line 25

def setup
  @sv_bin = '/opt/chef/embedded/bin/sv'
  @sv_dir = '/opt/chef/embedded/sv'
  @service_dir = '/opt/chef/embedded/service'

  Chef::Log.debug "Creating sv_dir for #{new_resource.name}"
  sv_dir.run_action(:create)

  Chef::Log.debug "Creating run_script for #{new_resource.name}"
  run_script.run_action(:create)

  Chef::Log.debug "Setting up svlog for #{new_resource.name}"
  default_log_dir.run_action(:create)
  log_dir.run_action(:create)
  log_run_script.run_action(:create)
end

#sv_dir_nameObject

Helper Resource Methods



45
46
47
# File 'lib/chef/container/runit.rb', line 45

def sv_dir_name
  ::File.join(@service_resource.sv_dir, new_resource.service_name)
end