From afdd9f1c77e82de05584663a2280c77859fca7e2 Mon Sep 17 00:00:00 2001 From: Tynan McAuley <16469394+tymcauley@users.noreply.github.com> Date: Mon, 5 Nov 2018 17:01:51 -0500 Subject: [PATCH 1/5] Fixed whitespace issues. --- README.md | 2 +- docker/monit-services | 4 ++-- tests/run-tests.sh | 26 +++++++++++++------------- xo-install.sh | 16 ++++++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 004fbbe..017bd31 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Tool has been tested to work with following distros: In order to use file level restore from delta backups, the service needs to be ran as root. CentOS installation is currently not able to do file level restore if the backed up disk contains LVM. -CentOS setup is confirmed to work with fresh minimal installation and SELinux enabled. +CentOS setup is confirmed to work with fresh minimal installation and SELinux enabled. Although script doesn't do any SELinux checks or modifications, so you need to take care of possible changes by yourself according to your system. Tool makes all necessary changes required for Xen-Orchestra to run (including packages, user creation, permissions). Please evaluate script if needed. diff --git a/docker/monit-services b/docker/monit-services index 3dfaf5a..65dc448 100644 --- a/docker/monit-services +++ b/docker/monit-services @@ -10,5 +10,5 @@ check process redis with pidfile /var/run/redis_6379.pid stop program = "/usr/bin/redis-cli shutdown" check process rpcbind - matching "rpcbind" - start program = "/usr/sbin/rpcbind" + matching "rpcbind" + start program = "/usr/sbin/rpcbind" diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 48138ad..bc72ce7 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -18,24 +18,24 @@ function RunTestsSingle { curl -s -L 192.168.33.101 >> $LOGFILE 2>&1 || false if [[ $? == "1" ]]; then - echo "$1 install HTTP Check: failed" + echo "$1 install HTTP Check: failed" else echo "$1 install HTTP Check: success" fi sleep 5 vagrant provision --provision-with update >> $LOGFILE 2>&1 - sleep 5 - echo "" >> $LOGFILE - echo "Curl output after update:" >> $LOGFILE - curl -s -L 192.168.33.101 >> $LOGFILE 2>&1 || false + sleep 5 + echo "" >> $LOGFILE + echo "Curl output after update:" >> $LOGFILE + curl -s -L 192.168.33.101 >> $LOGFILE 2>&1 || false - if [[ $? == "1" ]]; then - echo "$1 update HTTP Check: failed" - else - echo "$1 update HTTP Check: success" - fi - sleep 5 + if [[ $? == "1" ]]; then + echo "$1 update HTTP Check: failed" + else + echo "$1 update HTTP Check: success" + fi + sleep 5 vagrant destroy -f >> $LOGFILE 2>&1 unset VAGRANT_CWD @@ -54,13 +54,13 @@ for x in CentOS Debian Ubuntu; do echo "Vagrant box failed to start, exiting" exit 1; fi - + vagrant provision --provision-with install >> $LOGFILE 2>&1 sleep 5 echo "" >> $LOGFILE echo "Curl output after install:" >> $LOGFILE curl -s -L -m 5 192.168.33.101 >> $LOGFILE 2>&1 || false - + if [[ $? == "1" ]]; then echo "$x install HTTP Check: failed" else diff --git a/xo-install.sh b/xo-install.sh index 716c2a7..5d02dd1 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -120,7 +120,7 @@ function InstallDependenciesDebian { trap ErrorHandling ERR INT # Install necessary dependencies for XO build - + echo echo -n "Running apt-get update..." apt-get update >/dev/null @@ -178,8 +178,8 @@ function InstallDependenciesDebian { echo "Enabling and starting redis service" /bin/systemctl enable redis-server >/dev/null && /bin/systemctl start redis-server >/dev/null - echo "Enabling and starting rpcbind service" - /bin/systemctl enable rpcbind >/dev/null && /bin/systemctl start rpcbind >/dev/null + echo "Enabling and starting rpcbind service" + /bin/systemctl enable rpcbind >/dev/null && /bin/systemctl start rpcbind >/dev/null } 2>$LOGFILE @@ -203,9 +203,9 @@ function UpdateNodeYarn { function InstallXOPlugins { set -e - + trap ErrorHandling ERR INT - + if [[ "$PLUGINS" ]] && [[ ! -z "$PLUGINS" ]]; then echo @@ -436,9 +436,9 @@ function HandleArgs { ;; esac -} +} -function RollBackInstallation { +function RollBackInstallation { INSTALLATIONS=($(find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xen-orchestra-*")) @@ -643,7 +643,7 @@ read -p ": " option ;; 2) PullDockerImage - + ;; 3) exit 0 From 3944e5dabf4d437437f2e31c8cb45fb0ad45f86d Mon Sep 17 00:00:00 2001 From: Tynan McAuley <16469394+tymcauley@users.noreply.github.com> Date: Mon, 5 Nov 2018 17:20:55 -0500 Subject: [PATCH 2/5] Migrated configuration to a standalone file. The deployed configuration file (xo-install.cfg) is not tracked by git, so changes made by users won't affect their ability to update this git repo. --- .gitignore | 1 + sample.xo-install.cfg | 23 +++++++++++++++++++++++ xo-install.sh | 33 ++++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 sample.xo-install.cfg diff --git a/.gitignore b/.gitignore index cb81e89..e1382ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ xo-install.log +xo-install.cfg tests/*/* tests/* !tests/Ubuntu diff --git a/sample.xo-install.cfg b/sample.xo-install.cfg new file mode 100644 index 0000000..f3fe87e --- /dev/null +++ b/sample.xo-install.cfg @@ -0,0 +1,23 @@ +# Optional user that runs the service. root by default +#XOUSER="node" + +# Port number where xen-orchestra service is bound +PORT="80" + +# Base dir for installation and future updates +INSTALLDIR="/etc/xo" + +# Git branch or tag (append tags/ before the tag name) where xen-orchestra sources are fetched +BRANCH="master" + +# Log path for possible errors +LOGFILE="$(dirname $0)/xo-install.log" + +# comma separated list of plugins to be installed, check README for more information +#PLUGINS="xo-server-transport-email,xo-server-usage-report,xo-server-perf-alert" + +# NodeJS and Yarn are automatically updated when running update. Switch this option to false if you want to disable it. +AUTOUPDATE="true" + +# Define the number of previous installations you want to keep. Needs to be at least 1 +PRESERVE="3" diff --git a/xo-install.sh b/xo-install.sh index 5d02dd1..6f454c1 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -6,33 +6,16 @@ # Repository: https://github.com/ronivay/XenOrchestraInstallerUpdater # ######################################################################### -### Start of editable variables ### +SAMPLE_CONFIG_FILE="sample.xo-install.cfg" +CONFIG_FILE="xo-install.cfg" -# Optional user that runs the service. root by default -#XOUSER="node" +# Deploy default configuration file if the user doesn't have their own yet. +if [[ ! -e "$CONFIG_FILE" ]]; then + cp $SAMPLE_CONFIG_FILE $CONFIG_FILE +fi -# Port number where xen-orchestra service is bound -PORT="80" - -# Base dir for installation and future updates -INSTALLDIR="/etc/xo" - -# Git branch or tag (append tags/ before the tag name) where xen-orchestra sources are fetched -BRANCH="master" - -# Log path for possible errors -LOGFILE="$(dirname $0)/xo-install.log" - -# comma separated list of plugins to be installed, check README for more information -#PLUGINS="xo-server-transport-email,xo-server-usage-report,xo-server-perf-alert" - -# NodeJS and Yarn are automatically updated when running update. Switch this option to false if you want to disable it. -AUTOUPDATE="true" - -# Define the number of previous installations you want to keep. Needs to be at least 1 -PRESERVE="3" - -### End of editable variables ### +# See this file for all script configuration variables. +source $CONFIG_FILE function CheckUser { From d02296fe570929c78894124390b6212b8f77a59b Mon Sep 17 00:00:00 2001 From: Tynan McAuley <16469394+tymcauley@users.noreply.github.com> Date: Mon, 5 Nov 2018 17:25:35 -0500 Subject: [PATCH 3/5] Added options for serving interface over HTTPS. --- sample.xo-install.cfg | 4 ++++ xo-install.sh | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/sample.xo-install.cfg b/sample.xo-install.cfg index f3fe87e..b4f8459 100644 --- a/sample.xo-install.cfg +++ b/sample.xo-install.cfg @@ -21,3 +21,7 @@ AUTOUPDATE="true" # Define the number of previous installations you want to keep. Needs to be at least 1 PRESERVE="3" + +# X.509 certificate setup. +PATH_TO_HTTPS_CERT= +PATH_TO_HTTPS_KEY= diff --git a/xo-install.sh b/xo-install.sh index 6f454c1..c62fb94 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -17,6 +17,14 @@ fi # See this file for all script configuration variables. source $CONFIG_FILE +# Protocol to use for webserver. If both of the X.509 certificate files exist, +# then assume that we want to enable HTTPS for the server. +if [[ -e $PATH_TO_HTTPS_CERT ]] && [[ -e $PATH_TO_HTTPS_KEY ]]; then + HTTPS=true +else + HTTPS=false +fi + function CheckUser { # Make sure the script is ran as root @@ -303,6 +311,14 @@ function InstallXO { sleep 2 fi + if $HTTPS ; then + echo "Enabling HTTPS in xo-server configuration file" + sed -i "s%# cert: '.\/certificate.pem'% cert: '$PATH_TO_HTTPS_CERT'%" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.yaml + sed -i "s%# key: '.\/key.pem'% key: '$PATH_TO_HTTPS_KEY'%" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.yaml + sed -i "s/#redirectToHttps/redirectToHttps/" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.yaml + sleep 2 + fi + echo "Activating modified configuration file" mv $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.yaml $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/.xo-server.yaml @@ -346,13 +362,13 @@ function InstallXO { set +x timeout 60 bash <<-"EOF" - while [[ -z $(journalctl -u xo-server | sed -n 'H; /Starting XO Server/h; ${g;p;}' | grep "http:\/\/\[::\]:$PORT") ]]; do + while [[ -z $(journalctl -u xo-server | sed -n 'H; /Starting XO Server/h; ${g;p;}' | grep "https\{0,1\}:\/\/\[::\]:$PORT") ]]; do echo "waiting port to be open" sleep 10 done EOF - if [[ $(journalctl -u xo-server | sed -n 'H; /Starting XO Server/h; ${g;p;}' | grep "http:\/\/\[::\]:$PORT") ]]; then + if [[ $(journalctl -u xo-server | sed -n 'H; /Starting XO Server/h; ${g;p;}' | grep "https\{0,1\}:\/\/\[::\]:$PORT") ]]; then echo echo "WebUI started in port $PORT" echo "Default username: admin@admin.net password: admin" From 2ede089207635646d6a15f89eb6290cf054208aa Mon Sep 17 00:00:00 2001 From: Tynan McAuley <16469394+tymcauley@users.noreply.github.com> Date: Mon, 5 Nov 2018 18:30:02 -0500 Subject: [PATCH 4/5] Sped up Xen Orchestra upgrade process. Most importantly, the xo-server/xo-web build will only happen if the new xen-orchestra source code is different from the currently-installed build. Additionally, the xen-orchestra source code will now be kept in a separate source directory. So when a new upgrade happens, we pull any updates into that directory, and copy that updated source tree to the new install directory. This way, we're not performing a full clone each time we do an update. --- xo-install.sh | 79 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/xo-install.sh b/xo-install.sh index c62fb94..2ee01bb 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -17,6 +17,8 @@ fi # See this file for all script configuration variables. source $CONFIG_FILE +XO_SRC_DIR="$INSTALLDIR/xo-src/xen-orchestra" + # Protocol to use for webserver. If both of the X.509 certificate files exist, # then assume that we want to enable HTTPS for the server. if [[ -e $PATH_TO_HTTPS_CERT ]] && [[ -e $PATH_TO_HTTPS_KEY ]]; then @@ -247,15 +249,27 @@ function InstallXO { fi echo - echo "Creating install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME" - mkdir -p "$INSTALLDIR/xo-builds/xen-orchestra-$TIME" + echo "Fetching Xen Orchestra source code ..." + echo + if [[ ! -d "$XO_SRC_DIR" ]]; then + mkdir -p "$XO_SRC_DIR" + git clone https://github.com/vatesfr/xen-orchestra "$XO_SRC_DIR" + else + cd "$XO_SRC_DIR" + git pull + cd $(dirname $0) + fi + # Deploy the latest xen-orchestra source to the new install directory. echo - echo "Fetching source code from branch: $BRANCH ..." - echo - git clone https://github.com/vatesfr/xen-orchestra $INSTALLDIR/xo-builds/xen-orchestra-$TIME + echo "Creating install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME" + rm -rf "$INSTALLDIR/xo-builds/xen-orchestra-$TIME" + cp -r "$XO_SRC_DIR" "$INSTALLDIR/xo-builds/xen-orchestra-$TIME" if [[ "$BRANCH" != "master" ]]; then + echo + echo "Checking out source code from branch '$BRANCH'" + cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME git checkout $BRANCH cd $(dirname $0) @@ -264,6 +278,54 @@ function InstallXO { echo echo "done" + # Check if the new repo is any different from the currently-installed + # one. If not, then skip the build and delete the repo we just cloned. + + # Get the commit ID of the to-be-installed xen-orchestra. + cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME + NEW_REPO_HASH=$(git rev-parse HEAD) + NEW_REPO_HASH_SHORT=$(git rev-parse --short HEAD) + cd $(dirname $0) + + # Get the commit ID of the currently-installed xen-orchestra (if one + # exists). + if [[ -L $INSTALLDIR/xo-server ]]; then + cd $INSTALLDIR/xo-server + OLD_REPO_HASH=$(git rev-parse HEAD) + OLD_REPO_HASH_SHORT=$(git rev-parse --short HEAD) + cd $(dirname $0) + else + # If there's no existing installation, then we definitely want + # to proceed with the bulid. + OLD_REPO_HASH="" + OLD_REPO_HASH_SHORT="" + fi + + # If the new install is no different from the existing install, then don't + # proceed with the build. + if [[ "$NEW_REPO_HASH" == "$OLD_REPO_HASH" ]]; then + echo + echo "No changes to xen-orchestra since previous install. Skipping xo-server and xo-web build." + echo "Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME" + rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME + return 0 + fi + + # Now that we know we're going to be building a new xen-orchestra, make + # sure there's no already-running xo-server process. + if [[ $(ps aux | grep xo-server | grep -v grep) ]]; then + echo + echo -n "Shutting down xo-server..." + /bin/systemctl stop xo-server || { echo "failed to stop service, exiting..." ; exit 1; } + echo "done" + fi + + # If this isn't a fresh install, then list the upgrade the user is making. + if [[ ! -z "$OLD_REPO_HASH" ]]; then + echo + echo "Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" + fi + echo echo "xo-server and xo-web build quite a while. Grab a cup of coffee and lay back" echo @@ -386,13 +448,6 @@ function InstallXO { function UpdateXO { - if [[ $(ps aux | grep xo-server | grep -v grep) ]]; then - echo - echo -n "Shutting down xo-server..." - /bin/systemctl stop xo-server || { echo "failed to stop service, exiting..." ; exit 1; } - echo "done" - fi - InstallXO if [[ "$PRESERVE" != "0" ]]; then From f87a20acc922a87eef908f1d3ceb2ce8a28f3f91 Mon Sep 17 00:00:00 2001 From: Tynan McAuley <16469394+tymcauley@users.noreply.github.com> Date: Mon, 5 Nov 2018 18:35:05 -0500 Subject: [PATCH 5/5] Added ability to update only to tagged releases. --- sample.xo-install.cfg | 3 ++- xo-install.sh | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sample.xo-install.cfg b/sample.xo-install.cfg index b4f8459..16195c3 100644 --- a/sample.xo-install.cfg +++ b/sample.xo-install.cfg @@ -7,7 +7,8 @@ PORT="80" # Base dir for installation and future updates INSTALLDIR="/etc/xo" -# Git branch or tag (append tags/ before the tag name) where xen-orchestra sources are fetched +# Git branch or tag (append tags/ before the tag name) where xen-orchestra sources are fetched. +# Also, you can set this to "release" to use the latest tagged branch. BRANCH="master" # Log path for possible errors diff --git a/xo-install.sh b/xo-install.sh index 2ee01bb..be2b8df 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -266,7 +266,16 @@ function InstallXO { rm -rf "$INSTALLDIR/xo-builds/xen-orchestra-$TIME" cp -r "$XO_SRC_DIR" "$INSTALLDIR/xo-builds/xen-orchestra-$TIME" - if [[ "$BRANCH" != "master" ]]; then + if [[ "$BRANCH" == "release" ]]; then + cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME + TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) + + echo + echo "Checking out latest tagged release '$TAG'" + + git checkout $TAG 2> /dev/null # Suppress the detached-head message. + cd $(dirname $0) + elif [[ "$BRANCH" != "master" ]]; then echo echo "Checking out source code from branch '$BRANCH'"