HEX
Server: Apache
System: Linux a16-asgard6.hospedagemuolhost.com.br 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: maoristu4c3dbd03 (1436)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //proc/self/root/opt/VRTSpbx/bin/vxpbx_exchanged
#!/bin/sh
# $Copyright: Copyright (c) 2023 Veritas Technologies LLC. All rights reserved $
#
#
# The Licensed Software and Documentation are deemed to be commercial
# computer software as defined in FAR 12.212 and subject to restricted
# rights as defined in FAR Section 52.227-19 "Commercial Computer
# Software - Restricted Rights" and DFARS 227.7202, "Rights in
# Commercial Computer Software or Commercial Computer Software
# Documentation", as applicable, and any successor regulations. Any use,
# modification, reproduction release, performance, display or disclosure
# of the Licensed Software and Documentation by the U.S. Government
# shall be solely in accordance with the terms of this Agreement.  $

# setting the variables.
#
# vxpbx_exchanged       Bring up/down Veritas Private Branch Exchange
#
# chkconfig: 2345 20 80
# description: Provides Veritas Private Branch Exchange
PATH=$PATH:/usr/bin:/bin:/usr/local/bin
export PATH

PLATFORM=`uname`
PBXROOT=/opt/VRTSpbx

RETCODE=0
script=$0
option=$1

# if no options are given use the script name 
# to guess the intended usage.
if [ "x$option" = "x" ]; then
    case "$script" in
        *K45*pbx*)
            option="stop"
            ;;
        *S45*pbx*)
            option="start"
            ;;
    esac
fi

CURR_ZONE=NOT_APPLICABLE
if [ "SunOS" = "$PLATFORM" ] ; then
        if [ -f /usr/bin/zonename ] ; then
               CURR_ZONE=`/usr/bin/zonename`
        fi
fi
CURR_WPAR=NOT_APPLICABLE
if [ "AIX" = "$PLATFORM" ] ; then
       if [ "`uname -v`" = "6" ] ; then
	   CURR_WPAR="`uname -W`"
       fi
fi
# ps command path.

PS="ps -ef"
GREP=grep
CAT=cat
AWK=awk
if [ "FreeBSD" = "$PLATFORM" ] ; then
        PS="ps -axf -o comm -o pid -o command "
	GREP=grep
	CAT=cat
	AWK=awk
else
    if [ "SunOS" = "$PLATFORM" -a "`uname -r`" = "5.10" -a "$CURR_ZONE" = "global" ] ; then
             PS="/usr/bin/ps -f -z 0"
    fi
    if [ "SunOS" = "$PLATFORM" -a "`uname -r`" = "5.11" -a "$CURR_ZONE" = "global" ] ; then
             PS="/usr/bin/ps -f -z 0"
    fi
	if [ "AIX" = "$PLATFORM" -a "`uname -v`" = "6" -a "x$CURR_WPAR" = "x0" ] ; then
	         PS="/usr/bin/ps -ef -F \"user pid args\" -@ Global"
		 PS="eval $PS"
	fi
fi

# set the ld load path.
case "$PLATFORM" in
		AIX)
				LIBPATH=$PBXROOT/lib
				export LIBPATH; 
				;;
		HP-UX)
				SHLIB_PATH=$PBXROOT/lib
				export SHLIB_PATH; 
				LD_LIBRARY_PATH=$PBXROOT/lib
				export LD_LIBRARY_PATH;
				;;
		Darwin)
				DYLD_LIBRARY_PATH=$PBXROOT/lib
				export DYLD_LIBRARY_PATH;
				;;
		FreeBSD)
				# This can be removed once $ORIGIN starts working.
				compat_dir=""
				os_major=`uname -r | cut -f1 -d"."`
				if [ "${os_major}" -gt 6 ] ; then
					compat_dir=":/usr/local/lib/compat"
				fi
				ProcessorType=`uname -p`
				if [ "${ProcessorType}" != "i386" ] ; then
					LD_32_LIBRARY_PATH="$PBXROOT/lib:/usr/local/lib32/compat${compat_dir}"
					export LD_32_LIBRARY_PATH
				else
					LD_LIBRARY_PATH="$PBXROOT/lib${compat_dir}"
					export LD_LIBRARY_PATH
				fi
				;;
		*)
				LD_LIBRARY_PATH=$PBXROOT/lib
				export LD_LIBRARY_PATH;
				;;
