Guest User

Untitled

a guest
Apr 10th, 2018
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. set :application, "application"
  2. set :user, 'deploy'
  3. set :group, 'admin'
  4. set :server_name, "adamelliot.com"
  5. set :server_alias, "*.adamelliot.*"
  6. set :git_server, "git.warptube.com"
  7.  
  8. ssh_options[:port] = 22
  9.  
  10. # You shouldn't need to change anything past this point, unless you are
  11. # modifying the script for a different server configuration.
  12.  
  13. set :scm_user, "cap"
  14. set :repository, "git@#{git_server}:#{application}.git"
  15.  
  16. set :scm, "git"
  17. set :checkout, "export"
  18. set :deploy_via, :remote_cache
  19. set :branch, "master"
  20.  
  21. set :base_path, "/u/apps"
  22. set :deploy_to, "#{base_path}/#{application}"
  23.  
  24. set :apache_site_folder, "/etc/apache2/sites-enabled"
  25. set :use_sudo, true
  26. set :keep_releases, 3
  27.  
  28. role :app, server_name
  29. role :web, server_name
  30. role :db, server_name, :primary => true
  31.  
  32. ssh_options[:paranoid] = false
  33. default_run_options[:pty] = true
  34.  
  35. after "deploy:setup", "init:set_permissions"
  36. after "deploy:setup", "init:database_yml"
  37. after "deploy:setup", "init:create_database"
  38. after "deploy:setup", "init:create_vhost"
  39. after "deploy:setup", "init:enable_site"
  40. after "deploy:setup", "config:reload_apache"
  41. after "deploy", "deploy:restart"
  42. #after "deploy", "sphinx:index"
  43. after "deploy:update_code", "config:copy_shared_configurations"
  44.  
  45. namespace :deploy do
  46. [:start, :restart].each do |t|
  47. desc "Restarting mod_rails with restart.txt"
  48. task t, :roles => :app, :except => {:no_release => true} do
  49. run "touch #{current_path}/tmp/restart.txt"
  50. end
  51. end
  52.  
  53. desc "Runs db:populate on the server."
  54. task :migrate_and_populate do
  55. run("cd #{current_path}; /usr/bin/rake db:populate RAILS_ENV=production")
  56. end
  57.  
  58. desc "Stop task is a no-op with mod_rails"
  59. task :stop, :roles => :app do ; end
  60. end
  61.  
  62. namespace :sphinx do
  63. [:start, :restart, :index].each do |t|
  64. desc "Runs the ts:#{t} task on the server."
  65. task t, :roles => :app do
  66. run("cd #{current_path}; /usr/bin/rake ts:#{t} RAILS_ENV=production")
  67. end
  68. end
  69. end
  70.  
  71. namespace :config do
  72. desc "copy shared configurations to current"
  73. task :copy_shared_configurations, :roles => [:app] do
  74. %w[database.yml].each do |f|
  75. run "ln -nsf #{shared_path}/config/#{f} #{release_path}/config/#{f}"
  76. end
  77. end
  78.  
  79. desc "reloads apache configuration to make site active"
  80. task :reload_apache do
  81. sudo "/etc/init.d/apache2 reload"
  82. end
  83. end
  84.  
  85. namespace :gems do
  86. desc "Install gems"
  87. task :install, :roles => :app do
  88. run "cd #{current_path} && #{sudo} rake RAILS_ENV=production gems:install"
  89. end
  90. end
  91.  
  92. namespace :init do
  93. desc "setting proper permissions for deploy user"
  94. task :set_permissions do
  95. sudo "chmod -R g+rw #{base_path}/#{application}"
  96. sudo "chown -R #{user}:#{group} #{base_path}/#{application}"
  97. end
  98.  
  99. desc "create mysql db"
  100. task :create_database do
  101. set :db_root_user, 'root'#Capistrano::CLI.ui.ask("mysql super user: ") unless defined?(db_root_user)
  102. set :db_root_pass, Capistrano::CLI.password_prompt("#{db_root_user}'s database password: ") unless defined?(db_root_pass)
  103.  
  104. set :db_user, "#{application}"
  105. set :db_pass, Capistrano::CLI.password_prompt("new database password: ") unless defined?(db_pass)
  106.  
  107. # Create new user role, then create a database they can administer
  108. run "echo \"CREATE DATABASE #{application}_production\" | mysql -u #{db_root_user} --password=#{db_root_pass}"
  109. run "echo \"GRANT ALL PRIVILEGES ON #{application}_production.* TO '#{application}'@'localhost' IDENTIFIED BY '#{db_pass}' WITH GRANT OPTION;\" | mysql -u #{db_root_user} --password=#{db_root_pass}"
  110. end
  111.  
  112. desc "enable site"
  113. task :enable_site do
  114. sudo "ln -nsf #{shared_path}/config/apache_site.conf #{apache_site_folder}/#{application}"
  115. end
  116.  
  117. desc "create database.yml"
  118. task :database_yml do
  119. set :db_user, "#{application}"
  120. set :db_pass, Capistrano::CLI.password_prompt("new database password: ") unless defined?(db_pass)
  121. database_configuration = <<-DATABASE_YML
  122. login: &login
  123. adapter: mysql
  124. encoding: utf8
  125. database: #{application}_production
  126. host: localhost
  127. pool: 5
  128. username: #{db_user}
  129. password: #{db_pass}
  130. socket: /var/run/mysqld/mysqld.sock
  131.  
  132. production:
  133. <<: *login
  134. DATABASE_YML
  135. run "mkdir -p #{shared_path}/config"
  136. put database_configuration, "#{shared_path}/config/database.yml"
  137. end
  138.  
  139. desc "create vhost file"
  140. task :create_vhost do
  141. vhost_configuration = <<-VHOST
  142. <VirtualHost *:80>
  143. ServerName #{server_name}
  144. ServerAlias #{server_alias}
  145. DocumentRoot "#{base_path}/#{application}/current/public"
  146. RailsEnv production
  147. RailsAllowModRewrite off
  148. <directory "#{base_path}/#{application}/current/public">
  149. Order allow,deny
  150. Allow from all
  151. </directory>
  152. </VirtualHost>
  153. VHOST
  154.  
  155. put vhost_configuration, "#{shared_path}/config/apache_site.conf"
  156. end
  157.  
  158. end
Add Comment
Please, Sign In to add comment