Guest User

Untitled

a guest
May 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. set :domain, Capistrano::CLI.ui.ask("From which address should I pull the git repository? (192.168.x.x): ")
  2. set :application, "bart"
  3. set :keep_releases, 2
  4. set :repository, "git://#{domain}/#{application}.git"
  5. set :scm, :git
  6. set :deploy_via, :remote_cache
  7. set :deploy_to, "/var/www/#{application}"
  8. set :user, "deploy"
  9. set :runner, "mongrel"
  10. set :use_sudo, :false
  11.  
  12. set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
  13.  
  14. role :app, "#{domain}"
  15. role :web, "#{domain}"
  16. role :db, "#{domain}", :primary => true
  17.  
  18. # == CONFIG ====================================================================
  19. namespace :init do
  20. namespace :config do
  21. desc "Create database.yml"
  22. task :database do
  23. set :db_user, Capistrano::CLI.ui.ask("database user: ")
  24. set :db_pass, Capistrano::CLI.password_prompt("database password: ")
  25. database_configuration =<<-EOF
  26. ---
  27. login: &login
  28. adapter: mysql
  29. database: #{application}
  30. host: localhost
  31. username: #{db_user}
  32. password: #{db_pass}
  33.  
  34. production:
  35. <<: *login
  36.  
  37. EOF
  38. run "mkdir -p #{shared_path}/config"
  39. put database_configuration, "#{shared_path}/config/database.yml"
  40. end
  41.  
  42. desc "Create mongrel_cluster.yml"
  43. task :mongrel do
  44. mongrel_cluster_configuration = <<-EOF
  45. ---
  46. user: mongrel
  47. cwd: #{current_path}
  48. log_file: #{current_path}/log/mongrel.log
  49. port: "8000"
  50. environment: production
  51. group: mongrel
  52. address: 127.0.0.1
  53. pid_file: #{current_path}/tmp/pids/mongrel.pid
  54. servers: 3
  55. EOF
  56. run "mkdir -p #{shared_path}/config"
  57. put mongrel_cluster_configuration, "#{shared_path}/config/mongrel_cluster.yml"
  58. end
  59.  
  60. desc "Symlink shared configurations to current"
  61. task :localize, :roles => [:app] do
  62. %w[mongrel_cluster.yml database.yml].each do |f|
  63. run "ln -nsf #{shared_path}/config/#{f} #{current_path}/config/#{f}"
  64. end
  65. end
  66. end
  67. end
  68.  
  69.  
  70. # == NGINX =====================================================================
  71. namespace :nginx do
  72. desc "Start Nginx on the app server."
  73. task :start, :roles => :app do
  74. sudo "/etc/init.d/nginx start"
  75. end
  76.  
  77. desc "Restart the Nginx processes on the app server by starting and stopping the cluster."
  78. task :restart , :roles => :app do
  79. sudo "/etc/init.d/nginx restart"
  80. end
  81.  
  82. desc "Stop the Nginx processes on the app server."
  83. task :stop , :roles => :app do
  84. sudo "/etc/init.d/nginx stop"
  85. end
  86. end
  87.  
  88. # == DATABASE ==================================================================
  89. namespace :db do
  90. desc "Backup your Database to #{shared_path}/db_backups"
  91. task :backup, :roles => :db, :only => {:primary => true} do
  92. set :db_user, Capistrano::CLI.ui.ask("Database user: ")
  93. set :db_pass, Capistrano::CLI.password_prompt("Database password: ")
  94. now = Time.now
  95. run "mkdir -p #{shared_path}/backup"
  96. backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-')
  97. set :backup_file, "#{shared_path}/backup/#{application}-snapshot-#{backup_time}.sql"
  98. run "mysqldump --add-drop-table -u #{db_user} -p #{db_pass} #{application} --opt | bzip2 -c > #{backup_file}.bz2"
  99. end
  100. end
  101.  
  102. # == MONGREL ===================================================================
  103. namespace :deploy do
  104. desc "Start mongrel cluster"
  105. task :start do
  106. run "cd #{current_path} && sudo mongrel_rails cluster::start"
  107. end
  108.  
  109. desc "Stop mongrel cluster"
  110. task :stop do
  111. run "cd #{current_path} && sudo mongrel_rails cluster::stop"
  112. end
  113.  
  114. desc "Restart mongrel cluster"
  115. task :restart do
  116. run "cd #{current_path} && sudo mongrel_rails cluster::restart"
  117. end
  118. end
  119.  
  120. # == TASKS =====================================================================
  121. before "deploy:migrate", "db:backup"
  122.  
  123. after "deploy", "deploy:cleanup"
  124. after "deploy:migrations", "deploy:cleanup"
  125. after "deploy:setup", "init:config:database"
  126. after "deploy:setup", "init:config:mongrel"
  127. after "deploy:symlink", "init:config:localize"
  128.  
  129. task :after_update_code do
  130. sudo "chown mongrel:mongrel #{release_path}/tmp -R"
  131. sudo "chown mongrel:mongrel #{release_path}/log -R"
  132. sudo "chown mongrel:mongrel #{shared_path}/pids -R"
  133. end
Add Comment
Please, Sign In to add comment