harshancx

deployment script prod

Oct 18th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #!/usr/bin/bash
  2. #===========================================================================
  3. # Deployment Script for EDB Drupal Site
  4. # Usage: execute this script with elevated privileges
  5. # - e.g. 'sudo ./[this_script] [branch_to_deploy]'
  6. #===========================================================================
  7.  
  8. REPOSITORY_ROOT="/var/www/repo/enterprise-db"
  9. DRUPAL_ROOT="/var/www/html"
  10. DEPLOY_BRANCH="$1"
  11.  
  12. # Set default branch if not provided via command argument
  13. if [ "$DEPLOY_BRANCH" = "" ]; then
  14. set DEPLOY_BRANCH="production"
  15. fi
  16.  
  17. # Download latest code from specified branch in remote repository
  18. cd $REPOSITORY_ROOT
  19. git checkout $DEPLOY_BRANCH
  20. git pull origin $DEPLOY_BRANCH
  21.  
  22. # Enable Maintenance Mode
  23. cd $DRUPAL_ROOT
  24. drush vset maintenance_mode 1
  25.  
  26. # Sync downloaded repository files over to webroot
  27. rsync -avh "$REPOSITORY_ROOT/simplesamlphp/" /var/www/simplesamlphp/ --delete
  28. rsync -avh --exclude '.git' --exclude 'sites/default/files' --exclude 'sites/default/files-private' "$REPOSITORY_ROOT/docroot/" $DRUPAL_ROOT --delete
  29.  
  30. # Install environment-specific database settings
  31. cp -fv /var/www/repo/local.db.inc "$DRUPAL_ROOT/sites/default/local.db.inc"
  32.  
  33. # Remove one Simplesaml implementation and symlink to the other
  34. rm "$DRUPAL_ROOT/simplesaml"
  35. ln -s /var/www/simplesamlphp/www "$DRUPAL_ROOT/simplesaml"
  36.  
  37. # Lock down Drupal settings file and default site directory
  38. chmod 644 "$DRUPAL_ROOT/sites/default/settings.php"
  39. chmod 755 "$DRUPAL_ROOT/sites/default"
  40.  
  41. # Run Registry Rebuild in case our code update has created changes that might prevent
  42. # Drupal from being able to bootstrap. This will also flush site caches.
  43. drush rr
  44.  
  45. # After all files have been deployed and caches cleared, we set correct ownership and permissions
  46. # in various areas to ensure the system will function normally.
  47.  
  48. # Set default ownership for entire Drupal installation
  49. chown -R root:apache $DRUPAL_ROOT
  50.  
  51. # Set directory permissions for Drupal public and private file system
  52. find "$DRUPAL_ROOT/sites/default/files" -type d -exec chmod 775 {} +
  53. find "$DRUPAL_ROOT/sites/default/files-private" -type d -exec chmod 775 {} +
  54.  
  55. # Set file permissions for Drupal public and private file system
  56. find "$DRUPAL_ROOT/sites/default/files" -type f -exec chmod 664 {} +
  57. find "$DRUPAL_ROOT/sites/default/files-private" -type f -exec chmod 664 {} +
  58.  
  59. # Run any pending database updates
  60. drush updb -y
  61.  
  62. # Disable Maintenance Mode, only if the previous command was successful
  63. lastCode=$?
  64. if [[ $lastCode != 0 ]]; then
  65. echo "ERROR: Drush exited with code $lastCode"
  66. exit $lastCode
  67. fi
  68. drush vset maintenance_mode 0
Advertisement
Add Comment
Please, Sign In to add comment