esac;   

# do a test of the required binaries.
if [ ! -f $PBXROOT/bin/pbx_exchange ]; then
		echo "Veritas PBX Exchange daemon not found on this host.";
		exit 1;
fi;

if [ -f $PBXROOT/bin/pbxcfg ]; then
#Cant rely on output of pbxcfg as this will be localized output and is no longer just a number
		PBX_CLUSTERED=`$CAT /etc/vx/VxICS/VxPBX.cfg | $GREP \"ClusterEnabled\"=\"1\"`
#		PBX_CLUSTERED=`$PBXROOT/bin/pbxcfg -p -C 2> /dev/null`
fi;

if [ -z "$PBX_CLUSTERED" ]; then PBX_CLUSTERED=0; fi;

restart_exchange () {
	# Some machines may use older version of UNIX shell which we can't
	# use "for loop" in the simple format as "for i in {1..15}"
	for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
		PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
		if [ "$PID" ]; then
			if [ 6 -gt $i ]; then
				kill -15 $PID >/dev/null 2>&1
				sleep 1;
			else
				kill -9 $PID >/dev/null 2>&1
				sleep 5;
			fi
		else
			$PBXROOT/bin/cluster/monitor_server localhost 1556 pbx_monitor 2> /dev/null
			if [ $? -eq 0 ] 
			then
				echo "Could not stop Veritas Private Branch Exchange.";
				return 1;
			else
				break;
			fi
		fi	
	done
	PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
	if [ "$PID" ]; then
		echo "Could not stop Veritas Private Branch Exchange: time out reached.";
		return 1;
	fi
	$PBXROOT/bin/pbx_exchange
	STATUS=$?;
	if [ $STATUS -ne 0 ]
	then
		echo "Could not start PBX Exchange.";
		return 1;
	fi
	# Some machines may use older version of UNIX shell which we can't
	# use "for loop" in the simple format as "for i in {1..15}"	
	for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
		PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
		if [ -z "$PID" ]; then
			sleep 1;
		else
			break;
		fi
	done
	PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
	if [ -z "$PID" ]; then
		echo "Could not start PBX Exchange: time out reached.";
		return 1;
	fi	
}



kill_exchange () {
	# Some machines may use older version of UNIX shell which we can't
	# use "for loop" in the simple format as "for i in {1..15}"
	for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
		PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
		if [ "$PID" ]; then
			if [ 6 -gt $i ]; then
				kill -15 $PID  >/dev/null 2>&1
				sleep 1;
			else
				kill -9 $PID >/dev/null 2>&1
				sleep 5;
			fi
		elif [ "1" = "$i" ]; then
			echo "No running instance of Veritas Private Branch Exchange to stop.";
			return 0;
		else
			$PBXROOT/bin/cluster/monitor_server localhost 1556 pbx_monitor 2> /dev/null
			if [ $? -eq 0 ] 
			then
				echo "Could not stop Veritas Private Branch Exchange.";
				return 1;
			else
				if [ ! "$PLATFORM" = "HP-UX" ] ; then
					echo "Stopped Veritas Private Branch Exchange";
				fi
				return 0;
			fi
		fi	
	done
	PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
	if [ "$PID" ]; then	
		echo "Could not stop Veritas Private Branch Exchange: time out reached.";
		return 1;
	fi
}

start_exchange () {
	PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
	if [ "$PID" ]; then
		echo "Instance of pbx is already running. Stop it first.";
		return 0;
	else
		$PBXROOT/bin/pbx_exchange
		STATUS=$?;
		if [ $STATUS -eq 0 ]
		then
			# Some machines may use older version of UNIX shell which we can't
			# use "for loop" in the simple format as "for i in {1..15}"
			for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
				PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
				if [ -z "$PID" ]; then
					sleep 1;
				else
					break;
				fi
			done
			PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
			if [ -z "$PID" ]; then
				echo "Could not start PBX Exchange: time out reached.";
				return 1;
			fi	
			if [ ! "$PLATFORM" = "HP-UX" ] ; then 
				echo "Started Veritas Private Branch Exchange";
			fi
		else 
			echo "Could not start PBX Exchange.";
			return 1;
		fi
	fi
}

