Manage sqlite sync and shared datastore in ha mode
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user