Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # config
- gitBranch=${1:-master}
- gitUsername=username
- gitPassword=password
- gitUrl=https://${gitUsername}:${gitPassword}@neptune.inrecolan.com:443/Git/FamilyClub.git
- projectDir=/home/idiberi/familyclub
- timestamp=$(date +%s)
- gitDir=${projectDir}/bare.git
- projectCurrentLink=${projectDir}/current
- projectReleaseDir=${projectDir}/releases/${timestamp}
- # MYSQL BACKUP START
- mysqlUsername=username
- mysqlPassword=password
- mysqlDb=family_club
- mysqlBackupDir=${projectDir}/backup
- mysqlBackupName=${timestamp}.sql
- echo "> MySQL backup..."
- mkdir -p ${mysqlBackupDir}
- mysqldump -u${mysqlUsername} -p${mysqlPassword} ${mysqlDb} > ${mysqlBackupDir}/${mysqlBackupName}
- # MYSQL BACKUP END
- # START GIT
- echo "> Updating git bare repository from branch '${gitBranch}'..."
- echo "> Remove previous git repository..."
- rm -rf ${gitDir}
- echo "> Clone..."
- git clone --depth=1 --bare -b ${gitBranch} ${gitUrl} ${gitDir} || { echo "> Git clone failed!"; exit 1; }
- gitCurrentBranch=`git --git-dir=${gitDir} rev-parse --abbrev-ref HEAD`
- gitCurrentCommit=`git --git-dir=${gitDir} rev-parse --verify HEAD`
- echo "> Creating working copy..."
- mkdir -p ${projectReleaseDir}
- git --work-tree=${projectReleaseDir} --git-dir=${gitDir} checkout -f HEAD -- family-club
- # FIXME оставляем только содержимое family-club
- shopt -s dotglob nullglob
- mv ${projectReleaseDir}/family-club/* ${projectReleaseDir}
- rm -r ${projectReleaseDir}/family-club
- # END GIT
- echo "> Define a version"
- echo "${gitCurrentBranch}\n${gitCurrentCommit}\n${timestamp}" > ${projectReleaseDir}/version
- echo "> Composer install"
- cd ${projectReleaseDir} && composer install --no-dev --prefer-dist -o || { echo "> Composer failed!"; exit 1; }
- echo "> Bower install"
- cd ${projectReleaseDir} && bower install --allow-root -p || { echo "> Bower failed! (try: bower cache clean)"; exit 1; }
- echo "> Make symlink"
- ln -nsf ${projectReleaseDir} ${projectCurrentLink}
- echo "> Restart supervisord"
- { cd ${HOME}/supervisord && ./stop && sleep 10 && ./start; } || { echo "> Failed restart supervisord."; exit 1; }
- echo "> Clear redis cache"
- redis-cli -s /tmp/redis.sock flushall || { echo "> Failed clear cache."; exit 1; }
- echo "> Restart php-fpm. In several seconds website will unavailable."
- { cd ${HOME}/php-fpm && ./stop && ./start; } || { echo "> Failed restart php-fpm."; exit 1; }
- echo "+---------------------------------------+"
- echo "| The king is dead, long live the king! |"
- echo "+---------------------------------------+"
- echo "> Check if any migrations pending!"
- echo "> Cmd: $ php -c ~/php-fpm ~/familyclub/current/app/console migration:list"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement