diff --git a/postservice/99-z-ha b/postservice/99-z-ha index f437830..88b70d4 100644 --- a/postservice/99-z-ha +++ b/postservice/99-z-ha @@ -1,5 +1,15 @@ #!/bin/bash -/usr/share/eole/sbin/onehost_create_all +ha=$(CreoleGet activer_one_ha non) +if [[ ${ha} == "oui" ]] +then + indx=$(CreoleGet one_ha_server_index) +else + indx="0" +fi +if [[ ${1} == "instance" ]] && [[ ${indx} == "0" ]] +then + /usr/share/eole/sbin/onehost_create_all +fi exit 0 diff --git a/scripts/onehost_create_all b/scripts/onehost_create_all index 253fb63..af8a690 100755 --- a/scripts/onehost_create_all +++ b/scripts/onehost_create_all @@ -28,6 +28,7 @@ EOF 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" + su - oneadmin -c "ssh-keyscan $host" fi } @@ -46,20 +47,20 @@ function copy_files() 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 + 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 + 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 ${?} + cmd2="scp ${DBBCK} ${ip}:${DBFILE}.leader" + ret=$(su - ${user} -c -- "${cmd2}") + return ${?} } # @@ -69,10 +70,10 @@ function sync_db() # 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 ${?} + # Need to sync hosts with rsync after creation, ONE 5.6.1 bug + cmd2="onehost sync -f --rsync" + ret2=$(su - ${ONEUSER} -c -- "${cmd2}") + return ${?} } # @@ -159,6 +160,18 @@ 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 + declare -a HAPY_SLV=('') ONEUSER=$(CreoleGet virt_user) HAPY_SLV=$(echo $(CreoleGet one_nodes) | sed -e "s/\n/ /g") @@ -174,14 +187,7 @@ then exit 1 fi -master=1 -if [ "$(CreoleGet activer_one_ha)" = "oui" ]; then - if [ "$(CreoleGet one_ha_server_index)" != "0" ]; then - exit 0 - else - master=0 - fi -fi + for host in ${HAPY_SLV}; do echo -e "\n" EchoOrange "Traitement du noeud ${host}" @@ -196,17 +202,17 @@ for host in ${HAPY_SLV}; do EchoVert " * Enregistrement du noeud" register_node ${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 + 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