Merge pull request #5743 from betagouv/deploy-restart-jobs-for-workers

Redémarrage de delayed_job seulement pour les workers
This commit is contained in:
LeSim 2020-12-10 15:20:42 +01:00 committed by GitHub
commit bd697b6252
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ require 'mina/git'
require 'mina/rails'
require 'mina/rbenv'
SHARED_WORKER_FILE_NAME = 'i_am_a_worker'
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
@ -12,7 +13,8 @@ require 'mina/rbenv'
# Advanced settings:
# forward_agent - SSH forward_agent
# user - Username in the server to SSH to
# shared_dirs - Manually create these paths in shared/ on your server.
# shared_dirs, shared_files:
# - Manually create these paths in shared/ on your server.
# They will be linked in the 'deploy:link_shared_paths' step.
deploy_to = '/var/www/ds'
@ -23,6 +25,9 @@ shared_dirs = [
'tmp/pids',
'vendor/bundle'
]
shared_files = [
SHARED_WORKER_FILE_NAME
]
set :domain, ENV.fetch('domain')
set :deploy_to, deploy_to
@ -33,10 +38,17 @@ set :branch, ENV.fetch('branch')
set :forward_agent, true
set :user, 'ds'
set :shared_dirs, shared_dirs
set :shared_files, shared_files
set :rbenv_path, "/home/ds/.rbenv/bin/rbenv"
puts "Deploy to #{ENV.fetch('domain')}, branch: #{ENV.fetch('branch')}"
def is_worker_machine?
# The presence of a file identify if a machine is a worker or not.
# This is useful in order to know whether or not to restart delayed_job
File.file?(Rails.root.join(SHARED_WORKER_FILE_NAME))
end
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :setup do
@ -95,11 +107,13 @@ namespace :service do
desc "Restart delayed_job"
task :restart_delayed_job do
if is_worker_machine?
command %{
echo "-----> Restarting delayed_job service"
#{echo_cmd %[sudo systemctl restart delayed_job]}
}
end
end
end
desc "Deploys the current version to the server."