From 5c1a097a240fc4a6c43a66325c008f2851968f75 Mon Sep 17 00:00:00 2001 From: Laura Martin Date: Thu, 14 Jul 2016 19:06:18 +0100 Subject: [PATCH 1/3] Add options to Gor This commit adds the ability to set a different binary path than the default, as we found in upgrading that the path was set to /usr/local/bin/gor rather than /usr/bin/gor so the service failed to start. It also allows adding a hash on environment variables which will be loaded into the upstart file and loaded when the service starts. This is due to a bug that we ran into in updating documented here: https://github.com/buger/gor/wiki/Troubleshooting#gor-is-crashing-with-following-stacktrace --- manifests/config.pp | 2 ++ manifests/init.pp | 11 +++++++++++ spec/classes/config_spec.rb | 34 +++++++++++++++++++++++++++++++++ templates/etc/init/gor.conf.erb | 6 +++++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index dccdd6a..e6a7cd2 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,6 +4,8 @@ # class gor::config { $args = $::gor::args + $envvars = $::gor::envvars + $binary_path = $::gor::binary_path file { '/etc/init/gor.conf': content => template('gor/etc/init/gor.conf.erb'), diff --git a/manifests/init.pp b/manifests/init.pp index d524ac0..b545462 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -15,16 +15,27 @@ # Ensure parameter to pass to the service. # Default: running # +# [*envvars*] +# Environment variables to be passed into the upstart config. This could +# be used to turn on debugging options. +# +# [*binary_path*] +# Specify the location of the Gor binary. +# class gor ( $args, $package_ensure = present, $service_ensure = running, + $envvars = {}, + $binary_path = '/usr/bin/gor', ) { validate_hash($args) if empty($args) { fail("${title}: args param is empty") } + validate_hash($envvars) + anchor { 'gor::begin': } -> class { 'gor::package': } -> class { 'gor::config': } ~> diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index c562e85..aaaefce 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -79,4 +79,38 @@ end end end + + describe '#envvars' do + context 'valid hash' do + let(:params) {{ + :envvars => { + 'GODEBUG' => 'netdns=go', + 'FOO' => 'bar', + }, + :args => { + '-output-http-header' => 'User-Agent: gor', + '-output-http' => 'http://staging', + '-input-raw' => ':80', + }, + }} + + it 'should configure gor with correct environment variables in place' do + is_expected.to contain_file(upstart_file).with_content(/^env GODEBUG=\'netdns=go\'\nenv FOO=\'bar\'$/) + end + end + context 'empty hash' do + let(:params) {{ + :envvars => {}, + :args => { + '-output-http-header' => 'User-Agent: gor', + '-output-http' => 'http://staging', + '-input-raw' => ':80', + }, + }} + + it 'should configure gor without setting environment variables' do + is_expected.not_to contain_file(upstart_file).with_content(/^env GODEBUG=\'netdns=go\'\nenv FOO=\'bar\'$/) + end + end + end end diff --git a/templates/etc/init/gor.conf.erb b/templates/etc/init/gor.conf.erb index 08b1543..b2214d3 100644 --- a/templates/etc/init/gor.conf.erb +++ b/templates/etc/init/gor.conf.erb @@ -6,7 +6,11 @@ stop on runlevel [!2345] respawn respawn limit 5 20 -exec /usr/bin/gor \ +<% @envvars.each do |k, v| %> +<%= "env #{k}='#{v}'" -%> +<% end %> + +exec <%= @binary_path %> \ <%= @args.sort.map { |k,v| [v].flatten.map { |i| From 812b6cfb97a03ef561907b13be2ce43f09a54442 Mon Sep 17 00:00:00 2001 From: Laura Martin Date: Fri, 15 Jul 2016 11:23:03 +0100 Subject: [PATCH 2/3] Upgrade to release 0.3.1 --- CHANGELOG | 4 ++++ metadata.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 0f9c098..94dd688 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +2016-07-15 Release 0.3.1 +- Support ability to pass in environment variables +- Support explicitly setting binary path + 2016-07-12 Release 0.3.0 - Support command-line options which don't have values - Support Puppet 3.8 diff --git a/metadata.json b/metadata.json index e5974cf..4c3fbbf 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "gdsoperations-gor", - "version": "0.3.0", + "version": "0.3.1", "author": "Government Digital Service", "license": "MIT", "summary": "Module to manage gor", From 9368ef6a8e3db4aa96aa2c55a1f432528192d7ed Mon Sep 17 00:00:00 2001 From: Laura Martin Date: Fri, 15 Jul 2016 11:23:24 +0100 Subject: [PATCH 3/3] Add default rake task --- Rakefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rakefile b/Rakefile index ba5eb97..d71ed86 100644 --- a/Rakefile +++ b/Rakefile @@ -20,6 +20,8 @@ exclude_paths = [ PuppetLint.configuration.ignore_paths = exclude_paths PuppetSyntax.exclude_paths = exclude_paths +task :default => [:test] + desc "Run syntax, lint, and spec tests." task :test => [ :syntax,