Guest User

Untitled

a guest
Jun 15th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. set :application, "MyAppName"
  2. set :domain, "domainname"
  3. set :user, "userid"
  4. set :repository, "svn+ssh://#{user}@#{domain}/home/#{user}/svn/#{application}/trunk"
  5. set :rails_env, :production
  6. set :chmod755, %w(app config db lib public vendor script tmp public/dispatch.cgi public/dispatch.fcgi public/dispatch.rb)
  7. set :deploy_to, "/home/#{user}/apps/#{application}"
  8. set :use_sudo, false
  9. set :deploy_via, :checkout
  10. set :group_writable, false
  11. default_run_options[:pty] = true
  12. role :app, domain
  13. role :web, domain
  14. role :db, domain, :primary => true
  15.  
  16. load 'deploy' if respond_to?(:namespace) # cap2 differentiator
  17. Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
  18. load 'config/deploy'
  19.  
  20. namespace :deploy do
  21.  
  22. task :restart, :roles => :app do
  23. run "#{current_path}/script/process/reaper --dispatcher=dispatch.fcgi"
  24. end
  25.  
  26. desc "Set the proper permissions for directories and files on HostingRails accounts"
  27. task :after_deploy do
  28. run(chmod755.collect do |item|
  29. "chmod 755 #{current_path}/#{item}"
  30. end.join(" && "))
  31. end
  32.  
  33. end
  34.  
  35. require 'erb'
  36.  
  37. before "deploy:setup", :db
  38. after "deploy:update_code", "db:symlink"
  39. after "deploy", "deploy:cleanup"
  40.  
  41. def prompt_with_default(var, default)
  42. set(var) do
  43. Capistrano::CLI.ui.ask "Enter #{var} [#{default}] : "
  44. end
  45.  
  46. set var, default if eval("#{var.to_s}.empty?")
  47. end
  48.  
  49. default_run_options[:pty] = true
  50.  
  51. set :rake, "/usr/local/bin/rake"
  52.  
  53. set :user, "your username"
  54. set :application, "application name"
  55. set :repository, "svn repository path"
  56. set :host, "domain name"
  57. set :db_host, "DB host name"
  58. set :db_user, "DB user name"
  59. set :db_prefix, "any DB name prefix your host might require"
  60. set :rails_env, "production"
  61.  
  62. set :deploy_to, "/home/username/rails/#{host}" # your deployment directory
  63.  
  64. role :app, host
  65. role :web, host
  66. role :db, host, :primary => true
  67.  
  68. set :use_sudo, false
  69. set :checkout, "export"
  70.  
  71. #
  72. # TASKS
  73. #
  74. desc "Tasks to execute after code update"
  75. task :after_update_code, :roles => [:app, :db, :web] do
  76. # Make sure we're running in production
  77. run "sed -i -e '/ENV.*RAILS_ENV/s/# //' #{release_path}/config/environment.rb"
  78. run "sed -i -e '/ENV.*RAILS_ENV/s/production/#{rails_env}/' #{release_path}/config/environment.rb"
  79.  
  80. # Add banned IPs
  81. deny_lines = []
  82. File.readlines("#{release_path}/config/banned_ips").each {|ip|
  83. deny_lines << "deny from #{ip}"
  84. }
  85.  
  86. ip_ban_block = <<EOBAN
  87. # Bannination
  88. order allow,deny
  89. #{deny_lines.join}
  90. allow from all
  91. EOBAN
  92.  
  93. run "sed -i -e 's/# BANNED IPS/#{ip_ban_block}/' #{release_path}/public/.htaccess"
  94.  
  95. run "chmod +x #{release_path}/script/runner"
  96. run "chmod +x #{release_path}/script/process/reaper"
  97. run "chmod +x #{release_path}/script/process/spawner"
  98. run "chmod 755 #{release_path}/public/dispatch.*"
  99. end
  100.  
  101. desc "Restarting after deployment"
  102. task :after_deploy, :roles => [:app, :db, :web] do
  103. run "cd #{current_path} && rake RAILS_ENV=production db:sessions:clear tmp:clear"
  104. # fix permissions
  105. run "dos2unix #{release_path}/public/dispatch.*"
  106. run "dos2unix #{release_path}/public/.htaccess"
  107. run "chmod -R 755 #{release_path}"
  108. run "chmod -R 775 #{release_path}/log #{release_path}/tmp #{release_path}/script"
  109. run "find #{release_path}/ | xargs touch"
  110. run "touch #{deploy_to}/current/public/dispatch.fcgi"
  111. end
  112.  
  113. desc "Restarting after rollback"
  114. task :after_rollback, :roles => [:app, :db, :web] do
  115. run "touch #{deploy_to}/current/public/dispatch.fcgi"
  116. end
  117.  
  118. namespace :db do
  119. desc "Create database yaml in shared path"
  120. task :default do
  121. prompt_with_default(:db_password, "")
  122. db_config = ERB.new <<-EOF
  123. base: &base
  124. adapter: mysql
  125. port: 3306
  126. host: #{db_host}
  127. username: #{db_user}
  128. password: #{db_password}
  129.  
  130. development:
  131. database: #{db_prefix}#{application}development
  132. <<: *base
  133.  
  134. test:
  135. database: #{db_prefix}#{application}test
  136. <<: *base
  137.  
  138. production:
  139. database: #{db_prefix}#{application}production
  140. <<: *base
  141. EOF
  142.  
  143. run "mkdir -p #{shared_path}/config"
  144. put db_config.result, "#{shared_path}/config/database.yml"
  145. end
  146.  
  147. desc "Make symlink for database yaml"
  148. task :symlink do
  149. run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  150. end
  151. end
  152.  
  153. svn export $svn_path . --force
  154. cap deploy
Add Comment
Please, Sign In to add comment