From 1972bd6219b6b63426573da9fef95760acb64389 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 20 Dec 2019 16:01:14 +0100 Subject: [PATCH] Reload Unicorn and Sidekiq after deployment So we can remove the following manual step from the deployment process: > 9. There is one last step though. Until we don't fix it, the app server needs to be restarted manually for the changes to be loaded. Run: > $ ssh timeoverflow@www.timeoverflow.org > $ sudo systemctl restart timeoverflow > $ sudo systemctl restart sidekiq Now Capistrano's output looks like: ``` INFO [fbff0613] Running /usr/bin/env rm -rf /var/www/timeoverflow/releases/20191220151536 as timeoverflow@staging.timeoverflow.org DEBUG [fbff0613] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env rm -rf /var/www/timeoverflow/releases/20191220151536 ) INFO [fbff0613] Finished in 0.183 seconds with exit status 0 (successful). INFO [9ab57c12] Running sudo systemctl reload timeoverflow as timeoverflow@staging.timeoverflow.org DEBUG [9ab57c12] Command: sudo systemctl reload timeoverflow INFO [9ab57c12] Finished in 0.218 seconds with exit status 0 (successful). INFO [41e063eb] Running sudo systemctl restart sidekiq as timeoverflow@staging.timeoverflow.org DEBUG [41e063eb] Command: sudo systemctl restart sidekiq INFO [41e063eb] Finished in 2.895 seconds with exit status 0 (successful). DEBUG [3772e021] Running if test ! -d /var/www/timeoverflow/releases; then echo "Directory does not exist '/var/www/timeoverflow/releases'" 1>&2; false; fi as timeoverflow@staging.timeoverflow.org DEBUG [3772e021] Command: if test ! -d /var/www/timeoverflow/releases; then echo "Directory does not exist '/var/www/timeoverflow/releases'" 1>&2; false; fi DEBUG [3772e021] Finished in 0.181 seconds with exit status 0 (successful). INFO [266848f2] Running echo "Branch reload-unicorn-after-deployment (at fad9dbd) deployed as release 20191220152039 by pau" >> /var/www/timeoverflow/revisions.log as timeoverflow@staging.timeoverflow.org DEBUG [266848f2] Command: echo "Branch reload-unicorn-after-deployment (at fad9dbd) deployed as release 20191220152039 by pau" >> /var/www/timeoverflow/revisions.log INFO [266848f2] Finished in 0.181 seconds with exit status 0 (successful). ``` Which generates the following log line ``` ==> log/unicorn.err.log <== E, [2019-12-20T16:20:59.911297 #32630] ERROR -- : reexec-ed child already running PID:1213 ``` --- config/deploy.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index eb4d44cf7..ba4e81a33 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -47,13 +47,20 @@ # Default value for keep_releases is 5 # set :keep_releases, 5 -namespace :deploy do - after :restart, :clear_cache do - on roles(:web), in: :groups, limit: 3, wait: 10 do - # Here we can do anything such as: - # within release_path do - # execute :rake, 'cache:clear' - # end +namespace :unicorn do + desc 'reload Unicorn' + task :reload do + on roles(:app) do + execute "sudo systemctl reload timeoverflow" + end + end +end + +namespace :sidekiq do + desc 'reload Sidekiq' + task :restart do + on roles(:app) do + execute "sudo systemctl restart sidekiq" end end end @@ -67,4 +74,8 @@ end end end + before "deploy:migrate", "deploy:db:load" if ENV["COLD"] + +after "deploy:finishing", "unicorn:reload" +after "deploy:finishing", "sidekiq:restart"