From 73350f6451725d38ec980cce76493990fbe16f7c Mon Sep 17 00:00:00 2001 From: rafael Date: Tue, 7 Mar 2023 19:37:04 +0100 Subject: [PATCH] 10298 adding detailed info for general status for debbuging and fix some error codes --- pandora_server/util/pandora_server | 117 ++++++++++++++++------------- 1 file changed, 65 insertions(+), 52 deletions(-) diff --git a/pandora_server/util/pandora_server b/pandora_server/util/pandora_server index 4d9e3f0c38..1e612c968f 100755 --- a/pandora_server/util/pandora_server +++ b/pandora_server/util/pandora_server @@ -36,7 +36,6 @@ export PANDORA_HOME_EXTRA="/etc/pandora/conf.d" export PANDORA_DAEMON=/usr/bin/pandora_server export PANDORA_HA=/usr/bin/pandora_ha export PID_DIR=/var/run -export INCLUDE_EXTRA_CONFS=0 declare -A SERVERS_NAMES # Environment variables @@ -127,40 +126,64 @@ function extra_confs () { return 0 fi - # declare array - INCLUDE_EXTRA_CONFS=0 - # Loop all secondary servers confs for conf in ${EXTRA_CONF[@]} ; do + tmp_server_name=$(grep servername $PANDORA_HOME_EXTRA/$conf | grep -v '^#' | tail -1 | awk '{ print $2 }') + SERVERS_NAMES["$PANDORA_HOME_EXTRA/$conf"]=$tmp_server_name + done + + INCLUDE_EXTRA_CONFS=1 +} + +function check_extra_confs () { + [ "$1" ] || echo Error no defined conf found local tmp_server_name='' local mastery='' + tmp_server_name=$(grep servername $1 | grep -v '^#' | tail -1 | awk '{ print $2 }') # Check servername - tmp_server_name=$(grep servername $PANDORA_HOME_EXTRA/$conf | grep -v '^#' | tail -1 | awk '{ print $2 }') if [ "$tmp_server_name" == '' ]; then - echo "Error: The config file $conf has no sever name defined, servername is mandatory for secondary servers" + echo "Error: The config file $1 has no sever name defined, servername is mandatory for secondary servers" rc_exit fi if [ "$tmp_server_name" == "$SERVERS_NAMES[$PANDORA_HOME]" ]; then - echo "Error: The config file $PANDORA_HOME_EXTRA/$conf has the same servername as the primary server, servername should be unique for secondary servers" + echo "Error: The config file $1 has the same servername as the primary server, servername should be unique for secondary servers" rc_exit fi # check other confs servernames (todo) + local _count=0 + for name in ${!SERVERS_NAMES[@]}; do + [[ ${SERVERS_NAMES[$name]} == $tmp_server_name ]] && _count=`expr $_count + 1` + if [[ $_count -gt 1 ]] ; then + echo "Error: The config file $1 has the same servername as the another secondary server, servername should be unique for secondary servers" + rc_exit + fi + done # Check mastery - mastery=$(grep master $PANDORA_HOME_EXTRA/$conf | grep -v '^#' | tail -1 | awk '{ print $2 }') + mastery=$(grep master $1 | grep -v '^#' | tail -1 | awk '{ print $2 }') if [[ $mastery -ne 0 ]]; then - echo "Error: The config file $PANDORA_HOME_EXTRA/$conf has the same servername master value higer than 0, master should be disable for secondary servers" + echo "Error: The config file $1 has the same servername master value higer than 0, master should be disable for secondary servers" rc_exit fi - SERVERS_NAMES["$PANDORA_HOME_EXTRA/$conf"]=$tmp_server_name - - done - - INCLUDE_EXTRA_CONFS=1 +} + +function server_status () { + local _couter=0 + for key in ${!SERVERS_NAMES[@]}; do + unset SEC_PID + SEC_PID=$(pidof_secondary_server $key) + if [ -z "$SEC_PID" ] ; then + echo "${SERVERS_NAMES[$key]} ($key) Server is not running." + _couter=`expr $_couter + 1` + else + echo "${SERVERS_NAMES[$key]} ($key) Server is running with PID: $SEC_PID." + fi + done + [[ $_couter -gt 0 ]] && rc_failed 7 || rc_status -v } # Main script @@ -172,7 +195,7 @@ then rc_exit fi -extra_confs # check if extra confs are defined +extra_confs # check for config files case "$1" in start) @@ -236,42 +259,45 @@ case "$1" in if [ -z "$PANDORA_PID" ] then echo "$PANDORA_RB_PRODUCT_NAME HA is not running." - rc_failed 7 # program is not running + server_status + rc_failed 7 # program is not running else echo "$PANDORA_RB_PRODUCT_NAME HA is running with PID $PANDORA_PID." - rc_status + server_status + rc_status -v fi ;; start-server) - _couter=0 + _count=0 for key in ${!SERVERS_NAMES[@]}; do + [[ $key != "/etc/pandora/pandora_server.conf" ]] && check_extra_confs $key unset SEC_PID SEC_PID=$(pidof_secondary_server $key) if [ ! -z "$SEC_PID" ] ; then echo "${SERVERS_NAMES[$key]} ($key) Server is currently running on this machine with PID ($SEC_PID)." - _counter+=1 - fi - done - if [[ _counter -gt 0 ]]; then rc_exit ; fi # running start on a service already running - - export PERL_LWP_SSL_VERIFY_HOSTNAME=0 - _couter=0 - for key in ${!SERVERS_NAMES[@]}; do - $PANDORA_DAEMON $key -D - sleep 1 - unset SEC_PID - SEC_PID=$(pidof_secondary_server $key) - if [ ! -z "$SEC_PID" ] ; then - echo "${SERVERS_NAMES[$key]} Server is now running with PID $SEC_PID" - _counter+=1 + continue else - echo "Cannot ${SERVERS_NAMES[$key]} start Server. Aborted." - echo "Check ${SERVERS_NAMES[$key]} log files at /var/log/pandora/pandora_server.error & pandora_server.log" - echo "error" - rc_failed 7 # program is not running + + export PERL_LWP_SSL_VERIFY_HOSTNAME=0 + $PANDORA_DAEMON $key -D + sleep 1 + unset SEC_PID + SEC_PID=$(pidof_secondary_server $key) + if [ ! -z "$SEC_PID" ] ; then + echo "${SERVERS_NAMES[$key]} Server is now running with PID $SEC_PID" + else + echo "Cannot ${SERVERS_NAMES[$key]} start Server. Aborted." + echo "Check ${SERVERS_NAMES[$key]} log files at '/var/log/pandora/pandora_server.error' & 'pandora_server.log'" + _count=`expr $_count + 1` + fi fi done - if [[ _counter > 0 ]]; then rc_status -v ; fi + + if [[ _count -gt 0 ]]; then + rc_failed 7 + else + rc_status -v + fi ;; stop-server) @@ -307,20 +333,7 @@ case "$1" in rc_status -v ;; status-server) - _couter=0 - for key in ${!SERVERS_NAMES[@]}; do - unset SEC_PID - SEC_PID=$(pidof_secondary_server $key) - if [ -z "$SEC_PID" ] ; then - echo "${SERVERS_NAMES[$key]} ($key) Server is not running." - _counter+=1 - else - echo "${SERVERS_NAMES[$key]} ($key) Server is running with PID: $SEC_PID." - fi - done - if [[ _counter -gt 0 ]]; then rc_failed 7 ; fi # program is not running - rc_status # all running ok - + server_status ;; force-reload-server|restart-server) $0 stop-server