Add Docker container, update readme and fix indentations
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
This tool will will install and update [Xen Orchestra](https://xen-orchestra.com/#!/) automatically. xo-server and xo-web components are built from sources.
|
||||
|
||||
There's also an option to build/pull docker image to get things up and running quickly.
|
||||
|
||||
## Instructions
|
||||
|
||||
Clone this repository and run xo-install.sh script as root
|
||||
@@ -12,13 +14,15 @@ Clone this repository and run xo-install.sh script as root
|
||||
./install-xo.sh
|
||||
```
|
||||
|
||||
Tool makes some checks and offers options to update/install Xen-Orchestra or deploy a container.
|
||||
|
||||
Tool has been tested to work with following distros:
|
||||
|
||||
- CentOS 7
|
||||
- Debian 8
|
||||
- Ubuntu 16.05
|
||||
|
||||
CentOS was tested without SELinux. You need to deal with labels yourself if you want to use it.
|
||||
CentOS was tested without SELinux. You need to deal with labels and permissions yourself if you want to use it.
|
||||
|
||||
## Notes
|
||||
|
||||
|
43
docker/Dockerfile
Normal file
43
docker/Dockerfile
Normal file
@@ -0,0 +1,43 @@
|
||||
FROM centos:latest
|
||||
|
||||
MAINTAINER Roni Väyrynen <roni@vayrynen.info>
|
||||
|
||||
# Install set of dependencies to support running Xen-Orchestra
|
||||
|
||||
# Node v6
|
||||
RUN curl -s -L https://rpm.nodesource.com/setup_6.x | bash -
|
||||
|
||||
# yarn for installing node packages
|
||||
RUN curl -s -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo
|
||||
RUN yum -y install yarn
|
||||
|
||||
# epel-release for various packages not available from base repo
|
||||
RUN yum -y install epel-release
|
||||
|
||||
# build dependencies, git for fetchin source and redis server for storing ata
|
||||
RUN yum -y install gcc gcc-c++ make openssl-devel redis libpng-devel python git
|
||||
|
||||
# monit to keep an eye on processes
|
||||
RUN yum -y install monit
|
||||
ADD monit-services /etc/monit.d/services
|
||||
|
||||
# Fetch Xen-Orchestra sources from git stable branch
|
||||
RUN git clone -b stable http://github.com/vatesfr/xo-server /etc/xo-server
|
||||
RUN git clone -b stable http://github.com/vatesfr/xo-web /etc/xo-web
|
||||
|
||||
# Run build tasks against sources
|
||||
RUN cd /etc/xo-server && yarn
|
||||
RUN cd /etc/xo-web && yarn
|
||||
|
||||
# Fix path for xo-web content in xo-server configuration
|
||||
RUN sed -i "s/#'\/': '\/path\/to\/xo-web\/dist\//'\/': '..\/xo-web\/dist\//" /etc/xo-server/sample.config.yaml
|
||||
|
||||
# Move edited config sample to place
|
||||
RUN mv /etc/xo-server/sample.config.yaml /etc/xo-server/.xo-server.yaml
|
||||
|
||||
# Install forever for starting/stopping Xen-Orchestra
|
||||
RUN npm install forever -g
|
||||
|
||||
WORKDIR /etc/xo-server
|
||||
|
||||
CMD ["/usr/bin/monit"]
|
10
docker/monit-services
Normal file
10
docker/monit-services
Normal file
@@ -0,0 +1,10 @@
|
||||
set init
|
||||
|
||||
check process xo-server with pidfile /var/run/xo-server.pid
|
||||
start program = "/usr/bin/forever start --pidFile /var/run/xo-server.pid --sourceDir /etc/xo-server bin/xo-server"
|
||||
stop program = "/usr/bin/forever stop /etc/xo-server/bin/xo-server"
|
||||
|
||||
|
||||
check process redis with pidfile /var/run/redis/redis.pid
|
||||
start program = "/usr/bin/redis-server /etc/redis.conf --daemonize yes"
|
||||
stop program = "/usr/bin/redis-cli shutdown"
|
513
xo-install.sh
513
xo-install.sh
@@ -6,117 +6,118 @@
|
||||
PORT="80"
|
||||
INSTALLDIR="/etc/xo"
|
||||
BRANCH="stable"
|
||||
LOGFILE=$(dirname $0)/xo-install.log
|
||||
LOGFILE="$(dirname $0)/xo-install.log"
|
||||
|
||||
## Modify to your need ##
|
||||
|
||||
function CheckUser {
|
||||
|
||||
# Make sure the script is ran as root
|
||||
# Make sure the script is ran as root
|
||||
|
||||
if [[ ! $(whoami) == "root" ]]; then
|
||||
echo "This script needs to be ran as root"
|
||||
exit 0
|
||||
fi
|
||||
if [[ ! $(whoami) == "root" ]]; then
|
||||
echo "This script needs to be ran as root"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function InstallDependenciesCentOS {
|
||||
|
||||
set -e
|
||||
set -e
|
||||
|
||||
# Install necessary dependencies for XO build
|
||||
# Install necessary dependencies for XO build
|
||||
|
||||
# only run automated node install if package not found
|
||||
if [[ -z $(rpm -qa | grep ^node) ]]; then
|
||||
echo
|
||||
echo -n "Installing node.js..."
|
||||
curl -s -L https://rpm.nodesource.com/setup_6.x | bash - >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
# only run automated node install if package not found
|
||||
if [[ -z $(rpm -qa | grep ^node) ]]; then
|
||||
echo
|
||||
echo -n "Installing node.js..."
|
||||
curl -s -L https://rpm.nodesource.com/setup_6.x | bash - >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
|
||||
# only install yarn repo and package if not found
|
||||
if [[ -z $(rpm -qa | grep yarn) ]]; then
|
||||
echo
|
||||
echo -n "Installing yarn..."
|
||||
curl -s -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo >/dev/null 2>$LOGFILE && \
|
||||
yum -y install yarn >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
# only install yarn repo and package if not found
|
||||
if [[ -z $(rpm -qa | grep yarn) ]]; then
|
||||
echo
|
||||
echo -n "Installing yarn..."
|
||||
curl -s -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo >/dev/null 2>$LOGFILE && \
|
||||
yum -y install yarn >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
|
||||
# only install epel-release if doesn't exist
|
||||
if [[ -z $(rpm -qa | grep epel-release) ]]; then
|
||||
echo
|
||||
echo -n "Installing epel-repo..."
|
||||
yum -y install epel-release >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
# only install epel-release if doesn't exist
|
||||
if [[ -z $(rpm -qa | grep epel-release) ]]; then
|
||||
echo
|
||||
echo -n "Installing epel-repo..."
|
||||
yum -y install epel-release >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
|
||||
# install
|
||||
echo
|
||||
echo -n "Installing build dependencies, redis server, python and git..."
|
||||
yum -y install gcc gcc-c++ make openssl-devel redis libpng-devel python git >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
# install
|
||||
echo
|
||||
echo -n "Installing build dependencies, redis server, python and git..."
|
||||
yum -y install gcc gcc-c++ make openssl-devel redis libpng-devel python git >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
echo
|
||||
|
||||
echo "Enabling and starting redis service"
|
||||
/bin/systemctl enable redis >/dev/null 2>$LOGFILE && /bin/systemctl start redis >/dev/null 2>$LOGFILE
|
||||
echo "Enabling and starting redis service"
|
||||
/bin/systemctl enable redis >/dev/null 2>$LOGFILE && /bin/systemctl start redis >/dev/null 2>$LOGFILE
|
||||
|
||||
}
|
||||
|
||||
function InstallDependenciesDebian {
|
||||
# Install necessary dependencies for XO build
|
||||
|
||||
set -e
|
||||
set -e
|
||||
|
||||
echo
|
||||
echo -n "Running apt-get update..."
|
||||
apt-get update >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
|
||||
# Install apt-transport-https and ca-certificates because of yarn https repo url
|
||||
# Install necessary dependencies for XO build
|
||||
|
||||
echo
|
||||
echo -n "Installing apt-transport-https and ca-certificates packages to support https repos"
|
||||
apt-get install -y apt-transport-https ca-certificates >/dev/null 2>$LOGFILE
|
||||
echo -n "Running apt-get update..."
|
||||
apt-get update >/dev/null 2>$LOGFLE
|
||||
echo "done"
|
||||
|
||||
# install curl for later tasks if missing
|
||||
if [[ ! $(which curl) ]]; then
|
||||
# Install apt-transport-https and ca-certificates because of yarn https repo url
|
||||
echo
|
||||
echo -n "Installing apt-transport-https and ca-certificates packages to support https repos"
|
||||
apt-get install -y apt-transport-https ca-certificates >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
|
||||
# install curl for later tasks if missing
|
||||
if [[ ! $(which curl) ]]; then
|
||||
echo
|
||||
echo -n "Installing curl..."
|
||||
apt-get install -y curl >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
echo -n "Installing curl..."
|
||||
apt-get install -y curl >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
|
||||
# only install yarn repo and package if not found
|
||||
if [[ -z $(dpkg -l | grep yarn) ]]; then
|
||||
echo
|
||||
echo -n "Installing yarn..."
|
||||
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - >/dev/null 2>$LOGFILE
|
||||
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list >/dev/null 2>$LOGFILE
|
||||
apt-get update >/dev/null 2>$LOGFILE
|
||||
apt-get install -y yarn >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
# only install yarn repo and package if not found
|
||||
if [[ -z $(dpkg -l | grep yarn) ]]; then
|
||||
echo
|
||||
echo -n "Installing yarn..."
|
||||
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - >/dev/null 2>$LOGFILE
|
||||
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list >/dev/null 2>$LOGFILE
|
||||
apt-get update >/dev/null 2>$LOGFILE
|
||||
apt-get install -y yarn >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
|
||||
|
||||
# only run automated node install if package not found
|
||||
if [[ -z $(dpkg -l | grep node) ]] || [[ -z $(which npm) ]]; then
|
||||
echo
|
||||
echo -n "Installing node.js..."
|
||||
curl -sL https://deb.nodesource.com/setup_6.x | bash - >/dev/null 2>$LOGFILE
|
||||
apt-get install -y nodejs >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
# only run automated node install if package not found
|
||||
if [[ -z $(dpkg -l | grep node) ]] || [[ -z $(which npm) ]]; then
|
||||
echo
|
||||
echo -n "Installing node.js..."
|
||||
curl -sL https://deb.nodesource.com/setup_6.x | bash - >/dev/null 2>$LOGFILE
|
||||
apt-get install -y nodejs >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
fi
|
||||
|
||||
|
||||
# install packages
|
||||
echo
|
||||
echo -n "Installing build dependencies, redis server, python and git..."
|
||||
apt-get install -y build-essential redis-server libpng-dev git python-minimal >/dev/null 2>$LOGFILE
|
||||
# install packages
|
||||
echo
|
||||
echo -n "Installing build dependencies, redis server, python and git..."
|
||||
apt-get install -y build-essential redis-server libpng-dev git python-minimal >/dev/null 2>$LOGFILE
|
||||
|
||||
echo "Enabling and starting redis service"
|
||||
/bin/systemctl enable redis-server >/dev/null 2>$LOGFILE && /bin/systemctl start redis-server >/dev/null 2>$LOGFILE
|
||||
echo "Enabling and starting redis service"
|
||||
/bin/systemctl enable redis-server >/dev/null 2>$LOGFILE && /bin/systemctl start redis-server >/dev/null 2>$LOGFILE
|
||||
|
||||
|
||||
}
|
||||
@@ -124,120 +125,121 @@ function InstallDependenciesDebian {
|
||||
|
||||
function InstallXO {
|
||||
|
||||
set -e
|
||||
set -e
|
||||
|
||||
TIME=`date +%Y%d%m%H%M`
|
||||
TIME=`date +%Y%d%m%H%M`
|
||||
|
||||
# Create user if doesn't exist (if defined)
|
||||
# Create user if doesn't exist (if defined)
|
||||
|
||||
if [ $XOUSER ]; then
|
||||
if [[ -z $(getent passwd $XOUSER) ]]; then
|
||||
if [ $XOUSER ]; then
|
||||
if [[ -z $(getent passwd $XOUSER) ]]; then
|
||||
echo
|
||||
echo "Creating $XOUSER user"
|
||||
useradd -s /sbin/nologin $XOUSER
|
||||
echo
|
||||
sleep 2
|
||||
fi
|
||||
fi
|
||||
echo "Creating $XOUSER user"
|
||||
useradd -s /sbin/nologin $XOUSER
|
||||
echo
|
||||
sleep 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create installation directory if doesn't exist already
|
||||
if [[ ! -d "$INSTALLDIR" ]] ; then
|
||||
echo "Creating missing basedir to $INSTALLDIR"
|
||||
mkdir -p "$INSTALLDIR"
|
||||
fi
|
||||
# Create installation directory if doesn't exist already
|
||||
if [[ ! -d "$INSTALLDIR" ]] ; then
|
||||
echo "Creating missing basedir to $INSTALLDIR"
|
||||
mkdir -p "$INSTALLDIR"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Creating install directory: $INSTALLDIR/xo-builds/xo-server-$TIME"
|
||||
mkdir -p "$INSTALLDIR/xo-builds/xo-server-$TIME"
|
||||
sleep 2
|
||||
echo "Creating install directory: $INSTALLDIR/xo-builds/xo-web-$TIME"
|
||||
mkdir -p "$INSTALLDIR/xo-builds/xo-web-$TIME"
|
||||
sleep 2
|
||||
echo
|
||||
echo "Creating install directory: $INSTALLDIR/xo-builds/xo-server-$TIME"
|
||||
mkdir -p "$INSTALLDIR/xo-builds/xo-server-$TIME"
|
||||
sleep 2
|
||||
echo "Creating install directory: $INSTALLDIR/xo-builds/xo-web-$TIME"
|
||||
mkdir -p "$INSTALLDIR/xo-builds/xo-web-$TIME"
|
||||
sleep 2
|
||||
|
||||
echo
|
||||
echo "Fetching source code from branch: $BRANCH ..."
|
||||
echo
|
||||
git clone -b $BRANCH http://github.com/vatesfr/xo-server $INSTALLDIR/xo-builds/xo-server-$TIME
|
||||
echo
|
||||
echo
|
||||
git clone -b $BRANCH http://github.com/vatesfr/xo-web $INSTALLDIR/xo-builds/xo-web-$TIME
|
||||
echo
|
||||
echo "done"
|
||||
echo
|
||||
echo "Fetching source code from branch: $BRANCH ..."
|
||||
echo
|
||||
git clone -b $BRANCH http://github.com/vatesfr/xo-server $INSTALLDIR/xo-builds/xo-server-$TIME
|
||||
echo
|
||||
echo
|
||||
git clone -b $BRANCH http://github.com/vatesfr/xo-web $INSTALLDIR/xo-builds/xo-web-$TIME
|
||||
echo
|
||||
echo "done"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "xo-server and xo-web build quite a while. Grab a cup of coffee and lay back"
|
||||
echo
|
||||
echo -n "Running xo-server install..."
|
||||
cd $INSTALLDIR/xo-builds/xo-server-$TIME && yarn >/dev/null 2>$LOGFILE && yarn run build >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
echo -n "Running xo-web install..."
|
||||
cd $INSTALLDIR/xo-builds/xo-web-$TIME && yarn >/dev/null 2>$LOGFILE && yarn run build >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
|
||||
echo
|
||||
echo "Fixing binary path in systemd service configuration and symlinking to /etc/systemd/system/xo-server.service"
|
||||
sed -i "s#ExecStart=.*#ExecStart=$INSTALLDIR\/xo-server\/bin\/xo-server#" $INSTALLDIR/xo-builds/xo-server-$TIME/xo-server.service
|
||||
echo -n "Running xo-server install..."
|
||||
cd $INSTALLDIR/xo-builds/xo-server-$TIME && yarn >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
echo -n "Running xo-web install..."
|
||||
cd $INSTALLDIR/xo-builds/xo-web-$TIME && yarn >/dev/null 2>$LOGFILE
|
||||
echo "done"
|
||||
|
||||
echo
|
||||
echo "Fixing binary path in systemd service configuration and symlinking to /etc/systemd/system/xo-server.service"
|
||||
sed -i "s#ExecStart=.*#ExecStart=$INSTALLDIR\/xo-server\/bin\/xo-server#" $INSTALLDIR/xo-builds/xo-server-$TIME/xo-server.service
|
||||
echo
|
||||
echo "Adding WorkingDirectory parameter to systemd service configuration"
|
||||
sed -i "/ExecStart=.*/a WorkingDirectory=/etc/xo/xo-server" $INSTALLDIR/xo-builds/xo-server-$TIME/xo-server.service
|
||||
|
||||
if [ $XOUSER ]; then
|
||||
echo "Adding user to systemd config"
|
||||
sed -i "/SyslogIdentifier=.*/a User=$XOUSER" $INSTALLDIR/xo-builds/xo-server-$TIME/xo-server.service
|
||||
if [ $XOUSER ]; then
|
||||
echo "Adding user to systemd config"
|
||||
sed -i "/SyslogIdentifier=.*/a User=$XOUSER" $INSTALLDIR/xo-builds/xo-server-$TIME/xo-server.service
|
||||
|
||||
if [ $OSNAME == "CentOS" ]; then
|
||||
echo -n "Attempting to set cap_net_bind_service permission for /usr/bin/node..."
|
||||
setcap 'cap_net_bind_service=+ep' /usr/bin/node >/dev/null 2>$LOGFILE \
|
||||
&& echo "Success" || echo "Failed. Non-privileged user might not be able to bind to <1024 port"
|
||||
else
|
||||
echo -n "Attempting to set cap_net_bind_service permission for /usr/bin/nodejs..."
|
||||
setcap 'cap_net_bind_service=+ep' /usr/bin/nodejs >/dev/null 2>$LOGFILE \
|
||||
&& echo "Success" || echo "Failed. Non-privileged user might not be able to bind to <1024 port"
|
||||
fi
|
||||
fi
|
||||
if [ $OSNAME == "CentOS" ]; then
|
||||
echo -n "Attempting to set cap_net_bind_service permission for /usr/bin/node..."
|
||||
setcap 'cap_net_bind_service=+ep' /usr/bin/node >/dev/null 2>$LOGFILE \
|
||||
&& echo "Success" || echo "Failed. Non-privileged user might not be able to bind to <1024 port"
|
||||
else
|
||||
echo -n "Attempting to set cap_net_bind_service permission for /usr/bin/nodejs..."
|
||||
setcap 'cap_net_bind_service=+ep' /usr/bin/nodejs >/dev/null 2>$LOGFILE \
|
||||
&& echo "Success" || echo "Failed. Non-privileged user might not be able to bind to <1024 port"
|
||||
fi
|
||||
fi
|
||||
|
||||
ln -sfn $INSTALLDIR/xo-builds/xo-server-$TIME/xo-server.service /etc/systemd/system/xo-server.service
|
||||
sleep 2
|
||||
echo "Reloading systemd configuration"
|
||||
echo
|
||||
/bin/systemctl daemon-reload
|
||||
sleep 2
|
||||
echo
|
||||
echo "Symlinking systemd service configuration"
|
||||
ln -sfn $INSTALLDIR/xo-server/xo-server.service /etc/systemd/system/xo-server.service
|
||||
sleep 2
|
||||
echo "Reloading systemd configuration"
|
||||
echo
|
||||
/bin/systemctl daemon-reload
|
||||
sleep 2
|
||||
|
||||
echo "Fixing relative path to xo-web installation in xo-server configuration file"
|
||||
sed -i "s/#'\/': '\/path\/to\/xo-web\/dist\//'\/': '..\/..\/xo-web\/dist\//" $INSTALLDIR/xo-builds/xo-server-$TIME/sample.config.yaml
|
||||
sleep 2
|
||||
echo "Fixing relative path to xo-web installation in xo-server configuration file"
|
||||
sed -i "s/#'\/': '\/path\/to\/xo-web\/dist\//'\/': '..\/..\/xo-web\/dist\//" $INSTALLDIR/xo-builds/xo-server-$TIME/sample.config.yaml
|
||||
sleep 2
|
||||
|
||||
if [[ $PORT != "80" ]]; then
|
||||
echo "Changing port in xo-server configuration file"
|
||||
sed -i "s/port: 80/port: $PORT/" $INSTALLDIR/xo-builds/xo-server-$TIME/sample.config.yaml
|
||||
sleep 2
|
||||
fi
|
||||
if [[ $PORT != "80" ]]; then
|
||||
echo "Changing port in xo-server configuration file"
|
||||
sed -i "s/port: 80/port: $PORT/" $INSTALLDIR/xo-builds/xo-server-$TIME/sample.config.yaml
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
echo "Activating modified configuration file"
|
||||
mv $INSTALLDIR/xo-builds/xo-server-$TIME/sample.config.yaml $INSTALLDIR/xo-builds/xo-server-$TIME/.xo-server.yaml
|
||||
echo "Activating modified configuration file"
|
||||
mv $INSTALLDIR/xo-builds/xo-server-$TIME/sample.config.yaml $INSTALLDIR/xo-builds/xo-server-$TIME/.xo-server.yaml
|
||||
|
||||
echo
|
||||
echo "Symlinking fresh xo-server install/update to $INSTALLDIR/xo-server"
|
||||
ln -sfn $INSTALLDIR/xo-builds/xo-server-$TIME $INSTALLDIR/xo-server
|
||||
sleep 2
|
||||
echo "Symlinking fresh xo-web install/update to $INSTALLDIR/xo-web"
|
||||
ln -sfn $INSTALLDIR/xo-builds/xo-web-$TIME $INSTALLDIR/xo-web
|
||||
echo
|
||||
echo "Symlinking fresh xo-server install/update to $INSTALLDIR/xo-server"
|
||||
ln -sfn $INSTALLDIR/xo-builds/xo-server-$TIME $INSTALLDIR/xo-server
|
||||
sleep 2
|
||||
echo "Symlinking fresh xo-web install/update to $INSTALLDIR/xo-web"
|
||||
ln -sfn $INSTALLDIR/xo-builds/xo-web-$TIME $INSTALLDIR/xo-web
|
||||
|
||||
if [ $XOUSER ]; then
|
||||
chown -R $XOUSER:$XOUSER $INSTALLDIR/xo-builds/xo-web-$TIME
|
||||
chown -R $XOUSER:$XOUSER $INSTALLDIR/xo-builds/xo-server-$TIME
|
||||
if [ $XOUSER ]; then
|
||||
chown -R $XOUSER:$XOUSER $INSTALLDIR/xo-builds/xo-web-$TIME
|
||||
chown -R $XOUSER:$XOUSER $INSTALLDIR/xo-builds/xo-server-$TIME
|
||||
|
||||
if [ ! -d /var/lib/xo-server ]; then
|
||||
mkdir /var/lib/xo-server 2>/dev/null
|
||||
fi
|
||||
if [ ! -d /var/lib/xo-server ]; then
|
||||
mkdir /var/lib/xo-server 2>/dev/null
|
||||
fi
|
||||
|
||||
chown $XOUSER:$XOUSER /var/lib/xo-server
|
||||
fi
|
||||
chown $XOUSER:$XOUSER /var/lib/xo-server
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Starting xo-server..."
|
||||
/bin/systemctl start xo-server >/dev/null
|
||||
echo
|
||||
echo "Starting xo-server..."
|
||||
/bin/systemctl start xo-server >/dev/null
|
||||
|
||||
timeout 60 bash <<-"EOF"
|
||||
while [[ -z $(journalctl -u xo-server | grep "http:\/\/\[::\]:$PORT") ]]; do
|
||||
@@ -259,46 +261,50 @@ function InstallXO {
|
||||
|
||||
function UpdateXO {
|
||||
|
||||
/bin/systemctl stop xo-server || { echo "failed to stop service, exiting..." ; exit 1; }
|
||||
InstallXO
|
||||
|
||||
# remove old builds. leave 5 latest
|
||||
find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xo-web*" -printf "%T@ %p\n" | sort -n | cut -d' ' -f2- | head -n -5 | xargs -r rm -r
|
||||
find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xo-server*" -printf "%T@ %p\n" | sort -n | cut -d' ' -f2- | head -n -5 | xargs -r rm -r
|
||||
if [[ $(ps aux | grep xo-server | grep -v grep) ]]; then
|
||||
/bin/systemctl stop xo-server || { echo "failed to stop service, exiting..." ; exit 1; }
|
||||
fi
|
||||
|
||||
InstallXO
|
||||
|
||||
# remove old builds. leave 5 latest
|
||||
find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xo-web*" -printf "%T@ %p\n" | sort -n | cut -d' ' -f2- | head -n -5 | xargs -r rm -r
|
||||
find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xo-server*" -printf "%T@ %p\n" | sort -n | cut -d' ' -f2- | head -n -5 | xargs -r rm -r
|
||||
}
|
||||
|
||||
function CheckOS {
|
||||
|
||||
if [ -f /etc/centos-release ] ; then
|
||||
OSVERSION=$(grep -Eo "[0-9]" /etc/centos-release | head -1)
|
||||
OSNAME="CentOS"
|
||||
if [[ ! $OSVERSION == "7" ]]; then
|
||||
echo "Only CentOS 7 supported"
|
||||
exit 0
|
||||
fi
|
||||
elif [[ -f /etc/os-release ]]; then
|
||||
OSVERSION=$(grep ^VERSION_ID /etc/os-release | cut -d'=' -f2 | grep -Eo "[0-9]{1,2}" | head -1)
|
||||
OSNAME=$(grep ^NAME /etc/os-release | cut -d'=' -f2 | sed 's/"//g' | awk '{print $1}')
|
||||
if [[ $OSNAME == "Debian" ]] && [[ ! $OSVERSION =~ ^(8|9)$ ]]; then
|
||||
echo "Only Debian 8/9 supported"
|
||||
exit 0
|
||||
elif [[ $OSNAME == "Ubuntu" ]] && [[ ! $OSVERSION == "16" ]]; then
|
||||
echo "Only Ubuntu 16 supported"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "Only CentOS 7 / Ubuntu 16 and Debian 8/9 supported"
|
||||
exit 0
|
||||
fi
|
||||
if [ -f /etc/centos-release ] ; then
|
||||
OSVERSION=$(grep -Eo "[0-9]" /etc/centos-release | head -1)
|
||||
OSNAME="CentOS"
|
||||
if [[ ! $OSVERSION == "7" ]]; then
|
||||
echo "Only CentOS 7 supported"
|
||||
exit 0
|
||||
fi
|
||||
elif [[ -f /etc/os-release ]]; then
|
||||
OSVERSION=$(grep ^VERSION_ID /etc/os-release | cut -d'=' -f2 | grep -Eo "[0-9]{1,2}" | head -1)
|
||||
OSNAME=$(grep ^NAME /etc/os-release | cut -d'=' -f2 | sed 's/"//g' | awk '{print $1}')
|
||||
if [[ $OSNAME == "Debian" ]] && [[ ! $OSVERSION =~ ^(8|9)$ ]]; then
|
||||
echo "Only Debian 8/9 supported"
|
||||
exit 0
|
||||
elif [[ $OSNAME == "Ubuntu" ]] && [[ ! $OSVERSION == "16" ]]; then
|
||||
echo "Only Ubuntu 16 supported"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "Only CentOS 7 / Ubuntu 16 and Debian 8/9 supported"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function CheckSystemd {
|
||||
|
||||
if [ ! $(which systemctl) ]; then
|
||||
echo "This tool is implemented to work with systemd enabled systems only"
|
||||
exit 0
|
||||
fi
|
||||
if [ ! $(which systemctl) ]; then
|
||||
echo "This tool is implemented to work with systemd enabled systems only"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
CheckUser
|
||||
@@ -324,9 +330,9 @@ echo "OS: $OSNAME $OSVERSION"
|
||||
echo "Basedir: $INSTALLDIR"
|
||||
|
||||
if [ $XOUSER ]; then
|
||||
echo "User: $XOUSER"
|
||||
echo "User: $XOUSER"
|
||||
else
|
||||
echo "User: root"
|
||||
echo "User: root"
|
||||
fi
|
||||
|
||||
echo "Port: $PORT"
|
||||
@@ -338,50 +344,83 @@ echo "-----------------------------------------"
|
||||
echo
|
||||
echo "1. Install"
|
||||
echo "2. Update"
|
||||
echo "3. Exit"
|
||||
echo "3. Run with docker"
|
||||
echo "4. Exit"
|
||||
echo
|
||||
read -p ": " option
|
||||
|
||||
case $option in
|
||||
1)
|
||||
if [[ $(ps aux | grep xo-server | grep -v grep) ]]; then
|
||||
echo "Looks like xo-server process is already running, consider running update instead. Continue anyway?"
|
||||
read -p "[y/N]: " answer
|
||||
case $answer in
|
||||
y)
|
||||
case $option in
|
||||
1)
|
||||
if [[ $(ps aux | grep xo-server | grep -v grep) ]]; then
|
||||
echo "Looks like xo-server process is already running, consider running update instead. Continue anyway?"
|
||||
read -p "[y/N]: " answer
|
||||
case $answer in
|
||||
y)
|
||||
echo "Stopping xo-server..."
|
||||
/bin/systemctl stop xo-server || { echo "failed to stop service, exiting..." ; exit 1; }
|
||||
;;
|
||||
n)
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
n)
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ $OSNAME == "CentOS" ]; then
|
||||
InstallDependenciesCentOS
|
||||
InstallXO
|
||||
exit 0
|
||||
else
|
||||
InstallDependenciesDebian
|
||||
InstallXO
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
UpdateXO
|
||||
exit 0
|
||||
;;
|
||||
3)
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Please choose one of the options"
|
||||
echo
|
||||
exit 0
|
||||
;;
|
||||
if [ $OSNAME == "CentOS" ]; then
|
||||
InstallDependenciesCentOS
|
||||
InstallXO
|
||||
exit 0
|
||||
else
|
||||
InstallDependenciesDebian
|
||||
InstallXO
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
UpdateXO
|
||||
exit 0
|
||||
;;
|
||||
3)
|
||||
echo
|
||||
echo "Build image locally or fetch from docker hub?"
|
||||
echo "1. Build"
|
||||
echo "2. Pull"
|
||||
read -p ": " container
|
||||
case $container in
|
||||
1)
|
||||
echo
|
||||
docker build -t xen-orchestra $(dirname $0)/docker/image/.
|
||||
echo
|
||||
echo
|
||||
echo "Image built. Run container:"
|
||||
echo "docker run -itd -p 80:80 xen-orchestra"
|
||||
echo
|
||||
echo "If you want to persist xen-orchestra and redis data, use volume flags like:"
|
||||
echo "docker run -itd -p 80:80 -v /path/to/data/xo-server:/var/lib/xo-server -v /path/to/data/redis:/var/lib/redis xen-orchestra"
|
||||
;;
|
||||
2)
|
||||
echo
|
||||
docker pull ronivay/xen-orchestra
|
||||
echo
|
||||
echo
|
||||
echo "Image built. Run container:"
|
||||
echo "docker run -itd -p 80:80 ronivay/xen-orchestra"
|
||||
echo
|
||||
echo "If you want to persist xen-orchestra and redis data, use volume flags like:"
|
||||
echo "docker run -itd -p 80:80 -v /path/to/data/xo-server:/var/lib/xo-server -v /path/to/data/redis:/var/lib/redis ronivay/xen-orchestra"
|
||||
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
4)
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Please choose one of the options"
|
||||
echo
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
|
Reference in New Issue
Block a user