2014-11-13 10:06:16 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Register all Hâpy Cluster Nodes
|
|
|
|
#
|
|
|
|
|
|
|
|
. /usr/lib/eole/ihm.sh
|
|
|
|
|
|
|
|
#
|
2019-02-22 17:05:11 +01:00
|
|
|
# NAME: copy_ssh_id
|
2014-11-13 10:06:16 +01:00
|
|
|
# AIM: Copy the ssh key on the host
|
2019-02-22 17:05:11 +01:00
|
|
|
# PARAM: the hostname of the node
|
2014-11-13 10:06:16 +01:00
|
|
|
#
|
|
|
|
function copy_ssh_id()
|
|
|
|
{
|
2019-02-22 17:05:11 +01:00
|
|
|
local host=${1}
|
2016-10-14 15:57:04 +02:00
|
|
|
|
2019-02-22 17:05:11 +01:00
|
|
|
CLEF=$(cat ~oneadmin/.ssh/id_rsa.pub)
|
2019-02-27 11:34:34 +01:00
|
|
|
ssh ${host} bash <<EOF
|
2019-02-25 15:03:20 +01:00
|
|
|
if ! grep -qs "$CLEF" ~oneadmin/.ssh/authorized_keys; then
|
|
|
|
echo "$CLEF" >> ~oneadmin/.ssh/authorized_keys
|
2019-02-22 17:16:04 +01:00
|
|
|
chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys
|
2019-02-25 15:03:20 +01:00
|
|
|
su - oneadmin -c "ssh-keyscan $host"
|
|
|
|
cat ~oneadmin/.ssh/id_rsa.pub >> ~oneadmin/.ssh/authorized_keys
|
2016-10-14 15:57:04 +02:00
|
|
|
fi
|
|
|
|
EOF
|
2019-02-25 15:03:20 +01:00
|
|
|
[[ ${?} -ne 0 ]] && EchoRouge "Erreur lors de l'échange de clés SSH avec le noeud ${host}"
|
|
|
|
REMOTEKEY=$(su - oneadmin -c "ssh ${host} 'cat ~oneadmin/.ssh/id_rsa.pub'")
|
|
|
|
if ! grep -qs "$REMOTEKEY" ~oneadmin/.ssh/authorized_keys; then
|
|
|
|
su - oneadmin -c "echo ${REMOTEKEY} >> ~oneadmin/.ssh/authorized_keys"
|
2019-02-28 11:10:45 +01:00
|
|
|
su - oneadmin -c "ssh-keyscan $host"
|
2019-02-25 15:03:20 +01:00
|
|
|
fi
|
2014-11-13 10:06:16 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 15:45:40 +01:00
|
|
|
function copy_files()
|
|
|
|
{
|
|
|
|
local host=${1}
|
2019-02-25 16:18:40 +01:00
|
|
|
su - oneadmin -c "scp .one/* ${host}:.one/"
|
2019-02-25 15:45:40 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 11:34:34 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# NAME: sync_db
|
|
|
|
# AIM: Sync onedb in HA and sqlite mode
|
|
|
|
# PARAM: the hostname of the node
|
|
|
|
#
|
|
|
|
function sync_db()
|
|
|
|
{
|
|
|
|
local ip=${1}
|
2019-02-28 11:10:45 +01:00
|
|
|
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 ${?}
|
2019-02-27 11:34:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# NAME: sync_nodes
|
|
|
|
# AIM: force nodes sync with rsync (ONE 5.6.1 bug)
|
|
|
|
# PARAM: none
|
|
|
|
#
|
|
|
|
function sync_nodes()
|
|
|
|
{
|
2019-02-28 11:10:45 +01:00
|
|
|
# Need to sync hosts with rsync after creation, ONE 5.6.1 bug
|
|
|
|
cmd2="onehost sync -f --rsync"
|
|
|
|
ret2=$(su - ${ONEUSER} -c -- "${cmd2}")
|
|
|
|
return ${?}
|
2019-02-27 11:34:34 +01:00
|
|
|
}
|
|
|
|
|
2014-11-13 10:06:16 +01:00
|
|
|
#
|
|
|
|
# NAME: register_node
|
|
|
|
# AIM: register the node in OpenNebula master
|
|
|
|
# PARAM: the node hostname
|
|
|
|
#
|
|
|
|
function register_node()
|
|
|
|
{
|
2018-04-09 11:13:15 +02:00
|
|
|
cmd="onehost create -i kvm -v kvm -c 0 ${1}"
|
2019-02-27 11:34:34 +01:00
|
|
|
|
2014-11-13 10:06:16 +01:00
|
|
|
ret=$(su - ${ONEUSER} -c -- "${cmd}")
|
2019-02-25 12:11:30 +01:00
|
|
|
if [[ ${?} -ne 0 ]]
|
|
|
|
then
|
|
|
|
EchoRouge "Hosts register failed $res"
|
|
|
|
else
|
|
|
|
EchoVert "Hosts register OK"
|
|
|
|
fi
|
2014-11-13 10:06:16 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 11:52:47 +01:00
|
|
|
|
2014-11-13 10:06:16 +01:00
|
|
|
#
|
|
|
|
# NAME: wait_node_ok
|
|
|
|
# AIM: Wait until the node is OK or ERROR
|
2019-02-22 17:05:11 +01:00
|
|
|
# PARAM: The node name
|
2014-11-13 10:06:16 +01:00
|
|
|
#
|
|
|
|
function wait_node_ok()
|
|
|
|
{
|
|
|
|
local cmd="onehost show ${1} | awk '/^STATE/ {print \$3}'"
|
|
|
|
local spinstr='|/-\'
|
|
|
|
local delay=0.75
|
2019-02-25 15:03:20 +01:00
|
|
|
local cnt=0
|
2014-11-13 10:06:16 +01:00
|
|
|
|
|
|
|
while [ 1 ]
|
|
|
|
do
|
|
|
|
st=$(su - ${ONEUSER} -c "${cmd}")
|
|
|
|
[[ ${st} == "MONITORED" ]] && break
|
|
|
|
[[ ${st} == '' ]] && break
|
|
|
|
if [[ ${st} == "ERROR" ]]
|
|
|
|
then
|
2019-02-25 15:03:20 +01:00
|
|
|
if [ $cnt -gt 160 ]; then
|
|
|
|
EchoRouge "Erreur lors de l'enregistrement du noeud ${host} !"
|
|
|
|
break
|
|
|
|
fi
|
2014-11-13 10:06:16 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
local temp=${spinstr#?}
|
|
|
|
printf " [%c] " "$spinstr"
|
|
|
|
local spinstr=$temp${spinstr%"$temp"}
|
|
|
|
sleep $delay
|
|
|
|
printf "\b\b\b\b\b\b"
|
2019-02-25 15:03:20 +01:00
|
|
|
cnt=$((cnt+1))
|
2014-11-13 10:06:16 +01:00
|
|
|
done
|
|
|
|
printf " \b\b\b\b"
|
|
|
|
}
|
|
|
|
|
2019-02-25 12:11:30 +01:00
|
|
|
function init_ha_leader() {
|
|
|
|
# server with index 1 exists if already instanciate
|
|
|
|
onezone show 0 | grep -A 3 ^"HA & FEDERATION SYNC STATUS" | tail -n 1 | grep -q ^" 1 "
|
|
|
|
if [ ! $? = 0 ]; then
|
|
|
|
FOLLOWER=$(CreoleGet one_nodes)
|
|
|
|
for follower in $FOLLOWER; do
|
|
|
|
onezone server-add 0 --name $follower --rpc http://$follower:2633/RPC2
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-11-13 10:06:16 +01:00
|
|
|
#
|
|
|
|
# MAIN
|
|
|
|
#
|
|
|
|
HAPY_ACTIF=$(echo $(CreoleGet activer_onesinglenode))
|
|
|
|
if [[ $HAPY_ACTIF == "non" ]]
|
|
|
|
then
|
2019-02-22 17:16:04 +01:00
|
|
|
EchoRouge "Le serveur de virtualisation n'est pas activé dans l'interface de configuration du module"
|
|
|
|
exit 1
|
2014-11-13 10:06:16 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
HAPY_NODE_SUPPORT=$(echo $(CreoleGet activer_multinode))
|
|
|
|
if [[ $HAPY_NODE_SUPPORT == "non" ]]
|
|
|
|
then
|
2019-02-22 17:16:04 +01:00
|
|
|
EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
|
|
|
|
exit 1
|
2019-03-13 14:11:39 +01:00
|
|
|
<<<<<<< HEAD
|
2014-11-13 10:06:16 +01:00
|
|
|
fi
|
2019-02-27 11:34:34 +01:00
|
|
|
|
|
|
|
HAPY_HA=$(CreoleGet activer_one_ha "non")
|
|
|
|
|
2019-02-28 11:51:39 +01:00
|
|
|
master=1
|
|
|
|
if [[ ${HAPY_HA} == "oui" ]]; then
|
|
|
|
idx=$(CreoleGet one_ha_server_index)
|
|
|
|
if [[ ${idx} != "0" ]]; then
|
|
|
|
EchoBleu "Mode HA: (on) Index : [${idx}]"
|
|
|
|
echo -e "\t$(basename ${0}) doit être lancé uniquement sur le leader (index 0)"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
master=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-03-13 14:11:39 +01:00
|
|
|
=======
|
|
|
|
fi
|
|
|
|
|
|
|
|
HAPY_HA=$(CreoleGet activer_one_ha "non")
|
|
|
|
|
|
|
|
master=1
|
|
|
|
if [[ ${HAPY_HA} == "oui" ]]; then
|
|
|
|
idx=$(CreoleGet one_ha_server_index)
|
|
|
|
if [[ ${idx} != "0" ]]; then
|
|
|
|
EchoBleu "Mode HA: (on) Index : [${idx}]"
|
|
|
|
echo -e "\t$(basename ${0}) doit être lancé uniquement sur le leader (index 0)"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
master=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
>>>>>>> dcc8eeeecee5c5824e31c73b5ddf04590714f606
|
2014-11-13 10:06:16 +01:00
|
|
|
declare -a HAPY_SLV=('')
|
|
|
|
ONEUSER=$(CreoleGet virt_user)
|
|
|
|
HAPY_SLV=$(echo $(CreoleGet one_nodes) | sed -e "s/\n/ /g")
|
2019-02-27 11:34:34 +01:00
|
|
|
DBMODE=$(CreoleGet one_database_type "none")
|
2014-11-13 10:06:16 +01:00
|
|
|
|
|
|
|
echo -e "\n"
|
|
|
|
EchoBleu "Vous allez inscrire un noeud dans une grappe Hâpy"
|
|
|
|
EchoBleu "Pour ce faire vous devez vous munir du mot de passe de l'utilisateur 'oneadmin' de chacun des noeuds"
|
|
|
|
Question_ouinon "Voulez-vous commencer ?" 'True' "oui"
|
|
|
|
if [[ $? -ne 0 ]]
|
|
|
|
then
|
2019-02-22 17:16:04 +01:00
|
|
|
EchoOrange "Abandon de l'enregistrement"
|
|
|
|
exit 1
|
2014-11-13 10:06:16 +01:00
|
|
|
fi
|
|
|
|
|
2019-02-28 11:51:39 +01:00
|
|
|
|
2019-02-25 10:50:45 +01:00
|
|
|
for host in ${HAPY_SLV}; do
|
2014-11-13 10:06:16 +01:00
|
|
|
echo -e "\n"
|
2019-02-25 10:50:45 +01:00
|
|
|
EchoOrange "Traitement du noeud ${host}"
|
2014-11-13 10:06:16 +01:00
|
|
|
echo
|
|
|
|
EchoVert " * Gestion des clés SSH"
|
|
|
|
echo
|
2019-02-25 10:50:45 +01:00
|
|
|
copy_ssh_id ${host}
|
2019-02-25 15:45:40 +01:00
|
|
|
if [ $master = 0 ]; then
|
|
|
|
copy_files ${host}
|
2019-02-22 17:16:04 +01:00
|
|
|
fi
|
2016-10-14 15:57:04 +02:00
|
|
|
|
2014-11-13 10:06:16 +01:00
|
|
|
EchoVert " * Enregistrement du noeud"
|
2019-02-25 10:50:45 +01:00
|
|
|
register_node ${host}
|
2019-02-28 11:10:45 +01:00
|
|
|
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
|
2019-03-01 12:07:16 +01:00
|
|
|
if [[ ${HAPY_HA} != "oui" ]]
|
2019-03-13 14:11:39 +01:00
|
|
|
<<<<<<< HEAD
|
|
|
|
=======
|
2019-03-13 12:12:29 +01:00
|
|
|
then
|
2019-03-13 14:11:39 +01:00
|
|
|
>>>>>>> dcc8eeeecee5c5824e31c73b5ddf04590714f606
|
2019-03-01 12:07:16 +01:00
|
|
|
wait_node_ok ${HAPY_SLV[${i}]}
|
|
|
|
if [[ ${?} -ne 0 ]]
|
|
|
|
then
|
|
|
|
EchoRouge "Erreur lors de l'enregistrement du noeud ${HAPY_SLV[${i}]} !"
|
|
|
|
fi
|
2019-02-27 11:34:34 +01:00
|
|
|
fi
|
2014-11-13 10:06:16 +01:00
|
|
|
done
|
|
|
|
|
2019-02-25 12:11:30 +01:00
|
|
|
if [ $master = 0 ]; then
|
|
|
|
init_ha_leader
|
|
|
|
fi
|
2014-11-13 10:06:16 +01:00
|
|
|
echo -e "\n"
|
|
|
|
EchoVert "Enregistrement des noeuds terminé"
|