From 859d8f3cb7ff7d812bf610cdf808af89318cd6dd Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 25 Feb 2019 15:03:20 +0100 Subject: [PATCH] update onehost_create_all --- scripts/onehost_create_all | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/onehost_create_all b/scripts/onehost_create_all index 5849706..746fce7 100755 --- a/scripts/onehost_create_all +++ b/scripts/onehost_create_all @@ -16,15 +16,19 @@ function copy_ssh_id() local host=${1} CLEF=$(cat ~oneadmin/.ssh/id_rsa.pub) - ssh ${host} bash -s <> ~oneadmin/.ssh/authorized_keys + ssh ${host} bash -x <> ~oneadmin/.ssh/authorized_keys chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys + su - oneadmin -c "ssh-keyscan $host" + cat ~oneadmin/.ssh/id_rsa.pub >> ~oneadmin/.ssh/authorized_keys fi EOF - su - oneadmin -c "ssh-keyscan $host" - return ${?} + [[ ${?} -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" + fi } # @@ -65,10 +69,10 @@ function sync_host() # function wait_node_ok() { - local RET=0 local cmd="onehost show ${1} | awk '/^STATE/ {print \$3}'" local spinstr='|/-\' local delay=0.75 + local cnt=0 while [ 1 ] do @@ -77,8 +81,10 @@ function wait_node_ok() [[ ${st} == '' ]] && break if [[ ${st} == "ERROR" ]] then - RET=50 - break + if [ $cnt -gt 160 ]; then + EchoRouge "Erreur lors de l'enregistrement du noeud ${host} !" + break + fi fi local temp=${spinstr#?} @@ -86,10 +92,9 @@ function wait_node_ok() local spinstr=$temp${spinstr%"$temp"} sleep $delay printf "\b\b\b\b\b\b" - + cnt=$((cnt+1)) done printf " \b\b\b\b" - return ${RET} } function init_ha_leader() { @@ -135,7 +140,7 @@ fi follower=1 master=1 -if [ "$(CreoleGet activer_one_ha)" = "oui" ]; +if [ "$(CreoleGet activer_one_ha)" = "oui" ]; then if [ "$(CreoleGet one_ha_server_index)" != "0" ]; then follower=0 else @@ -149,7 +154,6 @@ for host in ${HAPY_SLV}; do EchoVert " * Gestion des clés SSH" echo copy_ssh_id ${host} - [[ ${?} -ne 0 ]] && EchoRouge "Erreur lors de l'échange de clés SSH avec le noeud ${host}" if [ $follower = 0 ]; then continue fi @@ -158,10 +162,6 @@ for host in ${HAPY_SLV}; do register_node ${host} sync_host ${host} wait_node_ok ${host} - if [[ ${?} -ne 0 ]] - then - EchoRouge "Erreur lors de l'enregistrement du noeud ${host} !" - fi done if [ $master = 0 ]; then