From b8e139c255bfc0adc4a08e0c82d61d7b6da054e9 Mon Sep 17 00:00:00 2001 From: Klas Meder Boqvist Date: Tue, 23 Oct 2012 00:27:25 +0200 Subject: [PATCH 1/5] Better handling of replacement of production symlink --- deploy.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deploy.sh b/deploy.sh index 4824d0b..ab3afce 100755 --- a/deploy.sh +++ b/deploy.sh @@ -149,13 +149,13 @@ function symlink_update() { local src=$1 local dst=$2 - # remove old symlink if [[ -L $dst ]]; then - rm $dst || die "Unable to delete production symlink" + # create new symlink + ln -s $src ${dst}_tmp || die "Unable to create new symlink" + + # replace old symlink + mv -Tf ${dst}_tmp $dst || die "Unable to replace production symlink" fi - - # create new symlink - ln -s $src $dst || die "Unable to create production symlink" } symlink_post_hook(){ From 00e6648f536f65b18e6586602fc2f5806873b21d Mon Sep 17 00:00:00 2001 From: Klas Meder Boqvist Date: Tue, 23 Oct 2012 00:28:28 +0200 Subject: [PATCH 2/5] Removed unnecessary code and moved ^C trap earlier --- deploy.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/deploy.sh b/deploy.sh index ab3afce..9ddee41 100755 --- a/deploy.sh +++ b/deploy.sh @@ -184,7 +184,6 @@ do_prune(){ # Called when script finishes or if user aborts cleanup(){ rm -f $LOCK_FILE || die - popd > /dev/null } handle_sigint(){ @@ -195,6 +194,9 @@ handle_sigint(){ ############## END FUNCTIONS ####################3 +# Catch ctrl-c +trap handle_sigint SIGINT + if [ $# -gt 1 ]; then echo "Bad usage" exit 48 @@ -224,11 +226,6 @@ fi # fix relative paths DIR=$(readlink -f $(dirname "${SETTINGS_FILE}")) echo "${infostar} Working directory: ${DIR}" -pushd ${DIR} > /dev/null - -# Catch ctrl-c -# This should be done after pushd since it calls popd to restore cwd -trap handle_sigint SIGINT # Create release name releasename="${releaseprefix:-release}-`date +%Y%m%d%H%M%S`" From 34c8919814f3a168ab7bd0f5c68b81e8d934e245 Mon Sep 17 00:00:00 2001 From: Klas Meder Boqvist Date: Tue, 23 Oct 2012 00:29:21 +0200 Subject: [PATCH 3/5] Performance tuning --- deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index 9ddee41..96da8f4 100755 --- a/deploy.sh +++ b/deploy.sh @@ -312,10 +312,10 @@ echo " rm $LOCK_FILE" echo "*********************************" echo answer="fail" -until [ "$answer" == "yes" ]; do +until [[ "$answer" = "yes" ]]; do echo -n "${bold}Do you wish to continue?${normal} [${green}yes${normal}/${red}no${normal}] " read answer - if [ "$answer" == "no" ]; then + if [[ "$answer" = "no" ]]; then echo "Aborting." exit 45 fi From 0aeac80b6eeedf3d95c5c9ff38ed2e7be2ef6d7e Mon Sep 17 00:00:00 2001 From: Klas Meder Boqvist Date: Tue, 23 Oct 2012 00:30:06 +0200 Subject: [PATCH 4/5] Changed to best practice in settings-example --- deploy_settings_example.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/deploy_settings_example.sh b/deploy_settings_example.sh index 1227fa0..67b307d 100644 --- a/deploy_settings_example.sh +++ b/deploy_settings_example.sh @@ -6,7 +6,7 @@ VCS="git" # All relative paths are relative to the directory this configuration exists in. # A lock file is used to ensure multiple deploys aren't run at the same time. -# LOCK_FILE=deploy.lock +#LOCK_FILE=deploy.lock # Path to an existing working copy (user must checkout/clone the repository # before the first deploy, the deploy script only updates/pulls new revisions) @@ -19,18 +19,18 @@ EXPORT_TARGET=/var/www/site/releases SYMLINK_PATH=/var/www/site/example.com # How many old releases to retain. -# RELEASE_COUNT=8 +#RELEASE_COUNT=8 # File patterns to remove from the export. If you create a custom # `export_post_hook` you must manually call `file_prune` if you need this # feature. -# PRUNE=(o -# ".*\.xcf" -# ) +#PRUNE=(o +# ".*\.xcf" +#) # Sample hook -# update_post_hook(){ -# echo "in overloaded post update hook" -# } +#update_post_hook(){ +# echo "in overloaded post update hook" +#} SETTINGS_FILE_OK=1 From 3859b6cb90197db3f7bb0839f17370a2069d2edb Mon Sep 17 00:00:00 2001 From: Klas Meder Boqvist Date: Tue, 23 Oct 2012 01:36:49 +0200 Subject: [PATCH 5/5] Fixed WorkingDir-bug (I just introduced) --- deploy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy.sh b/deploy.sh index 96da8f4..e06b707 100755 --- a/deploy.sh +++ b/deploy.sh @@ -226,6 +226,7 @@ fi # fix relative paths DIR=$(readlink -f $(dirname "${SETTINGS_FILE}")) echo "${infostar} Working directory: ${DIR}" +cd ${DIR} # Create release name releasename="${releaseprefix:-release}-`date +%Y%m%d%H%M%S`"