Skip to content

Commit

Permalink
Merge pull request #421 from visioncritical/various-fixes
Browse files Browse the repository at this point in the history
Consul 0.7.5 & Windows Fixes
  • Loading branch information
legal90 committed Apr 23, 2017
2 parents b31d1e7 + cb8974d commit d1a4af3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

default['consul']['service']['config_dir'] = join_path config_prefix_path, 'conf.d'

default['consul']['version'] = '0.7.4'
default['consul']['version'] = '0.7.5'

# Windows only
default['consul']['service']['nssm_params'] = {
Expand Down
8 changes: 8 additions & 0 deletions libraries/consul_installation_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then '4403357fbfddbcdd0742946cab7856638cb0f15898c75d79d155753621d60b0c'
when '0.7.3' then '08dd9af590a6c6ecd629e532083bd898b42c6425d08aa9f62b8f090a6dd65826'
when '0.7.4' then 'a66cd4efdff376e7fd5c22d2710d7ef6734562c46df80a05e3144222965d9a97'
when '0.7.5' then '60c1685bfbefe55d0ac67f37d4bc88752a204609221d0cc4425452f1ffc2e42b'
end
when 'darwin-i386'
case resource.version
Expand All @@ -116,6 +117,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then '23e6e8dd14c2be02fd095a865edd1725f5ccdbce1109ad5f70832866012d1d7f'
when '0.7.3' then 'cf369542e30c5aa22967459b25fec284284d292ff25e801bdcd1a5f37f1a5143'
when '0.7.4' then '7638e80c9db050ef8d63bad3baa338985da1a1bd4657f3b2fc4222d105c673a3'
when '0.7.5' then '9ff8798a94bab99fb2387afae5bc0fc2844a304675abbceb9315292019a8f582'
end
when 'solaris-amd64'
case resource.version
Expand All @@ -127,6 +129,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then 'f1ccaf9d9dd62544323e130cee7221df2a6d4b577e9e4a120db357e59782f12d'
when '0.7.3' then '49b13f83f8099537e72adc1bb34b6cb70b3699aa10245db4b8ef1f48c6e0b007'
when '0.7.4' then '0300ffa4d1007b00bca37112cf934d3e281afdc300ce336735bbf3a33ebcfc19'
when '0.7.5' then 'aa3705a958d0403e2ddacaa75c1d3ede5f290b0ef3a60e6e24976f2d8f32d840'
end
when 'windows-amd64'
case resource.version
Expand All @@ -140,6 +143,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then '7a5ec31018328a3764f22327c940765c9cd99e57c6759fc43fbfed8318d5e379'
when '0.7.3' then 'ec80a931603bf585704e338e6cb497af9aa58ebdae5e3442a3f78f7027d80b66'
when '0.7.4' then 'c2e071ebae166d4cfdf894966b2966026cf9175d394001704f68bcbccaa8e446'
when '0.7.5' then '6cc64b1bb949f926d403e0436d02bf740844cf268076cf6d3d345361c1aa5293'
end
when 'windows-i386'
case resource.version
Expand All @@ -156,6 +160,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then 'c041dc43995df3505d9146e3a2f532bfc491c49fb644bd1e2ceead7d7dc3011c'
when '0.7.3' then '87a7169bd5298e179a3bbd2f30b3447c09023dc771c97d083779090655bf0a5f'
when '0.7.4' then 'ede957f736758a40fb8e3e33eb423a71226db46085fe1507d880a0ce393e9658'
when '0.7.5' then '7ea88aa53026cb14bab6a68d5b64c43515ea39552594ae399978fc13bcd74707'
end
when 'linux-amd64'
case resource.version
Expand All @@ -172,6 +177,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then 'aa97f4e5a552d986b2a36d48fdc3a4a909463e7de5f726f3c5a89b8a1be74a58'
when '0.7.3' then '901a3796b645c3ce3853d5160080217a10ad8d9bd8356d0b73fcd6bc078b7f82'
when '0.7.4' then '23a61773bee9b29198cc1f8fe2e62c320f82f95006ff70840c15c1e58eead73b'
when '0.7.5' then '40ce7175535551882ecdff21fdd276cef6eaab96be8a8260e0599fadb6f1f5b8'
end
when 'linux-i386'
case resource.version
Expand All @@ -188,6 +194,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then '43b22bcd04e74445c3ea6c143b3acbfe5546d6792c28d123ef5832cd8f96162f'
when '0.7.3' then 'b15e96a1b5833b08d785d67b8f2465a9a0185e34149855943717dd818b347750'
when '0.7.4' then '7fe40af0825b2c6ab6c7e4e3e7d68471cccbd54f9a1513ad622b832cfda5fa07'
when '0.7.5' then '8abf0189776ecc5c8746e12021b6cfe6d96e0b4689ce4a4948b7e3faa07f3025'
end
when 'linux-arm'
case resource.version
Expand All @@ -201,6 +208,7 @@ def self.binary_checksum(node, resource)
when '0.7.2' then 'e18934a3a38b980bc0cfaa8d74379a6bfe58cf1ecf4b164e28ff37dd6c7198b0'
when '0.7.3' then 'a2d2d2cf194e3768aae7c3cdf140a056bf2534f4c83fb7a66cfbd4090c98773e'
when '0.7.4' then 'bfd9cbef9c7c9f2128704940323d1727d8edbbd595c8d82aba923e04f04b266d'
when '0.7.5' then 'df4bc38eff4305632d29c5650fbb7e7ff97b8ef12a964fd8ee5f691849c51711'
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion libraries/consul_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ def command
"#{program} agent -config-file=#{config_file} -config-dir=#{config_dir}"
end

def shell_environment
shell = node['consul']['service_shell']
shell.nil? ? {} : { 'SHELL' => shell }
end

def default_environment
{
'GOMAXPROCS' => [node['cpu']['total'], 2].max.to_s,
'PATH' => '/usr/local/bin:/usr/bin:/bin',
}
}.merge(shell_environment)
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion libraries/consul_service_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class ConsulServiceWindows < Chef::Provider
provides(:consul_service, os: %w(windows))
include ConsulCookbook::Helpers

