-
-
Save makasim/2133875 to your computer and use it in GitHub Desktop.
Deployment script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
targetUser="seld" | |
targetHost="seld.be" | |
parentDir="/home/seld" | |
childDir="packagist.org" | |
port="22" | |
configFile="~/etc/conf/$childDir" | |
target="$targetUser@$targetHost" | |
targetDir="$parentDir/$childDir" | |
if [ "$1" == "--rollback" ] | |
then | |
echo "> Rolling back to the previous version" | |
ssh -p $port $target " | |
DIRS=(\`ls $parentDir | grep $childDir-[0-9] | sort -r\`); | |
if [ \"\${DIRS[0]}\" = \"\" ]; then echo \"! No rollback dir available\"; exit; fi | |
mv $targetDir $targetDir-tmp | |
mv $parentDir/\${DIRS[0]} $targetDir | |
chmod -R +w $targetDir-tmp 2>/dev/null; | |
rm -rf $targetDir-tmp; | |
echo \"> Rollback complete (\${DIRS[0]} restored)\"" | |
exit | |
fi | |
echo "> Deploying" | |
sourceDir="./" | |
echo "> Preparing remote copy" | |
ssh $target " | |
chmod -R +w $targetDir-new 2>/dev/null; | |
rm -rf $targetDir-new; | |
cp -r $targetDir $targetDir-new; | |
chown -hR $targetUser:$targetUser $targetDir-new" | |
# rsyncing | |
echo "> Sending files to the server" | |
rsync --rsh="ssh -p $port" -rhz --executability --del --force --exclude="app/cache/*" \ | |
--exclude="app/logs/*" \ | |
--exclude="app/java/apache-solr*" \ | |
--exclude=".svn" \ | |
--exclude=".git" \ | |
--exclude="app/config/parameters.yml" \ | |
--chmod="Da=rx,a=r" \ | |
$sourceDir $target:$targetDir-new | |
echo "> Swapping old files with the new ones" | |
ssh -p $port $target " | |
chown -hR $targetUser:$targetUser $targetDir-new; | |
rm -rf $targetDir-new/app/cache/* | |
rm -rf $targetDir-new/app/logs/* | |
mkdir -p $targetDir-new/app/cache | |
mkdir -p $targetDir-new/app/logs | |
chmod -R ug+rwx $targetDir-new/app/cache | |
chmod -R ug+rwx $targetDir-new/app/logs | |
chmod -R u+w $targetDir-new/app/config | |
cp $configFile $targetDir-new/app/config/parameters.yml | |
chmod -R u-w $targetDir-new/app/config | |
chmod a+x $targetDir-new/app/console | |
mv $targetDir $targetDir-`date -u +%Y%m%d-%H%M%S` | |
mv $targetDir-new $targetDir" | |
echo "> Deployment complete, run ./deploy --rollback if everything is broken" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment