From f08a69566d1ec88d82bd363fc4b69fdb5a7a9f30 Mon Sep 17 00:00:00 2001 From: ronivay Date: Fri, 27 Jul 2018 09:33:56 +0300 Subject: [PATCH] Add possibility to rollback installation. Update function/argument names to be more clear and update readme --- README.md | 12 ++++++++- tests/CentOS/Vagrantfile | 2 +- tests/Debian/Vagrantfile | 2 +- tests/Ubuntu/Vagrantfile | 2 +- xo-install.sh | 56 +++++++++++++++++++++++++++++++++++++--- 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7f8cd78..989eb37 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,17 @@ Optional plugins can be installed. They are included in XO repository, but not i Clone this repository, edit variables to suit your preferences from the xo-install.sh script and run it as root ``` +basic functionality including menu: ./xo-install.sh -for non-interactive update task: +non-interactive update task (option 2): ./xo-install.sh --update + +non-interactive install task (option 1): +./xo-install.sh --install + +non-interactive rollback task (option 4): +./xo-install.sh --rollback ``` Tool makes some checks and offers options: @@ -34,6 +41,9 @@ Tool makes some checks and offers options: 3. Deploy container - Offers options to build container locally or pull from dockerhub +4. Rollback installation + - Offers option to choose which installation to use from existing ones (if more than 1) + notes: - If you choose to install with option 2, you need to take care that required packages are already installed diff --git a/tests/CentOS/Vagrantfile b/tests/CentOS/Vagrantfile index a13c5f5..c80be70 100644 --- a/tests/CentOS/Vagrantfile +++ b/tests/CentOS/Vagrantfile @@ -43,6 +43,6 @@ Vagrant.configure(2) do |config| # # Run automated test installation # - config.vm.provision :shell, path: "../../xo-install.sh", args: "--run-test", run: 'always' + config.vm.provision :shell, path: "../../xo-install.sh", args: "--install", run: 'always' end diff --git a/tests/Debian/Vagrantfile b/tests/Debian/Vagrantfile index 4949ea2..02894a1 100644 --- a/tests/Debian/Vagrantfile +++ b/tests/Debian/Vagrantfile @@ -43,6 +43,6 @@ Vagrant.configure(2) do |config| # # Run automated test installation # - config.vm.provision :shell, path: "../../xo-install.sh", args: "--run-test", run: 'always' + config.vm.provision :shell, path: "../../xo-install.sh", args: "--install", run: 'always' end diff --git a/tests/Ubuntu/Vagrantfile b/tests/Ubuntu/Vagrantfile index 93ec4cf..4781280 100644 --- a/tests/Ubuntu/Vagrantfile +++ b/tests/Ubuntu/Vagrantfile @@ -43,6 +43,6 @@ Vagrant.configure(2) do |config| # # Run automated test installation # - config.vm.provision :shell, path: "../../xo-install.sh", args: "--run-test", run: 'always' + config.vm.provision :shell, path: "../../xo-install.sh", args: "--install", run: 'always' end diff --git a/xo-install.sh b/xo-install.sh index 6f3deec..c895c79 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -340,14 +340,14 @@ function UpdateXO { } 2>$LOGFILE -function UpdateXOAutomate { +function HandleArgs { case "$1" in --update) UpdateNodeYarn UpdateXO ;; - --run-test) + --install) if [ $OSNAME == "CentOS" ]; then InstallDependenciesCentOS InstallXO @@ -358,6 +358,10 @@ function UpdateXOAutomate { exit 0 fi ;; + --rollback) + RollBackInstallation + exit 0 + ;; *) StartUpScreen ;; @@ -365,6 +369,44 @@ function UpdateXOAutomate { } +function RollBackInstallation { + + INSTALLATIONS=($(find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xen-orchestra-*")) + + if [[ $(echo ${#INSTALLATIONS[@]}) -le 1 ]]; then + echo "Only one installation exists, nothing to change" + exit 0 + fi + + echo "Which installation to roll back?" + echo + local PS3="Pick a number. CTRL+C to exit: " + select INSTALLATION in "${INSTALLATIONS[@]}"; do + case $INSTALLATION in + *xen-orchestra*) + echo + echo "Setting $INSTALLDIR/xo-server symlink to $INSTALLATION/packages/xo-server" + ln -sfn $INSTALLATION/packages/xo-server $INSTALLDIR/xo-server + echo "Setting $INSTALLDIR/xo-web symlink to $INSTALLATION/packages/xo-web" + ln -sfn $INSTALLATION/packages/xo-web $INSTALLDIR/xo-web + echo + echo "Updating xo-server.service systemd configuration file location" + ln -sfn $INSTALLDIR/xo-server/xo-server.service /etc/systemd/system/xo-server.service + /bin/systemctl daemon-reload + echo + echo "Restarting xo-server..." + /bin/systemctl restart xo-server + echo + break + ;; + *) + echo "Try again" + ;; + esac + done + +} + function CheckOS { if [ -f /etc/centos-release ] ; then @@ -452,6 +494,7 @@ echo "- Option 2. actually creates a new build from sources but works as an upda echo " NodeJS and Yarn packages are updated automatically. Check AUTOUPDATE variable to disable this" echo " Data stored in redis and /var/lib/xo-server/data will not be touched during update procedure." echo " 3 latest installations will be preserved and older ones are deleted after successful update. Fresh installation is symlinked as active" +echo " Rollback to another installation with --rollback" echo echo "- To run option 2. without interactive mode (as cronjob for automated updates for example) use --update" echo @@ -477,7 +520,8 @@ echo echo "1. Autoinstall" echo "2. Update / Install without packages" echo "3. Deploy docker container" -echo "4. Exit" +echo "4. Rollback to another existing installation" +echo "5. Exit" echo read -p ": " option @@ -540,6 +584,10 @@ read -p ": " option esac ;; 4) + RollBackInstallation + exit 0 + ;; + 5) exit 0 ;; *) @@ -556,7 +604,7 @@ CheckOS CheckSystemd if [[ $# == "1" ]]; then - UpdateXOAutomate "$1" + HandleArgs "$1" exit 0 else StartUpScreen