diff options
author | Mark Longair <mhl@pobox.com> | 2014-01-10 17:47:26 +0000 |
---|---|---|
committer | Mark Longair <mhl@pobox.com> | 2014-01-22 15:27:41 +0000 |
commit | 0b34cb567620874984974e639552d5dd49836f03 (patch) | |
tree | 73ce7306ae0948cd0bf2ab356647d5357fb93c0c /script/rails-deploy-before-down | |
parent | 58aa2bf89d0a3839bdfc13529f4c0fdac6a24132 (diff) |
Add the SHARED_FILES_PATH, SHARED_FILES & SHARED_DIRECTORIES options
This is to support sharing various files between multiple deployments
of Alaveteli. If you have set SHARED_FILES_PATH, SHARED_FILES and
SHARED_DIRECTORIES then the rails-deploy-before-down script will ensure
that a symlink is created from each of the files or directories
mentioned in SHARED_FILES and SHARED_DIRECTORIES to a corresponding
path within SHARED_FILES_PATH.
Diffstat (limited to 'script/rails-deploy-before-down')
-rwxr-xr-x | script/rails-deploy-before-down | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/script/rails-deploy-before-down b/script/rails-deploy-before-down index ecbf2a7f7..ad1049e44 100755 --- a/script/rails-deploy-before-down +++ b/script/rails-deploy-before-down @@ -57,6 +57,53 @@ cd log touch development.log fastcgi.crash.log production.log test.log cd .. +# Returns 0 if an element is present in a bash array, and 1 otherwise +# Taken from: http://stackoverflow.com/a/8574392/223092 +contains () { + local E + for E in "${@:2}" + do + [ "$E" == "$1" ] && return 0 + done + return 1 +} + +if [ x"$OPTION_SHARED_FILES_PATH" != x ] +then + for F in "${OPTION_SHARED_FILES[@]}" "${OPTION_SHARED_DIRECTORIES[@]}" + do + # Remove any trailing slash from directories: + NORMALIZED_F="${F%/}" + RELATIVE_DIRECTORY="$(dirname $NORMALIZED_F)" + DESTINATION="$OPTION_SHARED_FILES_PATH/$NORMALIZED_F" + # Ensure that the directory in the shared path exists: + mkdir -p "$OPTION_SHARED_FILES_PATH/$RELATIVE_DIRECTORY" + # If it's a directory, and it doesn't exist, make sure that + # it's created: + if contains "$F" "${OPTION_SHARED_DIRECTORIES[@]}" + then + if [ ! -d "$DESTINATION" ] + then + mkdir -p "$DESTINATION" + fi + fi + # Make sure we won't overwrite a file because it hasn't been + # moved to the shared directory yet: + if [ -e "$NORMALIZED_F" ] && [ ! -L "$NORMALIZED_F" ] + then + cat <<EOF +$F is a real file or directory, but is listed in SHARED_FILES or +SHARED_DIRECTORIES and SHARED_FILES_PATH is set. $F should have +been moved to $OPTION_SHARED_FILES_PATH/$F - for mySociety +deployments you can use script/mysociety-switch-to-shared to automate +this. +EOF + exit 1 + fi + ln -snf "$DESTINATION" "$NORMALIZED_F" + done +fi + # Force appropriate environment in production if [ "$OPTION_STAGING_SITE" = "0" ] then |