deploy.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # This is an example Capistrano deployment script for Huginn. It
  2. # assumes you're running on an Ubuntu box and want to use Foreman,
  3. # Upstart, and Unicorn.
  4. default_run_options[:pty] = true
  5. set :application, "huginn"
  6. set :deploy_to, "/home/you/app"
  7. set :user, "you"
  8. set :use_sudo, false
  9. set :scm, :git
  10. set :rails_env, 'production'
  11. set :repository, "git@github.com:you/huginn-private.git"
  12. set :branch, ENV['BRANCH'] || "master"
  13. set :deploy_via, :remote_cache
  14. set :keep_releases, 5
  15. puts " Deploying #{branch}"
  16. set :bundle_without, [:development]
  17. server "yourdomain.com", :app, :web, :db, :primary => true
  18. set :sync_backups, 3
  19. before 'deploy:restart', 'deploy:migrate'
  20. after 'deploy', 'deploy:cleanup'
  21. set :bundle_without, [:development, :test]
  22. after 'deploy:update_code', 'deploy:symlink_configs'
  23. after 'deploy:update', 'foreman:export'
  24. after 'deploy:update', 'foreman:restart'
  25. namespace :deploy do
  26. desc 'Link the .env environment and Procfile from shared/config into the new deploy directory'
  27. task :symlink_configs, :roles => :app do
  28. run <<-CMD
  29. cd #{latest_release} && ln -nfs #{shared_path}/config/.env #{latest_release}/.env
  30. CMD
  31. run <<-CMD
  32. cd #{latest_release} && ln -nfs #{shared_path}/config/Procfile #{latest_release}/Procfile
  33. CMD
  34. end
  35. end
  36. namespace :foreman do
  37. desc "Export the Procfile to Ubuntu's upstart scripts"
  38. task :export, :roles => :app do
  39. run "cd #{latest_release} && rvmsudo bundle exec foreman export upstart /etc/init -a #{application} -u #{user} -l #{deploy_to}/upstart_logs"
  40. end
  41. desc 'Start the application services'
  42. task :start, :roles => :app do
  43. sudo "sudo start #{application}"
  44. end
  45. desc 'Stop the application services'
  46. task :stop, :roles => :app do
  47. sudo "sudo stop #{application}"
  48. end
  49. desc 'Restart the application services'
  50. task :restart, :roles => :app do
  51. run "sudo start #{application} || sudo restart #{application}"
  52. end
  53. end
  54. # If you want to use rvm on your server and have it maintained by Capistrano, uncomment these lines:
  55. # set :rvm_ruby_string, '2.0.0@huginn'
  56. # set :rvm_type, :user
  57. # before 'deploy', 'rvm:install_rvm'
  58. # before 'deploy', 'rvm:install_ruby'
  59. # require "rvm/capistrano"
  60. # Load Capistrano additions
  61. Dir[File.expand_path("../../lib/capistrano/*.rb", __FILE__)].each{|f| load f }
  62. require "bundler/capistrano"
  63. load 'deploy/assets'