You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by av...@apache.org on 2024/12/27 11:17:51 UTC
(cloudberry) 12/13: Replace netstat with ss (code cleanup)
This is an automated email from the ASF dual-hosted git repository.
avamingli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit ace5385c486fc0b7a32b8d89d0a2eeb098e818e4
Author: Nihal Jain <jn...@vmware.com>
AuthorDate: Wed Sep 14 14:56:07 2022 +0530
Replace netstat with ss (code cleanup)
netstat has been replaced with ss earlier but some of the variable names and commented out codes were left as it is. This commit cleans up the old mentions of netstat and changes the variable names to avoid any confusion in the future.
---
gpMgmt/bin/gppylib/commands/gp.py | 6 +++---
gpMgmt/bin/gppylib/commands/unix.py | 4 ++--
gpMgmt/bin/gpstart | 10 +++++-----
gpMgmt/bin/lib/gp_bash_functions.sh | 30 ++++++++++++++----------------
gpMgmt/sbin/gpgetstatususingtransition.py | 12 ++++++------
5 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/gpMgmt/bin/gppylib/commands/gp.py b/gpMgmt/bin/gppylib/commands/gp.py
index 3ec845203a..4f9be6c993 100644
--- a/gpMgmt/bin/gppylib/commands/gp.py
+++ b/gpMgmt/bin/gppylib/commands/gp.py
@@ -1564,12 +1564,12 @@ def chk_local_db_running(datadir, port):
tmpfile_exists = os.path.exists("/tmp/.s.PGSQL.%d" % port)
lockfile_exists = os.path.exists(get_lockfile_name(port))
- netstat_port_active = PgPortIsActive.local('check ss for postmaster port',"/tmp/.s.PGSQL.%d" % port, port)
+ ss_port_active = PgPortIsActive.local('check ss for postmaster port',"/tmp/.s.PGSQL.%d" % port, port)
logger.debug("postmaster_pid_exists: %s tmpfile_exists: %s lockfile_exists: %s ss port: %s pid: %s" %\
- (postmaster_pid_exists, tmpfile_exists, lockfile_exists, netstat_port_active, pid_value))
+ (postmaster_pid_exists, tmpfile_exists, lockfile_exists, ss_port_active, pid_value))
- return (postmaster_pid_exists, tmpfile_exists, lockfile_exists, netstat_port_active, pid_value)
+ return (postmaster_pid_exists, tmpfile_exists, lockfile_exists, ss_port_active, pid_value)
def get_lockfile_name(port):
return "/tmp/.s.PGSQL.%d.lock" % port
diff --git a/gpMgmt/bin/gppylib/commands/unix.py b/gpMgmt/bin/gppylib/commands/unix.py
index fc0732ec81..08fbaabe0f 100644
--- a/gpMgmt/bin/gppylib/commands/unix.py
+++ b/gpMgmt/bin/gppylib/commands/unix.py
@@ -625,8 +625,8 @@ class PgPortIsActive(Command):
for r in rows:
val = r.split('.')
- netstatport = int(val[len(val) - 1])
- if netstatport == self.port:
+ ssport = int(val[len(val) - 1])
+ if ssport == self.port:
return True
return False
diff --git a/gpMgmt/bin/gpstart b/gpMgmt/bin/gpstart
index 6f6e8f6915..757e53ca40 100755
--- a/gpMgmt/bin/gpstart
+++ b/gpMgmt/bin/gpstart
@@ -392,17 +392,17 @@ class GpStart:
lockfile = "/tmp/.s.PGSQL.%s" % self.port
tmpfile_exists = os.path.exists(lockfile)
- netstat_port_active = unix.PgPortIsActive.local('check ss for coordinator port',
+ ss_port_active = unix.PgPortIsActive.local('check ss for coordinator port',
lockfile, self.port)
- if tmpfile_exists and netstat_port_active:
+ if tmpfile_exists and ss_port_active:
logger.info("Have lock file %s and a process running on port %s" % (lockfile, self.port))
raise ExceptionNoStackTraceNeeded("Coordinator instance process running")
- elif tmpfile_exists and not netstat_port_active:
+ elif tmpfile_exists and not ss_port_active:
logger.info("Have lock file %s but no process running on port %s" % (lockfile, self.port))
- elif not tmpfile_exists and netstat_port_active:
+ elif not tmpfile_exists and ss_port_active:
logger.info("No lock file %s but a process running on port %s" % (lockfile, self.port))
raise ExceptionNoStackTraceNeeded("Port %s is already in use" % self.port)
- elif not tmpfile_exists and not netstat_port_active:
+ elif not tmpfile_exists and not ss_port_active:
logger.info("No socket connection or lock file in /tmp found for port=%s" % self.port)
logger.info("No Coordinator instance process, entering recovery startup mode")
diff --git a/gpMgmt/bin/lib/gp_bash_functions.sh b/gpMgmt/bin/lib/gp_bash_functions.sh
index 9c1580bb52..528ec9ae29 100755
--- a/gpMgmt/bin/lib/gp_bash_functions.sh
+++ b/gpMgmt/bin/lib/gp_bash_functions.sh
@@ -857,32 +857,31 @@ GET_PG_PID_ACTIVE () {
PORT=$1;shift
HOST=$1
PG_LOCK_FILE="/tmp/.s.PGSQL.${PORT}.lock"
- PG_LOCK_NETSTAT=""
+ PG_LOCK_SS=""
if [ x"" == x"$HOST" ];then
- #See if we have a netstat entry for this local host
+ #See if we have a ss entry for this local host
PORT_ARRAY=(`$SS -an 2>/dev/null |$AWK '{for (i =1; i<=NF ; i++) if ($i==".s.PGSQL.${PORT}") print $i}'|$AWK -F"." '{print $NF}'|$SORT -u`)
for P_CHK in ${PORT_ARRAY[@]}
do
- if [ $P_CHK -eq $PORT ];then PG_LOCK_NETSTAT=$PORT;fi
+ if [ $P_CHK -eq $PORT ];then PG_LOCK_SS=$PORT;fi
done
- #PG_LOCK_NETSTAT=`$NETSTAT -an 2>/dev/null |$GREP ".s.PGSQL.${PORT}"|$AWK '{print $NF}'|$HEAD -1`
#See if we have a lock file in /tmp
if [ -f ${PG_LOCK_FILE} ];then
PG_LOCK_TMP=1
else
PG_LOCK_TMP=0
fi
- if [ x"" == x"$PG_LOCK_NETSTAT" ] && [ $PG_LOCK_TMP -eq 0 ];then
+ if [ x"" == x"$PG_LOCK_SS" ] && [ $PG_LOCK_TMP -eq 0 ];then
PID=0
LOG_MSG "[INFO]:-No socket connection or lock file in /tmp found for port=${PORT}"
else
#Now check the failure combinations
- if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
+ if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_SS" ];then
#Have a process but no lock file
LOG_MSG "[WARN]:-No lock file $PG_LOCK_FILE but process running on port $PORT" 1
PID=1
fi
- if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_NETSTAT" ];then
+ if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_SS" ];then
#Have a lock file but no process
if [ -r ${PG_LOCK_FILE} ];then
PID=`$CAT ${PG_LOCK_FILE}|$HEAD -1|$AWK '{print $1}'`
@@ -892,8 +891,8 @@ GET_PG_PID_ACTIVE () {
fi
LOG_MSG "[WARN]:-Have lock file $PG_LOCK_FILE but no process running on port $PORT" 1
fi
- if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
- #Have both a lock file and a netstat process
+ if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_SS" ];then
+ #Have both a lock file and a ss process
if [ -r ${PG_LOCK_FILE} ];then
PID=`$CAT ${PG_LOCK_FILE}|$HEAD -1|$AWK '{print $1}'`
else
@@ -911,21 +910,20 @@ GET_PG_PID_ACTIVE () {
PORT_ARRAY=($( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "$SS -an 2>/dev/null |$AWK '{for (i =1; i<=NF ; i++) if (\$i==\".s.PGSQL.${PORT}\") print \$i}'|$AWK -F\".\" '{print \$NF}'|$SORT -u"))
for P_CHK in ${PORT_ARRAY[@]}
do
- if [ $P_CHK -eq $PORT ];then PG_LOCK_NETSTAT=$PORT;fi
+ if [ $P_CHK -eq $PORT ];then PG_LOCK_SS=$PORT;fi
done
- #PG_LOCK_NETSTAT=`$TRUSTED_SHELL $HOST "$NETSTAT -an 2>/dev/null |$GREP ".s.PGSQL.${PORT}" 2>/dev/null"|$AWK '{print $NF}'|$HEAD -1`
PG_LOCK_TMP=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "ls ${PG_LOCK_FILE} 2>/dev/null|$WC -l" )
- if [ x"" == x"$PG_LOCK_NETSTAT" ] && [ $PG_LOCK_TMP -eq 0 ];then
+ if [ x"" == x"$PG_LOCK_SS" ] && [ $PG_LOCK_TMP -eq 0 ];then
PID=0
LOG_MSG "[INFO]:-No socket connection or lock file $PG_LOCK_FILE found for port=${PORT}"
else
#Now check the failure combinations
- if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
+ if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_SS" ];then
#Have a process but no lock file
LOG_MSG "[WARN]:-No lock file $PG_LOCK_FILE but process running on port $PORT on $HOST" 1
PID=1
fi
- if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_NETSTAT" ];then
+ if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_SS" ];then
#Have a lock file but no process
CAN_READ=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "if [ -r ${PG_LOCK_FILE} ];then echo 1;else echo 0;fi" )
@@ -937,8 +935,8 @@ GET_PG_PID_ACTIVE () {
LOG_MSG "[WARN]:-Have lock file $PG_LOCK_FILE but no process running on port $PORT on $HOST" 1
PID=1
fi
- if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
- #Have both a lock file and a netstat process
+ if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_SS" ];then
+ #Have both a lock file and a ss process
CAN_READ=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "if [ -r ${PG_LOCK_FILE} ];then echo 1;else echo 0;fi" )
if [ $CAN_READ -eq 1 ];then
PID=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "$CAT ${PG_LOCK_FILE}|$HEAD -1 2>/dev/null"|$AWK '{print $1}' )
diff --git a/gpMgmt/sbin/gpgetstatususingtransition.py b/gpMgmt/sbin/gpgetstatususingtransition.py
index efe229aa63..58b39636f2 100755
--- a/gpMgmt/sbin/gpgetstatususingtransition.py
+++ b/gpMgmt/sbin/gpgetstatususingtransition.py
@@ -119,17 +119,17 @@ class GpSegStatusProgram:
"""
lockFileExists = pidRunningStatus['lockFileExists']
- netstatPortActive = pidRunningStatus['netstatPortActive']
+ ssPortActive = pidRunningStatus['ssPortActive']
pidValue = pidRunningStatus['pidValue']
lockFileName = gp.get_lockfile_name(seg.getSegmentPort())
error = None
- if not lockFileExists and not netstatPortActive:
+ if not lockFileExists and not ssPortActive:
error = "No socket connection or lock file (%s) found for port %s" % (lockFileName, seg.getSegmentPort())
- elif not lockFileExists and netstatPortActive:
+ elif not lockFileExists and ssPortActive:
error = "No lock file %s but process running on port %s" % (lockFileName, seg.getSegmentPort())
- elif lockFileExists and not netstatPortActive:
+ elif lockFileExists and not ssPortActive:
error = "Have lock file %s but no process running on port %s" % (lockFileName, seg.getSegmentPort())
else:
if pidValue == 0:
@@ -145,14 +145,14 @@ class GpSegStatusProgram:
"""
Get an object containing various information about the postmaster pid's status
"""
- (postmasterPidFileExists, tempFileExists, lockFileExists, netstatPortActive, pidValue) = \
+ (postmasterPidFileExists, tempFileExists, lockFileExists, ssPortActive, pidValue) = \
gp.chk_local_db_running(seg.getSegmentDataDirectory(), seg.getSegmentPort())
return {
'postmasterPidFileExists' : postmasterPidFileExists,
'tempFileExists' : tempFileExists,
'lockFileExists' : lockFileExists,
- 'netstatPortActive' : netstatPortActive,
+ 'ssPortActive' : ssPortActive,
'pidValue' : pidValue
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org