-
-
Save Seldaek/1818768 to your computer and use it in GitHub Desktop.
#!/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" |
Nope, this works just fine for most intents and purposes and I like to keep tight control over it. Maybe one day I'll see the light. Puppet is great though for server setup.
Okay, I usually find easier to just have symbolic link for the current directory. So the datetime you have in it is when you deployed it instead of when you deployed the next version. It's a matter a taste mostly. Thanks for sharing!
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.
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.
No fabric?