diff --git a/attributes/redis_sentinel.rb b/attributes/redis_sentinel.rb index e15ece93..a7b44b71 100644 --- a/attributes/redis_sentinel.rb +++ b/attributes/redis_sentinel.rb @@ -16,11 +16,11 @@ # limitations under the License. # -config_dir = '/etc/redis' - -if node['platform_family'] == 'freebsd' - config_dir = '/usr/local/etc/redis' -end +config_dir = if node['platform_family'] == 'freebsd' + '/usr/local/etc/redis' + else + '/etc/redis' + end default['redisio']['sentinel_defaults'] = { 'user' => 'redis', diff --git a/providers/configure.rb b/providers/configure.rb index 60a0821c..342e3e2c 100644 --- a/providers/configure.rb +++ b/providers/configure.rb @@ -45,11 +45,11 @@ def configure # Merge the configuration defaults with the provided array of configurations provided current = current_defaults_hash.merge(current_instance_hash) - #Merge in the default maxmemory - node_memory_kb = node["memory"]["total"] - #On BSD platforms Ohai reports total memory as a Fixnum + # Merge in the default maxmemory + node_memory_kb = node['memory']['total'] + # On BSD platforms Ohai reports total memory as a Fixnum if node_memory_kb.is_a? String - node_memory_kb.slice! "kB" + node_memory_kb.slice! 'kB' node_memory_kb = node_memory_kb.to_i end @@ -86,13 +86,13 @@ def configure maxmemory = (node_memory_kb * 1024 * percent_factor / new_resource.servers.length).round.to_s end - if current['ulimit'] == 0 - descriptors = current['maxclients'] + 32 - elsif current['ulimit'] > current['maxclients'] - descriptors = current['ulimit'] - else - descriptors = current['maxclients'] - end + descriptors = if current['ulimit'] == 0 + current['maxclients'] + 32 + elsif current['ulimit'] > current['maxclients'] + current['ulimit'] + else + current['maxclients'] + end recipe_eval do server_name = current['name'] || current['port'] @@ -175,10 +175,10 @@ def configure # Setup the redis users descriptor limits # Pending response on https://github.com/brianbianco/redisio/commit/4ee9aad3b53029cc3b6c6cf741f5126755e712cd#diff-8ae42a59a6f4e8dc5b4e6dd2d6a34eab - #TODO: ulimit cookbook v0.1.2 doesn't work with freeBSD + # TODO: ulimit cookbook v0.1.2 doesn't work with freeBSD if current['ulimit'] && node['platform_family'] != 'freebsd' # ~FC023 user_ulimit current['user'] do - filehandle_limit descriptors + filehandle_limit descriptors end end @@ -325,31 +325,21 @@ def configure ) only_if { node['redisio']['job_control'] == 'upstart' } end - template "/usr/local/etc/rc.d/redis#{server_name}" do - source 'redis.rcinit.erb' - cookbook 'redisio' - owner current['user'] - group current['group'] - mode '0755' - variables({ - :name => server_name, - :bin_path => bin_path, - :job_control => node['redisio']['job_control'], - :port => current['port'], - :address => current['address'], - :user => current['user'], - :group => current['group'], - :maxclients => current['maxclients'], - :requirepass => current['requirepass'], - :shutdown_save => current['shutdown_save'], - :save => current['save'], - :configdir => current['configdir'], - :piddir => piddir, - :platform => node['platform'], - :unixsocket => current['unixsocket'] - }) - only_if { node['redisio']['job_control'] == 'rcinit' } - end + template "/usr/local/etc/rc.d/redis#{server_name}" do + source 'redis.rcinit.erb' + cookbook 'redisio' + owner current['user'] + group current['group'] + mode '0755' + variables( + name: server_name, + bin_path: bin_path, + user: current['user'], + configdir: current['configdir'], + piddir: piddir + ) + only_if { node['redisio']['job_control'] == 'rcinit' } + end end end # servers each loop end diff --git a/providers/install.rb b/providers/install.rb index f23f83ef..658fdc20 100644 --- a/providers/install.rb +++ b/providers/install.rb @@ -29,9 +29,9 @@ package_resource.run_action(:install) new_resource.updated_by_last_action(true) if package_resource.updated_by_last_action? -# freeBSD does not support from source since ports does not support versioning (without a lot of hassle) -elsif node.platform_family == 'freebsd' - fail 'Source install not supported for freebsd' + # freeBSD does not support from source since ports does not support versioning (without a lot of hassle) + elsif node['platform_family'] == 'freebsd' + raise 'Source install not supported for freebsd' # Tarball install else @tarball = "#{new_resource.base_name}#{new_resource.version}.#{new_resource.artifact_type}" diff --git a/providers/sentinel.rb b/providers/sentinel.rb index 51205a78..9653ced9 100644 --- a/providers/sentinel.rb +++ b/providers/sentinel.rb @@ -207,25 +207,22 @@ def configure ) only_if { node['redisio']['job_control'] == 'upstart' } end - #TODO: fix for freebsd - template "/usr/local/etc/rc.d/redis_#{sentinel_name}" do - source 'sentinel.rcinit.erb' - cookbook 'redisio' - owner current['user'] - group current['group'] - mode '0755' - variables({ - :name => sentinel_name, - :bin_path => bin_path, - :job_control => node['redisio']['job_control'], - :user => current['user'], - :group => current['group'], - :configdir => current['configdir'], - :piddir => piddir, - :platform => node['platform'], - }) - only_if { node['redisio']['job_control'] == 'rcinit' } - end + # TODO: fix for freebsd + template "/usr/local/etc/rc.d/redis_#{sentinel_name}" do + source 'sentinel.rcinit.erb' + cookbook 'redisio' + owner current['user'] + group current['group'] + mode '0755' + variables( + name: sentinel_name, + bin_path: bin_path, + user: current['user'], + configdir: current['configdir'], + piddir: piddir + ) + only_if { node['redisio']['job_control'] == 'rcinit' } + end end end # servers each loop end diff --git a/recipes/configure.rb b/recipes/configure.rb index 0e73f37a..0356eac3 100644 --- a/recipes/configure.rb +++ b/recipes/configure.rb @@ -74,7 +74,7 @@ when 'rcinit' service "redis#{server_name}" do provider Chef::Provider::Service::Freebsd - supports :start => true, :stop => true, :restart => true, :status => true + supports start: true, stop: true, restart: true, status: true end else Chef::Log.error('Unknown job control type, no service resource created!') diff --git a/test/integration/default/serverspec/redisio_spec.rb b/test/integration/default/serverspec/redisio_spec.rb index 70740a92..4846da02 100644 --- a/test/integration/default/serverspec/redisio_spec.rb +++ b/test/integration/default/serverspec/redisio_spec.rb @@ -11,7 +11,6 @@ ['save a', 'save b', 'save c'].each do |m| its(:content) { should match(m) } end - end else describe file('/etc/redis/savetest.conf') do @@ -20,6 +19,5 @@ ['save a', 'save b', 'save c'].each do |m| its(:content) { should match(m) } end - end end diff --git a/test/integration/helpers/serverspec/redisio_examples.rb b/test/integration/helpers/serverspec/redisio_examples.rb index fadf83ee..c124b3a9 100644 --- a/test/integration/helpers/serverspec/redisio_examples.rb +++ b/test/integration/helpers/serverspec/redisio_examples.rb @@ -6,12 +6,12 @@ "redis#{redis_port}" end expect(service service_name).to be_enabled - expect(service service_name).to be_running, :if => os[:family] != 'fedora' + expect(service service_name).to be_running, if: os[:family] != 'fedora' end # We use grep and commands here, since serverspec only checks systemd on fedora 20 # instead of also being able to check sysv style init systems. - describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), :if => os[:family] == 'fedora' do + describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), if: os[:family] == 'fedora' do its(:exit_status) { should eq(0) } end diff --git a/test/integration/helpers/serverspec/sentinel_examples.rb b/test/integration/helpers/serverspec/sentinel_examples.rb index f0bb7f98..257cafb7 100644 --- a/test/integration/helpers/serverspec/sentinel_examples.rb +++ b/test/integration/helpers/serverspec/sentinel_examples.rb @@ -7,14 +7,13 @@ "redis_sentinel_#{redis_cluster_name}" end expect(service name).to be_enabled - expect(service name).to be_running, :if => os[:family] != 'fedora' + expect(service name).to be_running, if: os[:family] != 'fedora' end - describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), :if => os[:family] == 'fedora' do + describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), if: os[:family] == 'fedora' do its(:exit_status) { should eq(0) } end - it "is listening on port #{redis_port}" do expect(port redis_port).to be_listening end