def application_path
{ 'Application' => new_resource.program }
end

def action_enable
notifying_block do
directories = %W(#{new_resource.data_dir}
Expand All @@ -30,6 +34,8 @@ def action_enable
end

nssm 'consul' do
extend ConsulCookbook::Helpers

program new_resource.program
args command(new_resource.config_file, new_resource.config_dir)
if respond_to? :parameters
Expand All @@ -42,7 +48,7 @@ def action_enable
end

if nssm_service_installed?
mismatch_params = check_nssm_params
mismatch_params = check_nssm_params(application_path)
unless mismatch_params.empty?
mismatch_params.each do |k, v|
action = v.eql?('') ? "reset consul #{k}" : "set consul #{k} #{v}"
Expand Down Expand Up @@ -88,6 +94,8 @@ def action_disable
notifying_block do
# nssm resource doesn't stop the service before it removes it
powershell_script 'Stop consul' do
extend ConsulCookbook::Helpers

action :run
code 'stop-service consul'
only_if { nssm_service_installed? && nssm_service_status?(%w(SERVICE_RUNNING SERVICE_PAUSED)) }
Expand Down
7 changes: 4 additions & 3 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ def nssm_service_status?(expected_status)
end

# Returns a hash of mismatched params
def check_nssm_params
def check_nssm_params(extra = {})
params = node['consul']['service']['nssm_params'].merge extra
# nssm can only get certain values
params = node['consul']['service']['nssm_params'].select { |k, _v| nssm_params.include? k.to_s }
params.each.each_with_object({}) do |(k, v), mismatch|
to_check = params.select { |k, _v| nssm_params.include? k.to_s }
to_check.each.each_with_object({}) do |(k, v), mismatch|
# shell_out! returns values with null bytes, need to delete them before we evaluate
unless shell_out!(%("#{nssm_exe}" get consul #{k}), returns: [0]).stdout.delete("\0").strip.eql? v.to_s
mismatch[k] = v
Expand Down
2 changes: 1 addition & 1 deletion test/integration/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def consul_version
'0.7.4'
'0.7.5'
end
7 changes: 2 additions & 5 deletions test/spec/libraries/consul_service_windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
allow(shellout).to receive(:stderr)
allow(shellout).to receive(:run_command)
allow(shellout).to receive(:exitstatus)
allow(shellout).to receive(:stdout).and_return("Consul v0.6.0\nConsul Protocol: 3 (Understands back to: 1)\n")
allow(shellout).to receive(:stdout).and_return("Consul v0.7.5\nConsul Protocol: 3 (Understands back to: 1)\n")

# Stub admin_user method since we are testing a Windows host via Linux
# Fixed in https://github.com/poise/poise/commit/2f42850c82e295af279d060155bcd5c7ebb31d6a but not released yet
Expand All @@ -26,19 +26,16 @@
recipe 'consul::default'

it do
skip('Add poise inversion system to consul_service otherwise windows tests will not pass')
is_expected.to create_directory('C:\Program Files\consul\conf.d')
end

it do
skip('Add poise inversion system to consul_service otherwise windows tests will not pass')
is_expected.to create_directory('C:\Program Files\consul\data')
end

it do
skip('Add poise inversion system to consul_service otherwise windows tests will not pass')
expect(chef_run).to install_nssm('consul').with(
program: 'C:\Program Files\consul\0.7.1\consul.exe',
program: 'C:\Program Files\consul\0.7.5\consul.exe',
args: 'agent -config-file="""C:\Program Files\consul\consul.json""" -config-dir="""C:\Program Files\consul\conf.d"""'
)
end
Expand Down

0 comments on commit d1a4af3

Please sign in to comment.