From 60a18a88c7b22333faae14e4e1541d96a7c1e6b8 Mon Sep 17 00:00:00 2001 From: mhmdksh Date: Thu, 22 Dec 2022 10:11:44 +0000 Subject: [PATCH] Added docker-compose installation script and modified scripts --- restart.sh | 3 -- .../database-backup.sh | 0 .../database-restore.sh | 6 ++-- scripts/docker-compose-latest.sh | 10 +++++++ scripts/readme.md | 28 +++++++++++++++++++ reset.sh => scripts/reset.sh | 2 +- scripts/restart.sh | 3 ++ setup.sh => scripts/setup.sh | 0 scripts/start.sh | 2 ++ scripts/upgrade.sh | 5 ++++ start.sh | 2 -- upgrade.sh | 5 ---- 12 files changed, 52 insertions(+), 14 deletions(-) delete mode 100644 restart.sh rename database-backup.sh => scripts/database-backup.sh (100%) rename database-restore.sh => scripts/database-restore.sh (72%) create mode 100644 scripts/docker-compose-latest.sh create mode 100644 scripts/readme.md rename reset.sh => scripts/reset.sh (86%) create mode 100644 scripts/restart.sh rename setup.sh => scripts/setup.sh (100%) create mode 100644 scripts/start.sh create mode 100644 scripts/upgrade.sh delete mode 100644 start.sh delete mode 100644 upgrade.sh diff --git a/restart.sh b/restart.sh deleted file mode 100644 index 3c3b8937c..000000000 --- a/restart.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -docker compose -f ./docker-compose.production.yml down -docker compose -f ./docker-compose.production.yml up \ No newline at end of file diff --git a/database-backup.sh b/scripts/database-backup.sh similarity index 100% rename from database-backup.sh rename to scripts/database-backup.sh diff --git a/database-restore.sh b/scripts/database-restore.sh similarity index 72% rename from database-restore.sh rename to scripts/database-restore.sh index b23132830..24fab095a 100644 --- a/database-restore.sh +++ b/scripts/database-restore.sh @@ -4,8 +4,8 @@ if ! test -f "$1" ; then echo "Usage: database-restore.sh filename\n" fi export $(grep -v '^#' .env | xargs) -docker compose -f ./docker-compose.production.yml down +docker-compose -f ./docker-compose.production.yml down docker volume rm $(docker volume ls -q) -docker compose -f ./docker-compose.production.yml up mongodb -d --remove-orphans +docker-compose -f ./docker-compose.production.yml up mongodb -d --remove-orphans docker exec -i mongodb-praise sh -c 'mongorestore --authenticationDatabase admin --nsInclude=praise_db.* --uri="mongodb://$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017/?authSource=admin" --drop --preserveUUID --archive' < $1 -docker compose -f ./docker-compose.production.yml up -d --remove-orphans \ No newline at end of file +docker-compose -f ./docker-compose.production.yml up -d --remove-orphans \ No newline at end of file diff --git a/scripts/docker-compose-latest.sh b/scripts/docker-compose-latest.sh new file mode 100644 index 000000000..1d5aeef83 --- /dev/null +++ b/scripts/docker-compose-latest.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +sudo apt remove docker-compose -y +sudo rm /usr/local/bin/docker-compose + +VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d') +DESTINATION=/usr/local/bin/docker-compose +sudo curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION +sudo chmod 755 $DESTINATION +docker-compose version diff --git a/scripts/readme.md b/scripts/readme.md new file mode 100644 index 000000000..1446f9622 --- /dev/null +++ b/scripts/readme.md @@ -0,0 +1,28 @@ +# Praise Scripts +Praise comes with a few bash scripts to simplify the management of a Praise installation. +Run scripts using: +``` +bash scriptname.sh +``` +## docker-compose-latest.sh +Installs the latest version of docker-compose automatically. +**Note:** This is a prerequisite to run all praise services +## setup.sh +Builds and runs the Praise setup script. Run this script before starting Praise the first time. +## start.sh +Starts all Praise services. +## restart.sh +Restarts all Praise services. Run this command after changing the server settings. +## upgrade.sh +Downloads new server images and restarts Praise to perform the upgrade. +## database-backup.sh +Makes a full backup of the database. Backup is saved as a file in the current folder. Script uses login information in .env. +## database-restore.sh +**Usage:** +``` +bash database-restore.sh [filename] +``` +Deletes the currently active database and replaces it with data from the backup. +## reset.sh +Shuts down all running Praise services, deletes all containers and images. +**Warning**: Use with caution. N.b. The server setting are not reset, all database passwords etc are left untouched. diff --git a/reset.sh b/scripts/reset.sh similarity index 86% rename from reset.sh rename to scripts/reset.sh index 3c3f60da6..ac47ffd1d 100644 --- a/reset.sh +++ b/scripts/reset.sh @@ -8,7 +8,7 @@ then echo echo "Shutting down containers..." echo - docker compose -f ./docker-compose.production.yml down + docker-compose -f ./docker-compose.production.yml down echo echo "Deleting images..." echo diff --git a/scripts/restart.sh b/scripts/restart.sh new file mode 100644 index 000000000..81cc32c32 --- /dev/null +++ b/scripts/restart.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker-compose -f ./docker-compose.production.yml down +docker-compose -f ./docker-compose.production.yml up \ No newline at end of file diff --git a/setup.sh b/scripts/setup.sh similarity index 100% rename from setup.sh rename to scripts/setup.sh diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 000000000..7dd5d9b09 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose -f ./docker-compose.production.yml up -d \ No newline at end of file diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh new file mode 100644 index 000000000..8d188c112 --- /dev/null +++ b/scripts/upgrade.sh @@ -0,0 +1,5 @@ +#!/bin/bash +bash database-backup.sh +docker-compose -f ./docker-compose.production.yml pull +docker-compose -f ./docker-compose.production.yml down +docker-compose -f ./docker-compose.production.yml up -d --remove-orphans \ No newline at end of file diff --git a/start.sh b/start.sh deleted file mode 100644 index 6c346fa53..000000000 --- a/start.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -docker compose -f ./docker-compose.production.yml up -d \ No newline at end of file diff --git a/upgrade.sh b/upgrade.sh deleted file mode 100644 index 426899bb1..000000000 --- a/upgrade.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -bash database-backup.sh -docker compose -f ./docker-compose.production.yml pull -docker compose -f ./docker-compose.production.yml down -docker compose -f ./docker-compose.production.yml up -d --remove-orphans \ No newline at end of file