Skip to content

Instantly share code, notes, and snippets.

@Seldaek
Created February 13, 2012 18:15
Show Gist options
  • Save Seldaek/1818768 to your computer and use it in GitHub Desktop.
Save Seldaek/1818768 to your computer and use it in GitHub Desktop.
Deployment script
#!/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"
@Seldaek
Copy link
Author

Seldaek commented Mar 20, 2012

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