Manage sqlite sync and shared datastore in ha mode

This commit is contained in:
Philippe Caseiro 2019-02-27 11:34:34 +01:00
parent 3e641814cf
commit 36fae0773d
3 changed files with 92 additions and 18 deletions

View File

@ -264,10 +264,11 @@ function create_datastore()
{
ds_type="${1}"
ds_name="${2}"
local ha=$(CreoleGet activer_one_ha)
# ref https://dev-eole.ac-dijon.fr/issues/16797
#ds_cluster="${3}"
if [[ $(CreoleGet activer_multinode 2>&1) == 'oui' ]]
if [[ $(CreoleGet activer_multinode 2>&1) == 'oui' ]] && [[ ${ha} == "non" ]]
then
SYS_TM_MAD='ssh'
ISO_TM_MAD='ssh'
@ -331,13 +332,14 @@ function update_datastore()
local cmd="onedatastore"
local opt="show"
local multinode=$(CreoleGet activer_multinode 2>&1)
local ha=$(CreoleGet activer_one_ha)
ds_type=""
ds_mad=""
ds_name=""
TMPL_FILE=$(mktemp)
if [[ ${multinode} == 'oui' ]]
if [[ ${multinode} == 'oui' ]] && [[ ${ha} == "non" ]]
then
SYS_TM_MAD='ssh'
ISO_TM_MAD='ssh'
@ -484,8 +486,9 @@ function main()
# Création des Datastores
#
manage_datastores "${clst_name}"
}
main
main $@
exit 0

26
preservice/31-one-ha Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
HA=$(CreoleGet activer_one_ha non)
DBMODE=$(CreoleGet one_database_type "none")
LEADER_DB_FILE="/var/lib/one/one.db.leader"
DBFILE="/var/lib/one/one.db"
# If HA is enabled and a leader database file is present
# we restore the leader database.
if [[ ${HA} == "oui" ]] && [[ ${DBMODE} == "sqlite" ]]
then
if [[ -f ${LEADER_DB_FILE} ]]
then
if [[ $(CreoleGet one_ha_server_index) != "0" ]]
then
onedb restore --sqlite ${DBFILE} ${LEADER_DB_FILE} -f
if [[ $? -eq 0 ]]
then
rm ${LEADER_DB_FILE}
exit ${?}
fi
fi
fi
fi
exit 0

View File

@ -16,7 +16,7 @@ function copy_ssh_id()
local host=${1}
CLEF=$(cat ~oneadmin/.ssh/id_rsa.pub)
ssh ${host} bash -x <<EOF
ssh ${host} bash <<EOF
if ! grep -qs "$CLEF" ~oneadmin/.ssh/authorized_keys; then
echo "$CLEF" >> ~oneadmin/.ssh/authorized_keys
chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys
@ -37,6 +37,44 @@ function copy_files()
su - oneadmin -c "scp .one/* ${host}:.one/"
}
#
# NAME: sync_db
# AIM: Sync onedb in HA and sqlite mode
# PARAM: the hostname of the node
#
function sync_db()
{
local ip=${1}
local user="oneadmin"
local DBFILE="/var/lib/one/one.db"
local DBBCK="/tmp/one.db.bck"
local ret=0
if [[ ! -f ${DBBCK} ]]
then
cmd="onedb backup --sqlite ${DBFILE} ${DBBCK}"
ret=$(su - ${user} -c -- "${cmd}")
fi
cmd2="scp ${DBBCK} ${ip}:${DBFILE}.leader"
ret=$(su - ${user} -c -- "${cmd2}")
return ${?}
}
#
# NAME: sync_nodes
# AIM: force nodes sync with rsync (ONE 5.6.1 bug)
# PARAM: none
#
function sync_nodes()
{
# Need to sync hosts with rsync after creation, ONE 5.6.1 bug
cmd2="onehost sync -f --rsync"
ret2=$(su - ${ONEUSER} -c -- "${cmd2}")
return ${?}
}
#
# NAME: register_node
# AIM: register the node in OpenNebula master
@ -45,6 +83,7 @@ function copy_files()
function register_node()
{
cmd="onehost create -i kvm -v kvm -c 0 ${1}"
ret=$(su - ${ONEUSER} -c -- "${cmd}")
if [[ ${?} -ne 0 ]]
then
@ -54,19 +93,6 @@ function register_node()
fi
}
# Fix host creation error from 5.6.1 with sync methode rsync
function sync_host()
{
CMD="onehost"
OPT="sync -f --rsync"
res=$(su - ${ONEUSER} -c "${CMD} ${OPT}")
if [[ ${?} -ne 0 ]]
then
EchoRouge "Hosts sync failed $res"
else
EchoVert "Hosts sync OK"
fi
}
#
# NAME: wait_node_ok
@ -130,9 +156,13 @@ then
EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
exit 1
fi
HAPY_HA=$(CreoleGet activer_one_ha "non")
declare -a HAPY_SLV=('')
ONEUSER=$(CreoleGet virt_user)
HAPY_SLV=$(echo $(CreoleGet one_nodes) | sed -e "s/\n/ /g")
DBMODE=$(CreoleGet one_database_type "none")
echo -e "\n"
EchoBleu "Vous allez inscrire un noeud dans une grappe Hâpy"
@ -165,8 +195,23 @@ for host in ${HAPY_SLV}; do
EchoVert " * Enregistrement du noeud"
register_node ${host}
sync_host ${host}
# wait_node_ok ${host}
if [[ ${HAPY_HA} == "oui" ]]
then
if [[ $DBMODE == "sqlite" ]]
then
if [[ $(CreoleGet one_ha_server_index) == "0" ]]
then
sync_db ${host}
fi
fi
fi
sync_nodes
wait_node_ok ${HAPY_SLV[${i}]}
if [[ ${?} -ne 0 ]]
then
EchoRouge "Erreur lors de l'enregistrement du noeud ${HAPY_SLV[${i}]} !"
fi
done
if [ $master = 0 ]; then