When someone installs CONSUL with the installer using a custom `app_name`, the deployment configuration file must use the same application name; otherwise, the Capistrano task to update the crontab will duplicate the crontab entries with different names causing unexpected errors. Below is an example of the issue. The first set of crontab entries was created during installation using a custom app_name. The second set of entries are duplicated during the first deployment with a wrong application name in the config/deploy.rb file. ``` deploy@ubuntu:~$ crontab -l * * * * * /bin/bash -l -c 'date > ~/cron-test.txt' 0 5 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230529101753 && RAILS_ENV=production bundle exec rake -s sitemap:refresh --silent' 0 1 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230529101753 && RAILS_ENV=production bundle exec rake files:remove_old_cached_attachments --silent' 0 3 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230529101753 && RAILS_ENV=production bundle exec rake votes:reset_hot_score --silent' 0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230529101753 && RAILS_ENV=production bundle exec rake -s stats:generate --silent' @reboot /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230529101753 && bundle exec puma -C config/puma/production.rb' @reboot /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230529101753 && RAILS_ENV=production bin/delayed_job -n 2 restart' * * * * * /bin/bash -l -c 'date > ~/cron-test.txt' 0 5 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230530112702 && RAILS_ENV=production bundle exec rake -s sitemap:refresh --silent' 0 1 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230530112702 && RAILS_ENV=production bundle exec rake files:remove_old_cached_attachments --silent' 0 3 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230530112702 && RAILS_ENV=production bundle exec rake votes:reset_hot_score --silent' 0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230530112702 && RAILS_ENV=production bundle exec rake -s stats:generate --silent' @reboot /bin/bash -l -c 'cd /home/deploy/participacyl/releases/20230530112702 && bundle exec puma -C config/puma/production.rb' ```
129 lines
3.2 KiB
Ruby
129 lines
3.2 KiB
Ruby
# config valid only for current version of Capistrano
|
|
lock "~> 3.17.1"
|
|
|
|
def deploysecret(key, default: "")
|
|
@deploy_secrets_yml ||= YAML.load_file("config/deploy-secrets.yml")[fetch(:stage).to_s]
|
|
@deploy_secrets_yml.fetch(key.to_s, default)
|
|
end
|
|
|
|
def main_deploy_server
|
|
if deploysecret(:server1) && !deploysecret(:server1).empty?
|
|
deploysecret(:server1)
|
|
else
|
|
deploysecret(:server)
|
|
end
|
|
end
|
|
|
|
set :rails_env, fetch(:stage)
|
|
set :rvm1_map_bins, -> { fetch(:rvm_map_bins).to_a.concat(%w[rake gem bundle ruby]).uniq }
|
|
|
|
set :application, deploysecret(:app_name, default: "consul")
|
|
set :deploy_to, deploysecret(:deploy_to)
|
|
set :ssh_options, port: deploysecret(:ssh_port)
|
|
|
|
set :repo_url, "https://github.com/consul/consul.git"
|
|
|
|
set :revision, `git rev-parse --short #{fetch(:branch)}`.strip
|
|
|
|
set :log_level, :info
|
|
set :pty, true
|
|
set :use_sudo, false
|
|
|
|
set :linked_files, %w[config/database.yml config/secrets.yml]
|
|
set :linked_dirs, %w[.bundle log tmp public/system public/assets public/ckeditor_assets public/machine_learning/data storage]
|
|
|
|
set :keep_releases, 5
|
|
|
|
set :local_user, ENV["USER"]
|
|
|
|
set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb"
|
|
|
|
set :delayed_job_workers, 2
|
|
set :delayed_job_roles, :background
|
|
|
|
set :whenever_roles, -> { :app }
|
|
|
|
namespace :deploy do
|
|
Rake::Task["delayed_job:default"].clear_actions
|
|
Rake::Task["puma:smart_restart"].clear_actions
|
|
|
|
after :updating, "install_ruby"
|
|
|
|
after "deploy:migrate", "add_new_settings"
|
|
|
|
after :publishing, "setup_puma"
|
|
|
|
after :published, "deploy:restart"
|
|
before "deploy:restart", "puma:restart"
|
|
before "deploy:restart", "delayed_job:restart"
|
|
before "deploy:restart", "puma:start"
|
|
|
|
after :finished, "refresh_sitemap"
|
|
|
|
desc "Deploys and runs the tasks needed to upgrade to a new release"
|
|
task :upgrade do
|
|
after "add_new_settings", "execute_release_tasks"
|
|
invoke "deploy"
|
|
end
|
|
end
|
|
|
|
task :install_ruby do
|
|
on roles(:app) do
|
|
within release_path do
|
|
begin
|
|
current_ruby = capture(:rvm, "current")
|
|
rescue SSHKit::Command::Failed
|
|
after "install_ruby", "rvm1:install:rvm"
|
|
after "install_ruby", "rvm1:install:ruby"
|
|
else
|
|
if current_ruby.include?("not installed")
|
|
after "install_ruby", "rvm1:install:rvm"
|
|
after "install_ruby", "rvm1:install:ruby"
|
|
else
|
|
info "Ruby: Using #{current_ruby}"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
task :refresh_sitemap do
|
|
on roles(:app) do
|
|
within release_path do
|
|
with rails_env: fetch(:rails_env) do
|
|
execute :rake, "sitemap:refresh:no_ping"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
task :add_new_settings do
|
|
on roles(:db) do
|
|
within release_path do
|
|
with rails_env: fetch(:rails_env) do
|
|
execute :rake, "settings:add_new_settings"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
task :execute_release_tasks do
|
|
on roles(:app) do
|
|
within release_path do
|
|
with rails_env: fetch(:rails_env) do
|
|
execute :rake, "consul:execute_release_tasks"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
desc "Create pid and socket folders needed by puma"
|
|
task :setup_puma do
|
|
on roles(:app) do
|
|
with rails_env: fetch(:rails_env) do
|
|
execute "mkdir -p #{shared_path}/tmp/sockets; true"
|
|
execute "mkdir -p #{shared_path}/tmp/pids; true"
|
|
end
|
|
end
|
|
end
|