Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # config
  4. gitBranch=${1:-master}
  5. gitUsername=username
  6. gitPassword=password
  7. gitUrl=https://${gitUsername}:${gitPassword}@neptune.inrecolan.com:443/Git/FamilyClub.git
  8. projectDir=/home/idiberi/familyclub
  9.  
  10. timestamp=$(date +%s)
  11. gitDir=${projectDir}/bare.git
  12. projectCurrentLink=${projectDir}/current
  13. projectReleaseDir=${projectDir}/releases/${timestamp}
  14.  
  15.  
  16.  
  17. # MYSQL BACKUP START
  18. mysqlUsername=username
  19. mysqlPassword=password
  20. mysqlDb=family_club
  21. mysqlBackupDir=${projectDir}/backup
  22. mysqlBackupName=${timestamp}.sql
  23.  
  24. echo "> MySQL backup..."
  25. mkdir -p ${mysqlBackupDir}
  26. mysqldump -u${mysqlUsername} -p${mysqlPassword} ${mysqlDb} > ${mysqlBackupDir}/${mysqlBackupName}
  27. # MYSQL BACKUP END
  28.  
  29.  
  30.  
  31. # START GIT
  32. echo "> Updating git bare repository from branch '${gitBranch}'..."
  33. echo "> Remove previous git repository..."
  34. rm -rf ${gitDir}
  35. echo "> Clone..."
  36. git clone --depth=1 --bare -b ${gitBranch} ${gitUrl} ${gitDir} || { echo "> Git clone failed!"; exit 1; }
  37.  
  38. gitCurrentBranch=`git --git-dir=${gitDir} rev-parse --abbrev-ref HEAD`
  39. gitCurrentCommit=`git --git-dir=${gitDir} rev-parse --verify HEAD`
  40.  
  41. echo "> Creating working copy..."
  42. mkdir -p ${projectReleaseDir}
  43. git --work-tree=${projectReleaseDir} --git-dir=${gitDir} checkout -f HEAD -- family-club
  44.  
  45. # FIXME оставляем только содержимое family-club
  46. shopt -s dotglob nullglob
  47. mv ${projectReleaseDir}/family-club/* ${projectReleaseDir}
  48. rm -r ${projectReleaseDir}/family-club
  49. # END GIT
  50.  
  51.  
  52.  
  53. echo "> Define a version"
  54. echo "${gitCurrentBranch}\n${gitCurrentCommit}\n${timestamp}" > ${projectReleaseDir}/version
  55.  
  56. echo "> Composer install"
  57. cd ${projectReleaseDir} && composer install --no-dev --prefer-dist -o || { echo "> Composer failed!"; exit 1; }
  58.  
  59. echo "> Bower install"
  60. cd ${projectReleaseDir} && bower install --allow-root -p || { echo "> Bower failed! (try: bower cache clean)"; exit 1; }
  61.  
  62. echo "> Make symlink"
  63. ln -nsf ${projectReleaseDir} ${projectCurrentLink}
  64.  
  65. echo "> Restart supervisord"
  66. { cd ${HOME}/supervisord && ./stop && sleep 10 && ./start; } || { echo "> Failed restart supervisord."; exit 1; }
  67.  
  68. echo "> Clear redis cache"
  69. redis-cli -s /tmp/redis.sock flushall || { echo "> Failed clear cache."; exit 1; }
  70.  
  71. echo "> Restart php-fpm. In several seconds website will unavailable."
  72. { cd ${HOME}/php-fpm && ./stop && ./start; } || { echo "> Failed restart php-fpm."; exit 1; }
  73.  
  74. echo "+---------------------------------------+"
  75. echo "| The king is dead, long live the king! |"
  76. echo "+---------------------------------------+"
  77.  
  78. echo "> Check if any migrations pending!"
  79. echo "> Cmd: $ php -c ~/php-fpm ~/familyclub/current/app/console migration:list"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement