Guest User

Untitled

a guest
Oct 7th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. # Deploy an example Drupal site.
  2. # TODO Move this to a definition with parameters.
  3. require_recipe "mysql"
  4. require_recipe "drush"
  5. require_recipe "drush_make"
  6.  
  7. docroot = "#{node[:www_root]}/drupal/www"
  8.  
  9. cookbook_file "#{node[:www_root]}/drupal/drupal.make" do
  10. source node[:drupal][:makefile]
  11. #notifies :restart, resources("service[apache2]"), :delayed
  12. end
  13.  
  14. # Download and install a fresh drupal.
  15. # We only do this if there's not alreayd a Drupal installation
  16. # here.
  17. bash "run-drush-make" do
  18. code "drush make #{node[:www_root]}/drupal/drupal.make #{node[:www_root]}/drupal/fresh"
  19. not_if { File.exists? "#{docroot}/index.php" }
  20. end
  21.  
  22. # Since Drush insists upon creating its own directory, yet we need to
  23. # create the directories ahead of time for Apache, we have to perform
  24. # monumental acts of stupidity like this.
  25. bash "relocate-dmake-files" do
  26. code "mv #{node[:www_root]}/drupal/fresh/* #{docroot}"
  27. #code "mv #{node[:www_root]}/drupal/fresh/* #{docroot} && mv #{node[:www_root]}/drupal/fresh/.* #{docroot}"
  28. not_if { File.exists? "#{docroot}/index.php" }
  29. end
  30. bash "kill-old-dmake" do
  31. code "rm -rf #{node[:www_root]}/drupal/fresh"
  32. end
  33.  
  34. # For each site:
  35. # - create a site-specific database.
  36. # - create a site-specific directory.
  37. # - create a default settings file.
  38. node[:hosts][:localhost_aliases].each do |a|
  39. db_name = a.gsub('.','_')
  40. execute "create-#{db_name}" do
  41. command "/usr/bin/mysql -u root -p#{node[:mysql][:server_root_password]} -e \"" +
  42. "CREATE DATABASE IF NOT EXISTS #{db_name};\""
  43. action :run
  44. ignore_failure true
  45. end
  46.  
  47. # Create the site directory.
  48. directory "#{docroot}/sites/#{a}" do
  49. action :create
  50. recursive true
  51. end
  52.  
  53. # Create the files directory and set perms to 777.
  54. # This is outside of the docroot because of issues
  55. # setting directories on the host OS to 0777.
  56. # directory "#{docroot}/sites/#{a}/files" do
  57. directory "/var/www/#{a}/files" do
  58. action :create
  59. owner 'www-data'
  60. mode 0777
  61. recursive true
  62. end
  63.  
  64. # Create a symbolic link to the file.
  65. #link "#{docroot}/sites/#{a}/files" do
  66. # to "/var/www/#{a}/files"
  67. #end
  68.  
  69. # cookbook_file "#{docroot}/sites/#{a}/settings.php" do
  70. # mode 0777
  71. # source "settings.php"
  72. # end
  73.  
  74. template "#{docroot}/sites/#{a}/settings.php" do
  75. source "settings-multisite.php.erb"
  76. mode 0777
  77. #not_if { File.exists? "#{docroot}/sites/#{a}/settings.php" }
  78. variables(:db_name => db_name, :db_user => 'root', :db_pass => node[:mysql][:server_root_password])
  79. end
  80. end
Add Comment
Please, Sign In to add comment