# the main switch case.
case "$option" in
    start_msg)
		echo "Starting Veritas Private Branch Exchange ";
		;;
    start)
        if [ "$PBX_CLUSTERED" = "0" ]; then
						start_exchange;
						RETCODE=$?;
           if [ $RETCODE -eq 0 ] ; then
               if [ "Linux" = "$PLATFORM" ] ; then
		   if [ -d /var/lock/subsys ] ; then
		       touch /var/lock/subsys/vxpbx_exchanged
		   fi
               fi
           fi
        else
            echo "pbx_exchange is configured to work in a cluster."
            echo "Please use the cluster manager to start exchange."
        fi;
        ;;
    startincluster)
        					start_exchange;
        					RETCODE=$?;
        ;;
    stop_msg)
		echo "Stopping Veritas Private Branch Exchange ";
		;;
    stop)
				if [ "$PBX_CLUSTERED" = "0" ]; then 
						kill_exchange;
						RETCODE=$?;
          if [ $RETCODE -eq 0 ] ; then
               if [ "Linux" = "$PLATFORM" ] ; then
		   if [ -f /var/lock/subsys/vxpbx_exchanged ] ; then
		       rm -f /var/lock/subsys/vxpbx_exchanged
		   fi
               fi
          fi
        else
            echo "pbx_exchange is configured to work in a cluster."
            echo "Please use the cluster manager to stop exchange."
        fi;   
        ;;
    restart)
	if [ "$PBX_CLUSTERED" = "0" ]; then 
            restart_exchange
	    RETCODE=$?;
	    if [ $RETCODE -eq 0 ]
		then
		echo "Restarted Veritas Private Branch Exchange";
	    fi
        else
            echo "pbx_exchange is configured to work in a cluster."
            echo "Please use the cluster manager to restart exchange."
        fi;   
	;;
    try-restart)
	if [ "$PBX_CLUSTERED" = "0" ]; then 
            PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
            if [ "$PID" ]; then
                restart_exchange
                RETCODE=$?;
		if [ $RETCODE -eq 0 ]
		    then
		    echo "Restarted Veritas Private Branch Exchange";
		fi
            else
                echo "Veritas Private Branch Exchange is not running";
                RETCODE=7
            fi
        else
            echo "pbx_exchange is configured to work in a cluster."
            echo "Please use the cluster manager to restart exchange."
        fi;   
	;;
    reload)
	echo "Presently 'reload' operation is not supported";
        RETCODE=3
	;;
    force-reload)
	if [ "$PBX_CLUSTERED" = "0" ]; then 
	    PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
	    if [ "$PID" ]; then
		restart_exchange
		RETCODE=$?;
		if [ $RETCODE = 0 ]
		    then
		    echo "Reloaded configuration by restarting Veritas Private Branch Exchange";
		fi
	    else
		echo "Veritas Private Branch Exchange is not running"
                RETCODE=7
	    fi
        else
            echo "pbx_exchange is configured to work in a cluster."
            echo "Please use the cluster manager to restart exchange."
        fi;   
	;;
    status)
        PID=`$PS | $GREP "$PBXROOT/bin/pbx_exchange"| $GREP -v 'grep' | $GREP -v pbx_exchanged | $AWK '{print $2}'`
        if [ "$PID" ] 
        then
	    RETCODE=0
            echo "Veritas Private Branch Exchange is running"
	else
	    RETCODE=3
            echo "Veritas Private Branch Exchange is not running"
	fi
	;;
    stopincluster)
		kill_exchange;
		RETCODE=$?;
	;;
    *)
        echo "Usage: $0 { start | stop | restart | try-restart | reload | force-reload | status }";
        ;;
esac
exit $RETCODE;