module PoiseService::ServiceMixin::Provider

Mixin for service wrapper providers.

@see ServiceMixin

Public Instance Methods

action_disable() click to toggle source

Default disable action for service wrappers.

@return [void]

# File lib/poise_service/service_mixin.rb, line 96
def action_disable
  notify_if_service do
    service_resource.run_action(:disable)
  end
end
action_enable() click to toggle source

Default enable action for service wrappers.

@return [void]

# File lib/poise_service/service_mixin.rb, line 87
def action_enable
  notify_if_service do
    service_resource.run_action(:enable)
  end
end
action_reload() click to toggle source

Default reload action for service wrappers.

@return [void]

# File lib/poise_service/service_mixin.rb, line 132
def action_reload
  notify_if_service do
    service_resource.run_action(:reload)
  end
end
action_restart() click to toggle source

Default restart action for service wrappers.

@return [void]

# File lib/poise_service/service_mixin.rb, line 123
def action_restart
  notify_if_service do
    service_resource.run_action(:restart)
  end
end
action_start() click to toggle source

Default start action for service wrappers.

@return [void]

# File lib/poise_service/service_mixin.rb, line 105
def action_start
  notify_if_service do
    service_resource.run_action(:start)
  end
end
action_stop() click to toggle source

Default stop action for service wrappers.

@return [void]

# File lib/poise_service/service_mixin.rb, line 114
def action_stop
  notify_if_service do
    service_resource.run_action(:stop)
  end
end

Private Instance Methods

notify_if_service(&block) click to toggle source

Set the current resource as notified if the provided block updates the service resource.

@api public @param block [Proc] Block to run. @return [void] @example

notify_if_service do
  service_resource.run_action(:enable)
end
# File lib/poise_service/service_mixin.rb, line 152
def notify_if_service(&block)
  service_resource.updated_by_last_action(false)
  block.call if block
  new_resource.updated_by_last_action(true) if service_resource.updated_by_last_action?
end
service_options(resource) click to toggle source

Abstract hook to set parameters on {#service_resource} when it is created. This is required to set at least `resource.command`.

@api public @param resource [Chef::Resource] Resource instance to set parameters on. @return [void] @example

def service_options(resource)
  resource.command('myapp --serve')
end
# File lib/poise_service/service_mixin.rb, line 189
def service_options(resource)
end
service_resource() click to toggle source

Service resource for this service wrapper. This returns a poise_service resource that will not be added to the resource collection. Override {#service_options} to set service resource parameters.

@api public @return [Chef::Resource] @example

service_resource.run_action(:restart)
# File lib/poise_service/service_mixin.rb, line 167
def service_resource
  @service_resource ||= PoiseService::Resources::PoiseService::Resource.new(new_resource.name, run_context).tap do |r|
    # Set some defaults.
    r.declared_type = :poise_service
    r.enclosing_provider = self
    r.source_line = new_resource.source_line
    r.service_name(new_resource.service_name)
    # Call the subclass hook for more specific settings.
    service_options(r)
  end
end