Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # config valid only for Capistrano 3.1
- lock '3.2.1'
- set :application, 'НАЗВАНИЕ_ПРИЛОЖЕНИЯ'
- application = 'НАЗВАНИЕ_ПРИЛОЖЕНИЯ'
- set :repo_url, 'ПУТЬ К РЕПОЗИТОРИЮ'
- #set :user, "deployer"
- set :rails_env, "production"
- set :bundle_flags, "--deployment"
- # Default branch is :master
- # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
- # Default deploy_to directory is /var/www/my_app
- # set :deploy_to, '/var/www/my_app'
- # Default value for :scm is :git
- # set :scm, :git
- # Default value for :format is :pretty
- # set :format, :pretty
- # Default value for :log_level is :debug
- # set :log_level, :debug
- # Default value for :pty is false
- set :pty, true
- # Default value for :linked_files is []
- # set :linked_files, %w{config/database.yml}
- # Default value for linked_dirs is []
- # set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
- # Default value for default_env is {}
- # set :default_env, { path: "/opt/ruby/bin:$PATH" }
- # Default value for keep_releases is 5
- # set :keep_releases, 5
- set :deploy_to, "/home/deployer/apps/#{application}"
- #set :deploy_via, :remote_cache
- set :scm, "git"
- set :branch, "master"
- set :ssh_options, { forward_agent: true }
- set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
- set :unicorn_config, "#{shared_path}/config/unicorn.rb"
- namespace :git do
- desc 'Push changes to repository'
- task :push do
- ask(:message, "Commit message?")
- run_locally do
- execute "git add -A"
- execute "git commit -m '#{fetch(:message)}'"
- execute "git push"
- end
- end
- end
- namespace :unicorn do
- desc 'Stop Unicorn'
- task :stop do
- on roles(:app) do
- if test("[ -f #{fetch(:unicorn_pid)} ]")
- execute :kill, capture(:cat, fetch(:unicorn_pid))
- end
- end
- end
- desc 'Start Unicorn'
- task :start do
- on roles(:app) do
- within current_path do
- with rails_env: fetch(:rails_env) do
- execute :bundle, "exec unicorn -c #{fetch(:unicorn_config)} -D"
- end
- end
- end
- end
- desc 'Reload Unicorn without killing master process'
- task :reload do
- on roles(:app) do
- if test("[ -f #{fetch(:unicorn_pid)} ]")
- execute :kill, '-s USR2', capture(:cat, fetch(:unicorn_pid))
- else
- error 'Unicorn process not running'
- end
- end
- end
- desc 'Restart Unicorn'
- task :restart
- before :restart, :stop
- before :restart, :start
- end
- namespace :deploy do
- desc 'Setup Config'
- task :setup_config do
- on roles(:all) do
- execute "mkdir -p #{shared_path}/config"
- execute "mkdir -p #{shared_path}/pids"
- upload!('shared/database.yml', "#{shared_path}/config/")
- upload!('shared/nginx.conf', "#{shared_path}/config/")
- upload!('shared/unicorn.rb', "#{shared_path}/config/")
- sudo "ln -nfs #{shared_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
- sudo "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
- end
- end
- # before :starting, "git:push"
- after :updating, "deploy:setup_config"
- before :publishing, "unicorn:stop"
- after :publishing, "unicorn:start"
- after :finishing, "deploy:cleanup" # keep only the last 5 releases
- end
Advertisement
Add Comment
Please, Sign In to add comment