From 335cd2b597be9c2821df0c1074761a335e64e8a3 Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Fri, 21 Sep 2018 15:29:57 +0200 Subject: [PATCH 1/6] Link unicorn and production.rb to capistrano's shared folder --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index a268bb326..f5d570665 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -21,7 +21,7 @@ set :log_level, :info set :pty, true set :use_sudo, false -set :linked_files, %w{config/database.yml config/secrets.yml} +set :linked_files, %w{config/database.yml config/secrets.yml config/unicorn.rb config/environments/production.rb} set :linked_dirs, %w{log tmp public/system public/assets} set :keep_releases, 5 From bebcc3da489ea47aafb82fee389e6dca8a43c8ef Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Fri, 21 Sep 2018 15:31:40 +0200 Subject: [PATCH 2/6] Skip ruby and bundler installations Ruby and bundler should already be installed in the system Before we can bring back these commands we need to review them, right now they are raising an interesting exception --- config/deploy.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index f5d570665..c89869333 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -41,9 +41,9 @@ set(:config_files, %w( set :whenever_roles, -> { :app } namespace :deploy do - before :starting, 'rvm1:install:rvm' # install/update RVM - before :starting, 'rvm1:install:ruby' # install Ruby and create gemset - before :starting, 'install_bundler_gem' # install bundler gem + #before :starting, 'rvm1:install:rvm' # install/update RVM + #before :starting, 'rvm1:install:ruby' # install Ruby and create gemset + #before :starting, 'install_bundler_gem' # install bundler gem after :publishing, 'deploy:restart' after :published, 'delayed_job:restart' From 8cfcc7e693032906b77339e5f70bd3f7301e0784 Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Fri, 21 Sep 2018 15:32:41 +0200 Subject: [PATCH 3/6] Use master as the default deploy branch It's a good practice to use a stable branch for deployments, but not all forks have this branch configured Using master as the default branch for now --- config/deploy/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 90eb501c2..4af02ce50 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,7 +1,7 @@ set :deploy_to, deploysecret(:deploy_to) set :server_name, deploysecret(:server_name) set :db_server, deploysecret(:db_server) -set :branch, :stable +set :branch, :master set :ssh_options, port: deploysecret(:ssh_port) set :stage, :production set :rails_env, :production From 4f4769062a48ad68134317450f3d6fc7e9e30ae6 Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Fri, 21 Sep 2018 15:34:40 +0200 Subject: [PATCH 4/6] Use a single server by default Capistrano configuration is prepared to deploy to multiple servers For now assuming that we are going to use a single server for everthing (app, db, cron jobs, queue system, etc) --- config/deploy/production.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 4af02ce50..14ae536ac 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -6,7 +6,7 @@ set :ssh_options, port: deploysecret(:ssh_port) set :stage, :production set :rails_env, :production -#server deploysecret(:server1), user: deploysecret(:user), roles: %w(web app db importer) -server deploysecret(:server2), user: deploysecret(:user), roles: %w(web app db importer cron background) -server deploysecret(:server3), user: deploysecret(:user), roles: %w(web app db importer) -server deploysecret(:server4), user: deploysecret(:user), roles: %w(web app db importer) +server deploysecret(:server1), user: deploysecret(:user), roles: %w(web app db importer cron background) +#server deploysecret(:server2), user: deploysecret(:user), roles: %w(web app db importer cron background) +#server deploysecret(:server3), user: deploysecret(:user), roles: %w(web app db importer) +#server deploysecret(:server4), user: deploysecret(:user), roles: %w(web app db importer) From e3c6fc77c623494915fdeec83ad527dac1f2dec1 Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Fri, 21 Sep 2018 15:39:56 +0200 Subject: [PATCH 5/6] Update Unicorn restart task We are using a simple unicorn.rb file in the Installer, which requires a different way of restarting the server This task is still a little limited and hackish but it does the job for now :relieved: We are killing any existing unicorn process and starting unicorn. It checks for existing processes in both the standard consul folder and in the capistrano `current` folder, and skipping any exception if unicorn was not running. --- lib/capistrano/tasks/restart.cap | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/capistrano/tasks/restart.cap b/lib/capistrano/tasks/restart.cap index 54c90819a..787191056 100644 --- a/lib/capistrano/tasks/restart.cap +++ b/lib/capistrano/tasks/restart.cap @@ -1,10 +1,8 @@ -namespace :deploy do - desc 'Commands for unicorn application' - %w(start stop force-stop restart upgrade reopen-logs).each do |command| - task command.to_sym do - on roles(:app), in: :sequence, wait: 5 do - execute "/etc/init.d/unicorn_#{fetch(:full_app_name)} #{command}" - end - end +desc 'Restart Unicorn' +task :restart do + on roles(:app) do + execute "kill -QUIT `cat /home/deploy/consul/pids/unicorn.pid`; true" + execute "kill -QUIT `cat /home/deploy/consul/shared/pids/unicorn.pid`; true" + execute "cd /home/deploy/consul/current && /home/deploy/.rvm/gems/ruby-2.3.2/wrappers/unicorn -c config/unicorn.rb -E production -D" end -end +end \ No newline at end of file From d0dbb16d72ffd9bfe4f35a663c95e271a8820d15 Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Fri, 21 Sep 2018 18:11:21 +0200 Subject: [PATCH 6/6] Add unicorn restart task to deploy namespace --- lib/capistrano/tasks/restart.cap | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/capistrano/tasks/restart.cap b/lib/capistrano/tasks/restart.cap index 787191056..30740e3a7 100644 --- a/lib/capistrano/tasks/restart.cap +++ b/lib/capistrano/tasks/restart.cap @@ -1,8 +1,10 @@ -desc 'Restart Unicorn' -task :restart do - on roles(:app) do - execute "kill -QUIT `cat /home/deploy/consul/pids/unicorn.pid`; true" - execute "kill -QUIT `cat /home/deploy/consul/shared/pids/unicorn.pid`; true" - execute "cd /home/deploy/consul/current && /home/deploy/.rvm/gems/ruby-2.3.2/wrappers/unicorn -c config/unicorn.rb -E production -D" - end +namespace :deploy do + desc 'Restart Unicorn' + task :restart do + on roles(:app) do + execute "kill -QUIT `cat /home/deploy/consul/pids/unicorn.pid`; true" + execute "kill -QUIT `cat /home/deploy/consul/shared/pids/unicorn.pid`; true" + execute "cd /home/deploy/consul/current && /home/deploy/.rvm/gems/ruby-2.3.2/wrappers/unicorn -c config/unicorn.rb -E production -D" + end + end end \ No newline at end of file