diff --git a/README.md b/README.md index eadb4c7..d0c5617 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,26 @@ To do so, use: sudo bash /distillery/provision.sh SLUG ``` +## Rebuild an instance -- 'rebuild.sh' + +Sometimes it becomes necessary (because of changes to this project) to rebuild the docker image running a certain docker instance. +To do so, use: + + +```bash +sudo bash /distillery/rebuild.sh SLUG +``` + +Note that rebuilding an instance does restart the docker container resulting in a small (typical < 1 second) interruption to the website in question. +Furthermore, while the container recreated, the old image stays on the host. +To delete all instances, run: + +```bash +sudo docker image prune --all +``` + + + ## Purge an existing WissKI instance -- 'purge.sh' diff --git a/distillery/lib/40_templates.sh b/distillery/lib/40_templates.sh index be2a9fe..8ddb5df 100644 --- a/distillery/lib/40_templates.sh +++ b/distillery/lib/40_templates.sh @@ -41,7 +41,7 @@ function install_resource_dir() { for filename in "$from"/*; do dest="$to/`basename "${filename}"`" echo "Writing \"$dest\"" - cp -r "$filename" "$dest" + cp -rTv "$filename" "$dest" done } diff --git a/distillery/lib/50_utils.sh b/distillery/lib/50_utils.sh index 40793af..443235c 100644 --- a/distillery/lib/50_utils.sh +++ b/distillery/lib/50_utils.sh @@ -13,4 +13,12 @@ export DEBIAN_FRONTEND=noninteractive # This file just sets a few utility functions to be used by the code. # randompw generates a random password as per the configuration file. -alias randompw="cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $PASSWORD_LENGTH | head -n 1" \ No newline at end of file +alias randompw="cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $PASSWORD_LENGTH | head -n 1" + +# update_stack fully updates a docker-compose stack in the given location. +function update_stack() { + cd "$1" + docker-compose pull + docker-compose build --pull + docker-compose up -d +} \ No newline at end of file diff --git a/distillery/rebuild.sh b/distillery/rebuild.sh new file mode 100644 index 0000000..8299a78 --- /dev/null +++ b/distillery/rebuild.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +# read the lib/shared.sh and read the slug argument. +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$DIR" +source "$DIR/lib/lib.sh" +require_slug_argument + + +# if the site doesn't exist, I can't open a shell. +if ! sql_bookkeep_exists "$SLUG"; then + log_error "=> Site '$SLUG' does not exist in bookeeping table. " + echo "I can't rebuild it. " + exit 1 +fi; + +# Read everything from the database +read -r INSTANCE_BASE_DIR MYSQL_DATABASE MYSQL_USER GRAPHDB_REPO GRAPHDB_USER <<< "$(sql_bookkeep_load "${SLUG}" "filesystem_base,sql_database,sql_user,graphdb_repository,graphdb_user" | tail -n +2)" + +log_info " => Updating compose files" +install_resource_dir "compose/runtime" "$INSTANCE_BASE_DIR" + +log_info "=> Rebuilding and restarting '$INSTANCE_BASE_DIR'" +update_stack "$INSTANCE_BASE_DIR" \ No newline at end of file diff --git a/distillery/shell.sh b/distillery/shell.sh index 8cec13a..6ce8c7a 100644 --- a/distillery/shell.sh +++ b/distillery/shell.sh @@ -6,8 +6,9 @@ DISABLE_LOG=1 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd "$DIR" source "$DIR/lib/lib.sh" -require_slug_argument DISABLE_LOG=0 +require_slug_argument + # if the site doesn't exist, I can't open a shell. if ! sql_bookkeep_exists "$SLUG"; then diff --git a/distillery/system_update.sh b/distillery/system_update.sh index cdf24cd..920b701 100755 --- a/distillery/system_update.sh +++ b/distillery/system_update.sh @@ -6,14 +6,6 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd "$DIR" source "$DIR/lib/lib.sh" -# update_stack fully updates a docker-compose stack in the given location. -function update_stack() { - cd "$1" - docker-compose pull - docker-compose build --pull - docker-compose up -d -} - log_info "=> Rebuilding and restarting 'web' stack" update_stack "$DEPLOY_WEB_DIR"