Created
February 13, 2012 18:15
-
-
Save Seldaek/1818768 to your computer and use it in GitHub Desktop.
Deployment script
This file contains 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.yml" | |
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; | |
if [ ! -d $targetDir ] | |
then | |
mkdir $targetDir | |
mkdir $targetDir-new | |
fi | |
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,Fa=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/server.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" |
Eh well, looking at fabric in more details I guess it might be good after all. I will give it a shot. I discarded it as a capistrano-like solution but it seems much less magic and more explicit, which sounds great.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah agreed that's not super nice, but it wouldn't be too hard to change this. I just wanted to avoid symlinks complexity - trashing foo- dirs can be done safely with the current scheme.