Class: KongCookbook::KongServiceProvider

Inherits:
Chef::Provider::Service::Init
  • Object
show all
Defined in:
libraries/kong_service_provider.rb

Overview

Chef service provider for the Kong init script.

Examples:

service 'kong' do
  provider KongCookbook::KongServiceProvider
  action :start
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_resource, run_context) ⇒ KongServiceProvider

KongServiceProvider constructor.

Sets init command, supported actions and status command.

Parameters:

  • new_resource (Chef::Resource)

    New resource.

  • run_context (Chef::RunContext)

    Chef Run Context.


44
45
46
47
48
49
# File 'libraries/kong_service_provider.rb', line 44

def initialize(new_resource, run_context)
  super
  @init_command = 'kong'
  new_resource.supports(restart: true, reload: true, status: true)
  new_resource.status_command('kill -0 $(cat /usr/local/kong/kong.pid)')
end

Instance Attribute Details

#init_commandObject (readonly)

Gets Init Command.


36
37
38
# File 'libraries/kong_service_provider.rb', line 36

def init_command
  @init_command
end

Instance Method Details

#define_resource_requirementsObject

Defines some Resource Requirements to check that Kong init script is installed and supports the required actions.

The Requirement raises a Chef::Exceptions::Service exception if not met.

Examples:

define_resource_requirements

Returns:

  • void


118
119
120
121
122
123
# File 'libraries/kong_service_provider.rb', line 118

def define_resource_requirements
  shared_resource_requirements

  all_actions_requirements
  actions_requirements
end

#restart_serviceMixed

Restarts the service using the correct user limits ($ ulimit -n).

Examples:

restart_service

Returns:

  • (Mixed)

    The Chef::Provider::Service::Init#restart_service result.


194
195
196
# File 'libraries/kong_service_provider.rb', line 194

def restart_service
  run_within_ulimit { super }
end

#run_within_ulimit { ... } ⇒ Mixed

Runs a block with the correct user limits required by Kong.

Examples:

def start_service
  run_within_ulimit { super }
end

Yields:

  • [] the block to run.

Returns:

  • (Mixed)

    The value returned by the block.


170
171
172
173
174
175
# File 'libraries/kong_service_provider.rb', line 170

def run_within_ulimit(&block)
  old_limit = ulimit_nofile_minimum(4096)
  value = block.call
  ulimit_nofile(old_limit)
  value
end

#start_serviceMixed

Starts the service using the correct user limits ($ ulimit -n).

Examples:

start_service

Returns:

  • (Mixed)

    The Chef::Provider::Service::Init#start_service result.


183
184
185
# File 'libraries/kong_service_provider.rb', line 183

def start_service
  run_within_ulimit { super }
end