class Chef::Provider::Service::Daemontools

Constants

VERSION

Public Class Methods

new(new_resource, run_context=nil) click to toggle source
Calls superclass method
# File lib/chef/provider/service/daemontools.rb, line 34
def initialize(new_resource, run_context=nil)
  super
  @svc_command    = 'svc'
  @svstat_command = 'svstat'
end

Public Instance Methods

disable_service() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 54
def disable_service
  if @current_resource.enabled
    service_link = "#{@new_resource.service_dir}/#{@new_resource.service_name}"
    shell_out!("rm -f #{service_link} && #{@svc_command} -dx . log", :cwd => service_link)
  end
end
enable_service() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 48
def enable_service
  if !@current_resource.enabled
    ::File.symlink(@new_resource.directory, "#{@new_resource.service_dir}/#{@new_resource.service_name}")
  end
end
load_current_resource() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 40
def load_current_resource
  @current_resource = Chef::Resource::Service.new(@new_resource.name)
  @current_resource.service_name(@new_resource.service_name)

  service_status!
  @current_resource
end
reload_service() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 73
def reload_service
  if @current_resource.enabled && @current_resource.running
    shell_out!("#{@svc_command} -h #{@new_resource.service_dir}/#{@new_resource.service_name}")
  end
end
restart_service() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 79
def restart_service
  if @current_resource.enabled && @current_resource.running
    shell_out!("#{@svc_command} -t #{@new_resource.service_dir}/#{@new_resource.service_name}")
  end
end
service_status!() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 85
def service_status!
  service_link = "#{@current_resource.service_dir}/#{@current_resource.service_name}"
  if ::File.symlink?(service_link) && ::File.exist?("#{service_link}/run")
    @current_resource.enabled(true)
    status = shell_out!("#{@svstat_command} #{service_link}")
    if status.exitstatus == 0

      retry_count = 4
      while status.stdout =~ /: supervise not running/ or status.stdout =~ /: unable to open supervise\/ok/
        sleep 1
        retry_count -= 1
        status = shell_out!("#{@svstat_command} #{service_link}")
        break if retry_count < 0
      end

      if status.stdout =~ /: up \(pid [1-9]/
        @current_resource.running(true)
      elsif status.stdout =~ /: down [1-9]/
        @current_resource.running(false)
      else
        @current_resource.running(false)
      end
    else
      @current_resource.running(false)
    end
  else
    @current_resource.enabled(false)
    @current_resource.running(false)
  end

  @current_resource
end
start_service() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 61
def start_service
  if @current_resource.enabled && !@current_resource.running
    shell_out!("#{@svc_command} -u #{@new_resource.service_dir}/#{@new_resource.service_name}")
  end
end
stop_service() click to toggle source
# File lib/chef/provider/service/daemontools.rb, line 67
def stop_service
  if @current_resource.enabled && @current_resource.running
    shell_out!("#{@svc_command} -d #{@new_resource.service_dir}/#{@new_resource.service_name}")
  end
end