Skip to content

Commit

Permalink
Merge pull request #134 from sonots/service_provider
Browse files Browse the repository at this point in the history
Support provider for service resource
  • Loading branch information
ryotarai committed May 20, 2015
2 parents 09ebacd + 0089b15 commit 832ee10
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/itamae/resource/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module Resource
class Service < Base
define_attribute :action, default: :nothing
define_attribute :name, type: String, default_name: true
define_attribute :provider, type: Symbol, default: nil

def initialize(*args)
super
@under = attributes.provider ? "_under_#{attributes.provider}" : ""
end

def pre_action
case @current_action
Expand All @@ -20,36 +26,42 @@ def pre_action
end

def set_current_attributes
current.running = run_specinfra(:check_service_is_running, attributes.name)
current.enabled = run_specinfra(:check_service_is_enabled, attributes.name)
current.running = run_specinfra(:"check_service_is_running#{@under}", attributes.name)
current.enabled = run_specinfra(:"check_service_is_enabled#{@under}", attributes.name)
end

def action_start(options)
unless current.running
run_specinfra(:start_service, attributes.name)
run_specinfra(:"start_service#{@under}", attributes.name)
end
end

def action_stop(options)
if current.running
run_specinfra(:stop_service, attributes.name)
run_specinfra(:"stop_service#{@under}", attributes.name)
end
end

def action_restart(options)
run_specinfra(:restart_service, attributes.name)
run_specinfra(:"restart_service#{@under}", attributes.name)
end

def action_reload(options)
run_specinfra(:reload_service, attributes.name)
if current.running
run_specinfra(:"reload_service#{@under}", attributes.name)
end
end

def action_enable(options)
run_specinfra(:enable_service, attributes.name)
unless current.enabled
run_specinfra(:"enable_service#{@under}", attributes.name)
end
end

def action_disable(options)
run_specinfra(:disable_service, attributes.name)
if current.enabled
run_specinfra(:"disable_service#{@under}", attributes.name)
end
end
end
end
Expand Down

0 comments on commit 832ee10

Please sign in to comment.