2017-08-08 19:13:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Script to start khanat server
|
|
|
|
#
|
|
|
|
# Copyright : GNU/AGPLv3
|
|
|
|
#
|
|
|
|
# Created : 1 AUG 2017
|
|
|
|
# Created by : AleaJactaEst
|
|
|
|
|
|
|
|
declare -i IMAGE=1
|
|
|
|
declare -i BASICSERVER=0
|
|
|
|
declare -i KHANATSERVER=0
|
|
|
|
declare -i KHANATRESSOURCES=0
|
2017-08-27 14:38:04 +00:00
|
|
|
declare -i KHANATDATACLIENT=0
|
2017-08-08 19:13:59 +00:00
|
|
|
declare -i RYZOMRESSOURCES=0
|
|
|
|
declare -i LAUNCHKHANAT=1
|
|
|
|
declare -i DEBUG=0
|
|
|
|
declare -i AUTODETEC=1
|
|
|
|
declare -i STOPKHANAT=0
|
|
|
|
declare -i CLEANCONTAINERKHANAT=0
|
|
|
|
declare -i CONNECTSSHKHANAT=0
|
2017-08-27 14:38:04 +00:00
|
|
|
declare -i KHANAT_CLIENT_VERSION=1
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
declare IMAGEGENERICSERVER="server_generic_debian_jessie_x86_64"
|
|
|
|
declare IMAGEKHANATSERVER="server_khanat_debian_jessie_x86_64"
|
2017-08-29 21:08:14 +00:00
|
|
|
declare LOCALBUILDDIR="build/builder_khanat_debian_jessie_x86_64"
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat << EOF
|
|
|
|
usage:$0 [options]
|
|
|
|
script to build under docker
|
|
|
|
|
|
|
|
Step:
|
|
|
|
1) generate tar with khanat-ressources
|
|
|
|
2) generate tar with ryzom-ressources
|
|
|
|
3) create image basic server
|
|
|
|
4) create image khanat server
|
|
|
|
5) launch khanat server
|
|
|
|
|
|
|
|
options:
|
|
|
|
-h, --help : Show this help
|
|
|
|
-d, --debug : Show debug message
|
|
|
|
-b, --force-basic : Force create/recreate image basic server
|
|
|
|
-t, --force-tar-ressources : Generate TAR.GZ for khanat-ressources (look directory ../khanat-ressources)
|
2017-08-27 14:38:04 +00:00
|
|
|
-q, --force-tar-data-client : Generate TAR.GZ for khanat-data-client (look directory ../khanat-data-client)
|
2017-08-08 19:13:59 +00:00
|
|
|
-z, --force-tar-ryzom-ressources : Generate TAR.GZ in data khanat-code
|
|
|
|
-k, --force-khanat : Force create/recreate image khanat server
|
|
|
|
-n, --no-launch-khanat : Doesn't launch khanat server
|
|
|
|
-s, --stop-server : Stop server khanat
|
|
|
|
-c, --clean-container-khanat : Remove old server khanat (stopped)
|
|
|
|
--ssh : connect on khanat server (with ssh) [Exclusive action, can't execute other action]
|
2017-08-10 16:27:18 +00:00
|
|
|
--client-version=[INTEGER] : version client khanat (we need to communicate with our server)
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
Example :
|
|
|
|
cd [root Khanat directory]
|
|
|
|
./server.sh
|
|
|
|
./server.sh -k
|
|
|
|
./server.sh --ssh
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function msg_debug()
|
|
|
|
{
|
|
|
|
if [[ $DEBUG -ne 0 ]]
|
|
|
|
then
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") DEBUG - $*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function msg_info()
|
|
|
|
{
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") INFO - $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
function msg_error()
|
|
|
|
{
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - $*" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# MAIN
|
|
|
|
#
|
|
|
|
|
2017-08-29 21:08:14 +00:00
|
|
|
msg_info "START"
|
|
|
|
|
2017-08-08 19:13:59 +00:00
|
|
|
calldir="$(dirname $0)"
|
|
|
|
basedir=$(cd $calldir; pwd)
|
|
|
|
rootdir="$(dirname $(dirname $(dirname $(dirname $(dirname $(dirname ${basedir}))))))"
|
|
|
|
ressourcedir="$(dirname ${rootdir})/khanat-ressources"
|
2017-08-27 14:38:04 +00:00
|
|
|
dataclientdir="$(dirname ${rootdir})/khanat-data-client"
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
while test $# -gt 0
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
-d|--debug)
|
|
|
|
DEBUG=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--ssh)
|
|
|
|
CONNECTSSHKHANAT=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-c|--clean-container-khanat)
|
|
|
|
CLEANCONTAINERKHANAT=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-s|--stop-server)
|
|
|
|
STOPKHANAT=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-b|--force-basic)
|
|
|
|
BASICSERVER=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-n|--no-launch-khanat)
|
|
|
|
LAUNCHKHANAT=0
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-t|--force-tar-ressources)
|
|
|
|
KHANATRESSOURCES=1
|
|
|
|
shift
|
|
|
|
;;
|
2017-08-27 14:38:04 +00:00
|
|
|
-q|--force-tar-data-client)
|
|
|
|
KHANATDATACLIENT=1
|
|
|
|
shift
|
|
|
|
;;
|
2017-08-08 19:13:59 +00:00
|
|
|
-z|--force-tar-ryzom-ressources)
|
|
|
|
RYZOMRESSOURCES=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-k|--force-khanat)
|
|
|
|
KHANATSERVER=1
|
|
|
|
shift
|
|
|
|
;;
|
2017-08-10 16:27:18 +00:00
|
|
|
--client-version*)
|
|
|
|
KHANAT_CLIENT_VERSION="${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2017-08-08 19:13:59 +00:00
|
|
|
*)
|
|
|
|
msg_error "options '$1' not recoginze"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
function chrashed()
|
|
|
|
{
|
|
|
|
msg_error "BUILD FAILED (code:$?)"
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
trap chrashed EXIT
|
|
|
|
|
|
|
|
msg_debug "prg: $0"
|
|
|
|
|
|
|
|
docker -v 1>/dev/null
|
|
|
|
if [[ $? -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_error "docker not installed"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$(uname -m)" in
|
|
|
|
x86_64)
|
|
|
|
;;
|
|
|
|
i686)
|
|
|
|
msg_error "Bad Archi"
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
msg_error "Unknown archi : $(uname -m)"
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ $CONNECTSSHKHANAT -ne 0 ]]
|
|
|
|
then
|
|
|
|
listcontainer="$(docker ps -qf 'status=running' -f 'ancestor='"${IMAGEKHANATSERVER}"'')"
|
|
|
|
if [[ ${#listcontainer[@]} -eq 1 ]]
|
|
|
|
then
|
|
|
|
|
|
|
|
ipaddress=$(docker inspect --format="{{ .NetworkSettings.IPAddress }}" ${listcontainer[@]})
|
|
|
|
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no compil@$ipaddress
|
|
|
|
fi
|
|
|
|
trap '' EXIT
|
|
|
|
msg_info "END SSH"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $AUTODETEC -ne 0 ]]
|
|
|
|
then
|
|
|
|
if [[ $(docker images -f "reference=$IMAGEGENERICSERVER" | wc -l) -lt 2 ]]
|
|
|
|
then
|
|
|
|
BASICSERVER=1
|
|
|
|
fi
|
2017-08-27 14:38:04 +00:00
|
|
|
if [[ ! -f ${rootdir}/khanat-ressources.tar.gz ]]
|
2017-08-08 19:13:59 +00:00
|
|
|
then
|
|
|
|
KHANATRESSOURCES=1
|
|
|
|
fi
|
2017-08-27 14:38:04 +00:00
|
|
|
if [[ ! -f ${rootdir}/khanat-data-client.tar.gz ]]
|
|
|
|
then
|
|
|
|
KHANATDATACLIENT=1
|
|
|
|
fi
|
2017-08-08 19:13:59 +00:00
|
|
|
if [[ ! -f ${rootdir}/ryzom-ressources.tar.gz ]]
|
|
|
|
then
|
|
|
|
RYZOMRESSOURCES=1
|
|
|
|
fi
|
|
|
|
if [[ $(docker images -f "reference=$IMAGEKHANATSERVER" | wc -l) -lt 2 ]]
|
|
|
|
then
|
|
|
|
KHANATSERVER=1
|
|
|
|
fi
|
|
|
|
|
2017-08-29 21:08:14 +00:00
|
|
|
if [[ -f ${rootdir}/ryzomcore.tar.gz ]]
|
|
|
|
then
|
|
|
|
sumsrc=$(md5sum ${rootdir}/code/${LOCALBUILDDIR}/ryzomcore-0.12.0..tar.gz | awk '{print $1}')
|
|
|
|
sumdst=$(md5sum ${rootdir}/ryzomcore.tar.gz | awk '{print $1}')
|
|
|
|
else
|
|
|
|
sumsrc=1
|
|
|
|
sumdsr=2
|
|
|
|
fi
|
2017-08-09 22:34:14 +00:00
|
|
|
msg_debug "ryzomcore checksum src:$sumsrc dst:$sumdst"
|
|
|
|
if [[ "$sumsrc" != "$sumdst" ]]
|
|
|
|
then
|
|
|
|
msg_debug "copy ryzomcore"
|
|
|
|
cp ${rootdir}/code/${LOCALBUILDDIR}/ryzomcore-0.12.0..tar.gz ${rootdir}/ryzomcore.tar.gz || exit 2
|
|
|
|
KHANATSERVER=1
|
|
|
|
fi
|
|
|
|
fi
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
DIRBUILD="${rootdir}/code/${LOCALBUILDDIR}"
|
|
|
|
|
|
|
|
msg_debug "calldir: $calldir"
|
|
|
|
msg_debug "basedir: $basedir"
|
|
|
|
msg_debug "rootdir: $rootdir"
|
|
|
|
msg_debug "ressourcedir: $ressourcedir"
|
|
|
|
msg_debug "generate basic image: $BASICSERVER"
|
|
|
|
msg_debug "generate tar khanat ressources: $KHANATRESSOURCES"
|
2017-08-27 14:38:04 +00:00
|
|
|
msg_debug "generate tar khanat data client: $KHANATDATACLIENT"
|
2017-08-08 19:13:59 +00:00
|
|
|
msg_debug "generate tar ryzom ressources: $RYZOMRESSOURCES"
|
|
|
|
msg_debug "generate khanat image: $KHANATSERVER"
|
|
|
|
msg_debug "launch khanat: $LAUNCHKHANAT"
|
|
|
|
msg_debug "stop khanat: $STOPKHANAT"
|
|
|
|
|
|
|
|
if [[ $KHANATRESSOURCES -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "$(date "+%Y/%m/%d %H:%M:%S") CREATE TAR with KHANAT Ressources"
|
|
|
|
if [[ ! -d ${ressourcedir} ]]
|
|
|
|
then
|
|
|
|
msg_error "Missing khanat-ressources directory ($ressourcedir)"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
(cd $ressourcedir; tar --exclude='.git' -czf ${rootdir}/khanat-ressources.tar.gz .) || exit 2
|
|
|
|
fi
|
|
|
|
|
2017-08-27 14:38:04 +00:00
|
|
|
if [[ $KHANATDATACLIENT -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "$(date "+%Y/%m/%d %H:%M:%S") CREATE TAR with KHANAT DATA CLIENT"
|
|
|
|
if [[ ! -d ${dataclientdir} ]]
|
|
|
|
then
|
|
|
|
msg_error "Missing khanat-data-client directory ($dataclientdir)"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
(cd $dataclientdir; tar --exclude='.git' -czf ${rootdir}/khanat-data-client.tar.gz .) || exit 2
|
|
|
|
fi
|
|
|
|
|
2017-08-08 19:13:59 +00:00
|
|
|
if [[ $RYZOMRESSOURCES -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "CREATE TAR with RYZOM Ressources"
|
|
|
|
if [[ ! -d ${ressourcedir} ]]
|
|
|
|
then
|
|
|
|
msg_error "Missing khanat-ressources directory ($ressourcedir)"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
cd ${rootdir}; tar czf ryzom-ressources.tar.gz \
|
|
|
|
code/ryzom/server/shard.screen.rc \
|
|
|
|
code/ryzom/common/* \
|
|
|
|
code/ryzom/client/* \
|
|
|
|
code/ryzom/server/* \
|
|
|
|
code/ryzom/tools/scripts/linux/* \
|
|
|
|
code/web/* || exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $STOPKHANAT -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "STOP SERVER KHANAT"
|
|
|
|
listcontainer="$(docker ps -qf 'status=running' -f 'ancestor='"${IMAGEKHANATSERVER}"'')"
|
|
|
|
msg_debug "CONTAINER KHANAT UP : ${listcontainer[@]}"
|
|
|
|
if [[ -n "$listcontainer" ]]
|
|
|
|
then
|
|
|
|
docker stop "$listcontainer" || exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $CLEANCONTAINERKHANAT -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "CLEAN CONTAINER KHANAT"
|
|
|
|
listcontainer=( $(docker ps -qf 'status=exited' -f 'ancestor='"${IMAGEKHANATSERVER}"'') )
|
|
|
|
msg_debug "CONTAINER KHANAT EXITED : ${listcontainer[@]}"
|
|
|
|
if [[ -n "${listcontainer[@]}" ]]
|
|
|
|
then
|
|
|
|
docker rm --force "${listcontainer[@]}" || exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $BASICSERVER -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "GENERATE DOCKER IMAGE BASIC SERVER"
|
|
|
|
cd $rootdir; docker build . -t ${IMAGEGENERICSERVER} \
|
|
|
|
--file "${basedir}/Dockerfile" || exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $KHANATSERVER -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "GENERATE DOCKER IMAGE KHANAT SERVER"
|
2017-08-10 16:27:18 +00:00
|
|
|
cat << EOF > $rootdir/todelete.sh
|
|
|
|
#!/bin/bash
|
|
|
|
# Temporary file, use only to send some information on build docker
|
|
|
|
export KHANAT_CLIENT_VERSION=$KHANAT_CLIENT_VERSION
|
|
|
|
EOF
|
2017-08-08 19:13:59 +00:00
|
|
|
cd $rootdir; docker build . -t ${IMAGEKHANATSERVER} \
|
|
|
|
--file "${basedir}/Dockerfile.khanat" || exit 2
|
2017-08-10 16:27:18 +00:00
|
|
|
rm $rootdir/todelete.sh
|
2017-08-08 19:13:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $LAUNCHKHANAT -ne 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "START KHANAT SERVER"
|
|
|
|
cd $rootdir; docker run -it --hostname=khanat ${IMAGEKHANATSERVER} /opt/autostart.sh
|
2017-08-10 16:27:18 +00:00
|
|
|
clear
|
2017-08-08 19:13:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
trap '' EXIT
|
|
|
|
msg_info "END"
|