Skip to content

Commit

Permalink
Added nssm running check & updated consul_definition
Browse files Browse the repository at this point in the history
Added a check to start Consul via nssm if it's not running. And
updated consul_definition resource/provider with the new helper
methods.
  • Loading branch information
Ginja committed Jan 20, 2016
1 parent 478a2e8 commit cf8a9fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
19 changes: 12 additions & 7 deletions libraries/consul_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ module Resource
# @since 1.0.0
class ConsulDefinition < Chef::Resource
include Poise(fused: true)
include ConsulCookbook::Helpers
provides(:consul_definition)
default_action(:create)

# @!attribute path
# @return [String]
attribute(:path, kind_of: String, default: lazy { "/etc/consul/#{name}.json" })
attribute(:path, kind_of: String, default: lazy { join_path config_prefix_path, "#{name}.json" })

# @!attribute user
# @return [String]
Expand Down Expand Up @@ -44,16 +45,20 @@ def to_json
notifying_block do
directory ::File.dirname(new_resource.path) do
recursive true
owner new_resource.user
group new_resource.group
mode '0755'
if node['os'].eql? 'linux'
owner new_resource.user
group new_resource.group
mode '0755'
end
end

file new_resource.path do
owner new_resource.user
group new_resource.group
content new_resource.to_json
mode '0640'
if node['os'].eql? 'linux'
owner new_resource.user
group new_resource.group
mode '0640'
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions libraries/consul_service_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ def action_enable
code "#{nssm_exe} restart consul"
end
end
# Check if the service is running, but don't bother if we're already
# changing some nssm parameters
unless nssm_service_running? && mismatch_params.empty?
batch 'Trigger consul restart' do
action :run
code "#{nssm_exe} restart consul"
end
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def nssm_service_installed?
exit_code == 0 ? true : false
end

def nssm_service_running?
shell_out!(%{"#{nssm_exe}" status consul}, returns: [0]).stdout.delete("\0").strip.eql? 'SERVICE_RUNNING'
end

# Returns a hash of mismatched params
def check_nssm_params
# nssm can only get certain values
Expand Down

0 comments on commit cf8a9fb

Please sign in to comment.