From 115204d819376529538946c788eca2edcd8dab77 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Dec 2016 02:48:50 +0800 Subject: [PATCH 1/7] add default values for opts Signed-off-by: Michael --- attributes/default.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/attributes/default.rb b/attributes/default.rb index c5dde16..3381969 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -5,7 +5,10 @@ # Copyright (c) 2016, David Joos # -default['beanstalkd']['opts'] = {} +default['beanstalkd']['opts'] = { + :p => '11300', + :l => '127.0.0.1' +} # Ubuntu only default['beanstalkd']['start_during_boot'] = false From 78704662342e27d453007088cd48d424e735b3ee Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Dec 2016 02:51:34 +0800 Subject: [PATCH 2/7] modified the beanstalkd service configuration Signed-off-by: Michael --- recipes/default.rb | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index 8258829..3a5b31d 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -6,33 +6,32 @@ # package 'beanstalkd' do - action :upgrade + action :upgrade end case node['platform'] when 'debian', 'ubuntu' - template_path = '/etc/default/beanstalkd' # templates/ubuntu + template_path = '/etc/default/beanstalkd' # templates/ubuntu else - template_path = '/etc/sysconfig/beanstalkd' # templates/default + template_path = '/etc/sysconfig/beanstalkd' # templates/default end template template_path do - source 'beanstalkd.erb' - owner 'root' - group 'root' - mode 0644 - variables( - :opts => node['beanstalkd']['opts'], - :start_during_boot => node['beanstalkd']['start_during_boot'] - ) - notifies :restart, 'service[beanstalkd]' + source 'beanstalkd.erb' + owner 'root' + group 'root' + mode 0644 + variables( + :opts => node['beanstalkd']['opts'], + :start_during_boot => node['beanstalkd']['start_during_boot'] + ) + notifies :restart, 'service[beanstalkd]' end + service 'beanstalkd' do - start_command '/etc/init.d/beanstalkd start' - stop_command '/etc/init.d/beanstalkd stop' - status_command '/etc/init.d/beanstalkd status' - supports [:start, :stop, :status] - # starts the service if it's not running and enables it to start at system boot time - action [:enable, :start] + supports [:start, :stop, :status] + # starts the service if it's not running and enables it to start at system boot time + action [:enable, :start] end + From a691d7dd42adeab1f0591f6d463b85bfb7f01b31 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Dec 2016 02:52:03 +0800 Subject: [PATCH 3/7] added flags for each options Signed-off-by: Michael --- templates/default/beanstalkd.erb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/default/beanstalkd.erb b/templates/default/beanstalkd.erb index 3e0ff0d..40a5158 100644 --- a/templates/default/beanstalkd.erb +++ b/templates/default/beanstalkd.erb @@ -9,29 +9,29 @@ # Available options correspond to the options to the # beanstalkd commandline. -BEANSTALKD_ADDR=<% if @opts['l'].nil? %>0.0.0.0<% else %><%= @opts['l'] %><% end %> -BEANSTALKD_PORT=<% if @opts['p'].nil? %>11300<% else %><%= @opts['p'] %><% end %> -BEANSTALKD_USER=<% if @opts['u'].nil? %>beanstalkd<% else %><%= @opts['u'] %><% end %> +ADDR= -l <% if @opts['l'].nil? %>0.0.0.0<% else %><%= @opts['l'] %><% end %> +PORT= -p <% if @opts['p'].nil? %>11300<% else %><%= @opts['p'] %><% end %> +USER= -u <% if @opts['u'].nil? %>beanstalkd<% else %><%= @opts['u'] %><% end %> # Job size is left to the default. Uncomment and set it # to a value to have it take affect. -<% unless @opts['z'] %>#<% end %>BEANSTALKD_MAX_JOB_SIZE=<% if @opts['z'].nil? %>65535<% else %><%= @opts['z'] %><% end %> +<% unless @opts['z'] %>#<% end %>MAX_JOB_SIZE= -z <% if @opts['z'].nil? %>65535<% else %><%= @opts['z'] %><% end %> # Using the binlog is off by default. # # The direcory to house the binlog. -<% unless @opts['b'] %>#<% end %>BEANSTALKD_BINLOG_DIR=<% if @opts['b'].nil? %>/var/lib/beanstalkd/binlog<% else %><%= @opts['b'] %><% end %> +<% unless @opts['b'] %>#<% end %>$BINLOG_DIR= -b <% if @opts['b'].nil? %>/var/lib/beanstalkd/binlog<% else %><%= @opts['b'] %><% end %> # # fsync the binlog at most once every N milliseconds. # setting this to 0 means 'always fsync'. If this is unset, # and the binlog is used, then no explicit fsync is ever # performed. That is, the -F option is used. -<% unless @opts['f'] %>#<% end %>BEANSTALKD_BINLOG_FSYNC_PERIOD=<% if @opts['f'].nil? %><% else %><%= @opts['f'] %><% end %> +<% unless @opts['f'] %>#<% end %>BINLOG_FSYNC_PERIOD= -f <% if @opts['f'].nil? %><% else %><%= @opts['f'] %><% end %> # # The size of each binlog file. This is rounded # up to the nearest 512 byte boundary. -<% unless @opts['s'] %>#<% end %>BEANSTALKD_BINLOG_SIZE=<% if @opts['s'].nil? %>10485760<% else %><%= @opts['s'] %><% end %> +<% unless @opts['s'] %>#<% end %>BINLOG_SIZE= -s <% if @opts['s'].nil? %>10485760<% else %><%= @opts['s'] %><% end %> <% unless @start_during_boot %>#<% end %>START=yes From bbcfb4ec6ece5df47fd93e9b3d347b32778eb946 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Dec 2016 23:58:19 +0800 Subject: [PATCH 4/7] added chefspec tests Signed-off-by: Michael --- spec/unit/default_spec.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/unit/default_spec.rb b/spec/unit/default_spec.rb index e3a1fea..fbf4aad 100644 --- a/spec/unit/default_spec.rb +++ b/spec/unit/default_spec.rb @@ -1,5 +1,24 @@ require 'spec_helper' describe 'beanstalkd::default' do - let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } + let(:chef_run) { + ChefSpec::Runner.new.converge(described_recipe) + } + + it 'should upgrade the beanstalkd' do + expect(chef_run).to upgrade_package('beanstalkd') + end + + it 'should deploy the beanstalkd template' do + expect(chef_run).to create_template('/etc/sysconfig/beanstalkd').with(user: 'root') + + end + + it 'must enable the beanstalkd service' do + expect(chef_run).to enable_service('beanstalkd') + end + + it 'should start the beanstalkd service' do + expect(chef_run).to start_service('beanstalkd') + end end From 48b61321258b259a46ec3eaac9ebf95f1e142fb0 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 15 Dec 2016 00:03:29 +0800 Subject: [PATCH 5/7] remove the default value of opts attribute Signed-off-by: Michael --- attributes/default.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 3381969..c5dde16 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -5,10 +5,7 @@ # Copyright (c) 2016, David Joos # -default['beanstalkd']['opts'] = { - :p => '11300', - :l => '127.0.0.1' -} +default['beanstalkd']['opts'] = {} # Ubuntu only default['beanstalkd']['start_during_boot'] = false From 003dda9884e4bfad97488d061a5ca4ef10f8c369 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 15 Dec 2016 00:47:43 +0800 Subject: [PATCH 6/7] change indentation Signed-off-by: Michael --- recipes/default.rb | 30 +++++++++++++++--------------- spec/unit/default_spec.rb | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index 3a5b31d..9761bcf 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -6,32 +6,32 @@ # package 'beanstalkd' do - action :upgrade + action :upgrade end case node['platform'] when 'debian', 'ubuntu' - template_path = '/etc/default/beanstalkd' # templates/ubuntu + template_path = '/etc/default/beanstalkd' # templates/ubuntu else - template_path = '/etc/sysconfig/beanstalkd' # templates/default + template_path = '/etc/sysconfig/beanstalkd' # templates/default end template template_path do - source 'beanstalkd.erb' - owner 'root' - group 'root' - mode 0644 - variables( - :opts => node['beanstalkd']['opts'], - :start_during_boot => node['beanstalkd']['start_during_boot'] - ) - notifies :restart, 'service[beanstalkd]' + source 'beanstalkd.erb' + owner 'root' + group 'root' + mode 0644 + variables( + :opts => node['beanstalkd']['opts'], + :start_during_boot => node['beanstalkd']['start_during_boot'] + ) + notifies :restart, 'service[beanstalkd]' end service 'beanstalkd' do - supports [:start, :stop, :status] - # starts the service if it's not running and enables it to start at system boot time - action [:enable, :start] + supports [:start, :stop, :status] + # starts the service if it's not running and enables it to start at system boot time + action [:enable, :start] end diff --git a/spec/unit/default_spec.rb b/spec/unit/default_spec.rb index fbf4aad..f43de16 100644 --- a/spec/unit/default_spec.rb +++ b/spec/unit/default_spec.rb @@ -1,24 +1,24 @@ require 'spec_helper' describe 'beanstalkd::default' do - let(:chef_run) { - ChefSpec::Runner.new.converge(described_recipe) - } + let(:chef_run) { + ChefSpec::Runner.new.converge(described_recipe) + } - it 'should upgrade the beanstalkd' do - expect(chef_run).to upgrade_package('beanstalkd') - end + it 'should upgrade the beanstalkd' do + expect(chef_run).to upgrade_package('beanstalkd') + end - it 'should deploy the beanstalkd template' do - expect(chef_run).to create_template('/etc/sysconfig/beanstalkd').with(user: 'root') + it 'should deploy the beanstalkd template' do + expect(chef_run).to create_template('/etc/sysconfig/beanstalkd').with(user: 'root') - end + end - it 'must enable the beanstalkd service' do - expect(chef_run).to enable_service('beanstalkd') - end + it 'must enable the beanstalkd service' do + expect(chef_run).to enable_service('beanstalkd') + end - it 'should start the beanstalkd service' do - expect(chef_run).to start_service('beanstalkd') - end + it 'should start the beanstalkd service' do + expect(chef_run).to start_service('beanstalkd') + end end From dbb376a8885ed5c34ab12ad89bc761d2160e6915 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 15 Dec 2016 01:23:21 +0800 Subject: [PATCH 7/7] fix indentation and spaces Signed-off-by: Michael --- recipes/default.rb | 2 -- spec/unit/default_spec.rb | 29 +++++++++++++---------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index 9761bcf..a3a6220 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -28,10 +28,8 @@ notifies :restart, 'service[beanstalkd]' end - service 'beanstalkd' do supports [:start, :stop, :status] # starts the service if it's not running and enables it to start at system boot time action [:enable, :start] end - diff --git a/spec/unit/default_spec.rb b/spec/unit/default_spec.rb index f43de16..09b94f2 100644 --- a/spec/unit/default_spec.rb +++ b/spec/unit/default_spec.rb @@ -1,24 +1,21 @@ require 'spec_helper' describe 'beanstalkd::default' do - let(:chef_run) { - ChefSpec::Runner.new.converge(described_recipe) - } + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } - it 'should upgrade the beanstalkd' do - expect(chef_run).to upgrade_package('beanstalkd') - end + it 'should upgrade the beanstalkd' do + expect(chef_run).to upgrade_package('beanstalkd') + end - it 'should deploy the beanstalkd template' do - expect(chef_run).to create_template('/etc/sysconfig/beanstalkd').with(user: 'root') + it 'should deploy the beanstalkd template' do + expect(chef_run).to create_template('/etc/sysconfig/beanstalkd') + end - end + it 'must enable the beanstalkd service' do + expect(chef_run).to enable_service('beanstalkd') + end - it 'must enable the beanstalkd service' do - expect(chef_run).to enable_service('beanstalkd') - end - - it 'should start the beanstalkd service' do - expect(chef_run).to start_service('beanstalkd') - end + it 'should start the beanstalkd service' do + expect(chef_run).to start_service('beanstalkd') + end end