10298 adding detailed info for general status for debbuging and fix some error codes

This commit is contained in:
rafael 2023-03-07 19:37:04 +01:00
parent 88316a5c83
commit 73350f6451

View File

@ -36,7 +36,6 @@ export PANDORA_HOME_EXTRA="/etc/pandora/conf.d"
export PANDORA_DAEMON=/usr/bin/pandora_server export PANDORA_DAEMON=/usr/bin/pandora_server
export PANDORA_HA=/usr/bin/pandora_ha export PANDORA_HA=/usr/bin/pandora_ha
export PID_DIR=/var/run export PID_DIR=/var/run
export INCLUDE_EXTRA_CONFS=0
declare -A SERVERS_NAMES declare -A SERVERS_NAMES
# Environment variables # Environment variables
@ -127,40 +126,64 @@ function extra_confs () {
return 0 return 0
fi fi
# declare array
INCLUDE_EXTRA_CONFS=0
# Loop all secondary servers confs # Loop all secondary servers confs
for conf in ${EXTRA_CONF[@]} ; do 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 tmp_server_name=''
local mastery='' local mastery=''
tmp_server_name=$(grep servername $1 | grep -v '^#' | tail -1 | awk '{ print $2 }')
# Check servername # Check servername
tmp_server_name=$(grep servername $PANDORA_HOME_EXTRA/$conf | grep -v '^#' | tail -1 | awk '{ print $2 }')
if [ "$tmp_server_name" == '' ]; then 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 rc_exit
fi fi
if [ "$tmp_server_name" == "$SERVERS_NAMES[$PANDORA_HOME]" ]; then 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 rc_exit
fi fi
# check other confs servernames (todo) # 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 # 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 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 rc_exit
fi fi
SERVERS_NAMES["$PANDORA_HOME_EXTRA/$conf"]=$tmp_server_name }
done function server_status () {
local _couter=0
INCLUDE_EXTRA_CONFS=1 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 # Main script
@ -172,7 +195,7 @@ then
rc_exit rc_exit
fi fi
extra_confs # check if extra confs are defined extra_confs # check for config files
case "$1" in case "$1" in
start) start)
@ -236,42 +259,45 @@ case "$1" in
if [ -z "$PANDORA_PID" ] if [ -z "$PANDORA_PID" ]
then then
echo "$PANDORA_RB_PRODUCT_NAME HA is not running." 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 else
echo "$PANDORA_RB_PRODUCT_NAME HA is running with PID $PANDORA_PID." echo "$PANDORA_RB_PRODUCT_NAME HA is running with PID $PANDORA_PID."
rc_status server_status
rc_status -v
fi fi
;; ;;
start-server) start-server)
_couter=0 _count=0
for key in ${!SERVERS_NAMES[@]}; do for key in ${!SERVERS_NAMES[@]}; do
[[ $key != "/etc/pandora/pandora_server.conf" ]] && check_extra_confs $key
unset SEC_PID unset SEC_PID
SEC_PID=$(pidof_secondary_server $key) SEC_PID=$(pidof_secondary_server $key)
if [ ! -z "$SEC_PID" ] ; then if [ ! -z "$SEC_PID" ] ; then
echo "${SERVERS_NAMES[$key]} ($key) Server is currently running on this machine with PID ($SEC_PID)." echo "${SERVERS_NAMES[$key]} ($key) Server is currently running on this machine with PID ($SEC_PID)."
_counter+=1 continue
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
else 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" export PERL_LWP_SSL_VERIFY_HOSTNAME=0
echo "error" $PANDORA_DAEMON $key -D
rc_failed 7 # program is not running 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 fi
done done
if [[ _counter > 0 ]]; then rc_status -v ; fi
if [[ _count -gt 0 ]]; then
rc_failed 7
else
rc_status -v
fi
;; ;;
stop-server) stop-server)
@ -307,20 +333,7 @@ case "$1" in
rc_status -v rc_status -v
;; ;;
status-server) status-server)
_couter=0 server_status
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
;; ;;
force-reload-server|restart-server) force-reload-server|restart-server)
$0 stop-server $0 stop-server