diff options
-rw-r--r-- | config/general.yml-example | 28 | ||||
-rwxr-xr-x | script/rails-deploy-before-down | 47 |
2 files changed, 75 insertions, 0 deletions
diff --git a/config/general.yml-example b/config/general.yml-example index b8d9fc854..bd835494b 100644 --- a/config/general.yml-example +++ b/config/general.yml-example @@ -214,3 +214,31 @@ USE_MAILCATCHER_IN_DEVELOPMENT: true # only have an effect in environments where # config.action_controller.perform_caching is set to true CACHE_FRAGMENTS: true + +# In some deployments of Alaveteli you may wish to install each newly +# deployed version alongside the previous ones, in which case certain +# files and resources should be shared between these installations: +# for example, the 'files' directory, the 'cache' directory and the +# generated graphs such as 'public/foi-live-creation.png'. If you're +# installing Alaveteli in such a setup then set SHARED_FILES_PATH to +# the directory you're keeping these files under. Otherwise, leave it +# blank. +SHARED_FILES_PATH: '' + +# If you have SHARED_FILES_PATH set, then these options list the files +# and directories that are shared; i.e. those that the deploy scripts +# should create symlinks to from the repository. +SHARED_FILES: + - config/database.yml + - config/general.yml + - config/rails_env.rb + - config/newrelic.yml + - config/httpd.conf + - public/foi-live-creation.png + - public/foi-user-use.png + - config/aliases +SHARED_DIRECTORIES: + - files/ + - cache/ + - lib/acts_as_xapian/xapiandbs/ + - vendor/bundle 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 |