From 1b784d15c7003490ef4691cab29e4a49dec91cd0 Mon Sep 17 00:00:00 2001 From: Kazuki Nishikawa Date: Sat, 16 Jan 2021 22:19:32 +0900 Subject: [PATCH] fix: run `monit reload` only once, after `configure hook` Fixes #251 --- libraries/drivers_appserver_base.rb | 2 -- libraries/drivers_worker_base.rb | 2 -- recipes/configure.rb | 4 ++++ spec/unit/recipes/configure_spec.rb | 6 ++++++ spec/unit/recipes/deploy_spec.rb | 6 ++++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/drivers_appserver_base.rb b/libraries/drivers_appserver_base.rb index 973a61b2..4089179b 100644 --- a/libraries/drivers_appserver_base.rb +++ b/libraries/drivers_appserver_base.rb @@ -47,8 +47,6 @@ def add_appserver_monit source 'appserver.monitrc.erb' variables opts end - - context.execute 'monit reload' end def restart_monit diff --git a/libraries/drivers_worker_base.rb b/libraries/drivers_worker_base.rb index 3873164c..ea38aac9 100644 --- a/libraries/drivers_worker_base.rb +++ b/libraries/drivers_worker_base.rb @@ -25,8 +25,6 @@ def add_worker_monit cookbook opts[:source_cookbook].to_s variables opts end - - context.execute 'monit reload' end def worker_monit_template_cookbook diff --git a/recipes/configure.rb b/recipes/configure.rb index 10a80afb..bb110922 100644 --- a/recipes/configure.rb +++ b/recipes/configure.rb @@ -35,4 +35,8 @@ webserver = Drivers::Webserver::Factory.build(self, application) fire_hook(:configure, items: databases + [source, framework, appserver, worker, webserver]) + + execute 'monit reload' do + only_if 'which monit' + end end diff --git a/spec/unit/recipes/configure_spec.rb b/spec/unit/recipes/configure_spec.rb index 975df6b5..a1ef19d4 100644 --- a/spec/unit/recipes/configure_spec.rb +++ b/spec/unit/recipes/configure_spec.rb @@ -24,9 +24,11 @@ let(:chef_run_rhel) do chef_runner_rhel.converge(described_recipe) end + let(:monit_installed) { false } before do stub_search(:aws_opsworks_app, '*:*').and_return([aws_opsworks_app]) stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([aws_opsworks_rds_db_instance]) + stub_command('which monit').and_return(monit_installed) end context 'context savvy' do @@ -65,6 +67,8 @@ end context 'Postgresql + Git + Unicorn + Nginx + Rails + Sidekiq' do + let(:monit_installed) { true } + it 'creates proper database.yml template with connection options' do db_config = Drivers::Db::Postgresql.new(chef_run, aws_opsworks_app, rds: aws_opsworks_rds_db_instance).out expect(db_config[:adapter]).to eq 'postgresql' @@ -502,6 +506,7 @@ solo_node.set['deploy'] = deploy end.converge(described_recipe) end + let(:monit_installed) { true } before do stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([aws_opsworks_rds_db_instance(engine: 'mysql')]) @@ -1023,6 +1028,7 @@ solo_node.set['nginx'] = node['nginx'] end.converge(described_recipe) end + let(:monit_installed) { true } before do stub_search(:aws_opsworks_app, '*:*').and_return([aws_opsworks_app(data_sources: [])]) diff --git a/spec/unit/recipes/deploy_spec.rb b/spec/unit/recipes/deploy_spec.rb index 54c79654..b839caaa 100644 --- a/spec/unit/recipes/deploy_spec.rb +++ b/spec/unit/recipes/deploy_spec.rb @@ -20,9 +20,11 @@ let(:chef_run_rhel) do chef_runner_rhel.converge(described_recipe) end + let(:monit_installed) { false } before do stub_search(:aws_opsworks_app, '*:*').and_return([aws_opsworks_app]) stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([aws_opsworks_rds_db_instance]) + stub_command('which monit').and_return(monit_installed) end it 'includes recipes' do @@ -69,6 +71,8 @@ end context 'Postgresql + Git + Unicorn + Nginx + Sidekiq' do + let(:monit_installed) { true } + it 'creates git wrapper script' do expect(chef_run).to create_template('/tmp/ssh-git-wrapper.sh') end @@ -204,6 +208,7 @@ solo_node.set['deploy'] = deploy end end + let(:monit_installed) { true } let(:tmpdir) { '/tmp/opsworks_ruby' } before do @@ -289,6 +294,7 @@ solo_node.set['deploy'] = deploy end end + let(:monit_installed) { true } let(:tmpdir) { '/tmp/opsworks_ruby' } before do