daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Script variables
  4. SF2_ENVIRONMENT=prod
  5. REPOSITORY=
  6. DEPLOY_BASE_DIR=/var/www
  7. DEPLOY_DIR=$DEPLOY_BASE_DIR/`date +%s`
  8. USAGE="Usage: $0 install|update [git_repository_url]"
  9.  
  10. # Commands
  11. MKDIR=/bin/mkdir
  12. GIT=/usr/bin/git
  13. PHP=/usr/bin/php
  14. CP=/bin/cp
  15. RM=/bin/rm
  16. CHMOD=/bin/chmod
  17. LN=/bin/ln
  18. SERVICE=/sbin/service
  19.  
  20. if [ $# -lt 1 ]; then
  21.     echo -e $USAGE;
  22.     exit;
  23. fi
  24.  
  25. if [ $# -eq 2 ]; then
  26.     REPOSITORY=$2
  27. elif [ -z $REPOSITORY ]; then
  28.     echo -e 'No git repository specified!\nEither set the REPOSITORY variable in this script, or specify the git repository url argument';
  29.     exit;
  30. fi
  31.  
  32. if [ $1 == "install" ]; then
  33.     echo 'Fetching the latest code...';
  34.     $MKDIR $DEPLOY_DIR
  35.     $GIT clone $REPOSITORY $DEPLOY_DIR/
  36.     $PHP $DEPLOY_DIR/bin/vendors install
  37. elif [ $1 == "update" ]; then
  38.     echo 'Fetching the latest code...';
  39.     if [ ! -d $DEPLOY_BASE_DIR/current ]; then
  40.         echo "$DEPLOY_BASE_DIR/current does not exist. Maybe you need to run install first?"
  41.         exit;
  42.     fi
  43.     $CP -LR $DEPLOY_BASE_DIR/current $DEPLOY_DIR  
  44.     cd $DEPLOY_DIR;
  45.     $GIT pull origin master
  46.     $GIT reset --hard HEAD
  47. else
  48.     echo -e $USAGE;
  49.     exit;
  50. fi
  51.  
  52. # Set app/cache permissions
  53. if [ -d $DEPLOY_DIR/app/cache ]; then
  54.     $CHMOD -R 777 $DEPLOY_DIR/app/cache
  55. fi
  56.  
  57. # Clear and warmup the symfony2 cache
  58. if [ -f $DEPLOY_DIR/app/console ]; then
  59.     $RM -rf $DEPLOY_DIR/app/cache/$SF2_ENVIRONMENT
  60.     $PHP $DEPLOY_DIR/app/console --env=$SF2_ENVIRONMENT cache:warmup
  61. fi
  62.  
  63. # Set app/cache permissions again
  64. if [ -d $DEPLOY_DIR/app/cache ]; then
  65.     $CHMOD -R 777 $DEPLOY_DIR/app/cache
  66. fi
  67.  
  68. # Set app/logs permissions
  69. if [ -d $DEPLOY_DIR/app/logs ];
  70. then
  71.     $CHMOD -R 777 $DEPLOY_DIR/app/logs
  72. fi
  73.  
  74. # Install and symlink assets
  75. if [ -f $DEPLOY_DIR/app/console ]; then
  76.     $PHP $DEPLOY_DIR/app/console --env=$SF2_ENVIRONMENT assets:install --symlink $DEPLOY_DIR/web
  77. fi
  78.  
  79. # Update current symlink
  80. if [ -L $DEPLOY_BASE_DIR/current ] || [ -e $DEPLOY_BASE_DIR/current ]; then
  81.     $RM $DEPLOY_BASE_DIR/current
  82. fi
  83. $LN -s $DEPLOY_DIR $DEPLOY_BASE_DIR/current
  84.  
  85. # Restart php-fpm to clear the APC caches
  86. $SERVICE php-fpm restart
  87.  
  88. echo 'Deployment complete.';
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top