From 9a75f9c21d5986c9381b2a1419fd6300600b5259 Mon Sep 17 00:00:00 2001 From: Igor Rzegocki Date: Sat, 16 Apr 2016 20:13:59 +0200 Subject: [PATCH] Fixed appserver restart sequence --- libraries/drivers_appserver_unicorn.rb | 19 ++++++++++++++++++- spec/unit/recipes/deploy_spec.rb | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libraries/drivers_appserver_unicorn.rb b/libraries/drivers_appserver_unicorn.rb index aff3ec7d..2a688995 100644 --- a/libraries/drivers_appserver_unicorn.rb +++ b/libraries/drivers_appserver_unicorn.rb @@ -7,7 +7,7 @@ class Unicorn < Drivers::Appserver::Base output filter: [ :accept_filter, :backlog, :delay, :preload_app, :tcp_nodelay, :tcp_nopush, :tries, :timeout, :worker_processes ] - notifies action: :restart, + notifies action: :start, resource: proc { |app| "service[unicorn_#{app['shortname']}]" }, timer: :immediately @@ -17,8 +17,25 @@ def configure(context) add_unicorn_service_context(context) end + def before_deploy(context) + manual_action(context, :stop) + end + + def after_deploy(context) + manual_action(context, :start) + end + private + def manual_action(context, action) + deploy_to = deploy_dir(app) + service_script = File.join(deploy_to, File.join('shared', 'scripts', 'unicorn.service')) + + context.execute "#{action} unicorn" do + command "#{service_script} #{action}" + end + end + def add_unicorn_config(context) deploy_to = deploy_dir(app) environment = app['environment'] diff --git a/spec/unit/recipes/deploy_spec.rb b/spec/unit/recipes/deploy_spec.rb index e4070350..b798cf56 100644 --- a/spec/unit/recipes/deploy_spec.rb +++ b/spec/unit/recipes/deploy_spec.rb @@ -35,8 +35,6 @@ end it 'performs a deploy' do - deploy = chef_run.deploy(aws_opsworks_app['shortname']) - expect(chef_run).to deploy_deploy('dummy_project').with( repository: 'git@git.example.com:repo/project.git', revision: 'master', @@ -44,7 +42,9 @@ enable_submodules: false, ssh_wrapper: '/tmp/ssh-git-wrapper.sh' ) - expect(deploy).to notify("service[unicorn_#{aws_opsworks_app['shortname']}]").to(:restart).immediately + + expect(chef_run).to run_execute('stop unicorn') + expect(chef_run).to run_execute('start unicorn') end end end