Advertisement
Guest User

Untitled

a guest
Feb 12th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.27 KB | None | 0 0
  1. # config valid for current version and patch releases of Capistrano
  2. lock "~> 3.11.0"
  3.  
  4. set :application, 'gconti'
  5. set :repo_url, 'git@git.u2c.su:U2C/conti/backend.git'
  6. set :rails_env, 'production'
  7.  
  8. set :username, 'contirails'
  9. set :application, 'backend'
  10. set :deploy_to, "/home/#{fetch(:username)}/#{fetch(:application)}"
  11. set :log_level, :info
  12. set :linked_files, %w{config/secrets.yml config/database.yml}
  13. set :rvm_ruby_version, '2.5.1'
  14. set :default_shell, :bash
  15. # Default branch is :master
  16. # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
  17.  
  18. # Default deploy_to directory is /var/www/my_app_name
  19. #set :deploy_to, '/home/conti/srv/gconti'
  20.  
  21. # Default value for :format is :airbrussh.
  22. # set :format, :airbrussh
  23.  
  24. # You can configure the Airbrussh format using :format_options.
  25. # These are the defaults.
  26. # set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
  27.  
  28. # Default value for :pty is false
  29. # set :pty, true
  30.  
  31. # Default value for :linked_files is []
  32. #append :linked_files, 'config/database.yml', 'config/secrets.yml'
  33.  
  34. # Default value for linked_dirs is []
  35. #append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system', 'public/uploads'
  36.  
  37. # Default value for default_env is {}
  38. # set :default_env, { path: "/opt/ruby/bin:$PATH" }
  39.  
  40. # Default value for local_user is ENV['USER']
  41. # set :local_user, -> { `git config user.name`.chomp }
  42.  
  43. # Default value for keep_releases is 5
  44. # set :keep_releases, 5
  45.  
  46. # Uncomment the following to require manually verifying the host key before first deploy.
  47. # set :ssh_options, verify_host_key: :secure
  48.  
  49.  
  50. namespace :setup do
  51.   desc 'Загрузка конфигурационных файлов на удаленный сервер'
  52.   task :upload_config do
  53.     on roles :all do
  54.       execute :mkdir, "-p #{shared_path}"
  55.       ['shared/config', 'shared/run'].each do |f|
  56.         upload!(f, shared_path, recursive: true)
  57.       end
  58.     end
  59.   end
  60. end
  61.  
  62. namespace :nginx do
  63.   desc 'Создание симлинка в /etc/nginx/conf.d на nginx.conf приложения'
  64.   task :append_config do
  65.     on roles :all do
  66.       sudo :ln, "-fs #{shared_path}/config/nginx.conf /etc/nginx/conf.d/#{fetch(:application)}.conf"
  67.     end
  68.   end
  69.   desc 'Релоад nginx'
  70.   task :reload do
  71.     on roles :all do
  72.       sudo :service, :nginx, :reload
  73.     end
  74.   end
  75.   desc 'Рестарт nginx'
  76.   task :restart do
  77.     on roles :all do
  78.       sudo :service, :nginx, :restart
  79.     end
  80.   end
  81.   after :append_config, :restart
  82. end
  83.  
  84. set :unicorn_config, "#{shared_path}/config/unicorn.rb"
  85. set :unicorn_pid, "#{shared_path}/run/unicorn.pid"
  86.  
  87. namespace :application do
  88.   desc 'Запуск Unicorn'
  89.   task :start do
  90.     on roles(:app) do
  91.       execute "cd #{release_path} && ~/.rvm/bin/rvm default do bundle exec unicorn_rails -c #{fetch(:unicorn_config)} -E #{fetch(:rails_env)} -D"
  92.     end
  93.   end
  94.   desc 'Завершение Unicorn'
  95.   task :stop do
  96.     on roles(:app) do
  97.       execute "if [ -f #{fetch(:unicorn_pid)} ] && [ -e /proc/$(cat #{fetch(:unicorn_pid)}) ]; then kill -9 `cat #{fetch(:unicorn_pid)}`; fi"
  98.     end
  99.   end
  100. end
  101.  
  102. namespace :deploy do
  103.   after :finishing, 'application:stop'
  104.   after :finishing, 'application:start'
  105.   after :finishing, :cleanup
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement