Guest User

Untitled

a guest
Apr 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. require 'palmtree/recipes/mongrel_cluster'
  2.  
  3. set :domain, "dev.mysite.com"
  4. set :application, "mysite"
  5.  
  6. set :keep_releases, 3
  7. set :repository, "svn://#{domain}/#{application}/trunk"
  8. set :scm, :subversion
  9. set :deploy_via, :export
  10. set :deploy_to, "/var/www/#{application}"
  11.  
  12. set :user, "deploy"
  13. set :runner, "mongrel"
  14. set :use_sudo, :true
  15.  
  16. set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
  17.  
  18. role :app, "#{domain}"
  19. role :web, "#{domain}"
  20. role :db, "#{domain}", :primary => true
  21.  
  22. # == CONFIG ====================================================================
  23. namespace :init do
  24. namespace :config do
  25. desc "Create database.yml"
  26. task :database do
  27. set :db_host, Capistrano::CLI.ui.ask("database host: ")
  28. set :db_user, Capistrano::CLI.ui.ask("database user: ")
  29. set :db_pass, Capistrano::CLI.password_prompt("database password: ")
  30. database_configuration =<<-EOF
  31. ---
  32.  
  33. production:
  34. adapter: mysql
  35. database: #{application}
  36. host: #{db_host}
  37. username: #{db_user}
  38. password: #{db_pass}
  39. EOF
  40. run "mkdir -p #{shared_path}/config"
  41. put database_configuration, "#{shared_path}/config/database.yml"
  42. end
  43.  
  44. desc "Create backgroundrb.yml"
  45. task :backgroundrb, :roles => :app do
  46. backgroundrb_configuration = <<-EOF
  47. :backgroundrb:
  48. :ip: 127.0.0.1
  49. :port: 22222
  50. :environment: production
  51. EOF
  52. run "mkdir -p #{shared_path}/config"
  53. put backgroundrb_configuration, "#{shared_path}/config/backgroundrb.yml"
  54. end
  55.  
  56. desc "Create mongrel_cluster.yml"
  57. task :mongrel, :roles => [:app] do
  58. mongrel_cluster_configuration = <<-EOF
  59. ---
  60. user: mongrel
  61. cwd: #{current_path}
  62. log_file: #{current_path}/log/mongrel.log
  63. port: "9000"
  64. environment: production
  65. group: mongrel
  66. address: 127.0.0.1
  67. pid_file: #{current_path}/tmp/pids/mongrel.pid
  68. servers: 3
  69. EOF
  70. run "mkdir -p #{shared_path}/config"
  71. put mongrel_cluster_configuration, "#{shared_path}/config/mongrel_cluster.yml"
  72. end
  73.  
  74. desc "Symlink shared configurations to current"
  75. task :localize, :roles => [:app] do
  76. %w[memcached.yml mongrel_cluster.yml amazon_s3.yml amazon_sqs.yml database.yml backgroundrb.yml].each do |f|
  77. run "rm -f #{current_path}/config/#{f}"
  78. run "ln -nsf #{shared_path}/config/#{f} #{current_path}/config/#{f}"
  79. end
  80. end
  81. end
  82. end
  83.  
  84.  
  85. # == NGINX =====================================================================
  86. namespace :nginx do
  87. desc "Start Nginx on the app server."
  88. task :start, :roles => :app do
  89. sudo "/etc/init.d/nginx start"
  90. end
  91.  
  92. desc "Restart the Nginx processes on the app server by starting and stopping the cluster."
  93. task :restart , :roles => :app do
  94. sudo "/etc/init.d/nginx restart"
  95. end
  96.  
  97. desc "Stop the Nginx processes on the app server."
  98. task :stop , :roles => :app do
  99. sudo "/etc/init.d/nginx stop"
  100. end
  101. end
  102.  
  103. # == BACKGROUNDRB ==============================================================
  104. namespace :drb do
  105. desc 'Start backgroundrb'
  106. task :start, :roles => :app do
  107. run "#{current_path}/script/backgroundrb start"
  108. end
  109.  
  110. desc 'Stop backgroundrb'
  111. task :stop, :roles => :app do
  112. run "#{current_path}/script/backgroundrb stop"
  113. end
  114.  
  115. desc 'Restart backgroundrb'
  116. task :restart, :roles => :app do
  117. stop
  118. start
  119. end
  120.  
  121. end
  122.  
  123. # == MONGREL ===================================================================
  124. namespace :deploy do
  125. desc "Start mongrel cluster"
  126. task :start, :roles => :app do
  127. run "cd #{current_path} && sudo mongrel_rails cluster::start"
  128. end
  129.  
  130. desc "Stop mongrel cluster"
  131. task :stop, :roles => :app do
  132. run "cd #{current_path} && sudo mongrel_rails cluster::stop"
  133. end
  134.  
  135. desc "Restart mongrel cluster"
  136. task :restart, :roles => :app do
  137. run "cd #{current_path} && sudo mongrel_rails cluster::restart"
  138. end
  139. end
  140.  
  141. # == TASKS =====================================================================
  142. after "deploy", "deploy:cleanup"
  143. after "deploy:migrations", "deploy:cleanup"
  144. after "deploy:setup", "init:config:database"
  145. after "deploy:setup", "init:config:mongrel"
  146. after "deploy:symlink", "init:config:localize"
  147.  
  148. task :after_update_code, :roles => :app do
  149. sudo "chown mongrel:mongrel #{release_path}/tmp -R"
  150. sudo "chown mongrel:mongrel #{release_path}/log -R"
  151. sudo "chown mongrel:mongrel #{shared_path}/pids -R"
  152. sudo "chmod 777 #{release_path}/public/javascripts"
  153. sudo "chmod 777 #{release_path}/public/stylesheets"
  154. sudo "chmod +x #{release_path}/script/backgroundrb"
  155. drb:restart
  156. end
Add Comment
Please, Sign In to add comment