[script]fix端口占用误判

This commit is contained in:
tomsun28
2022-03-16 21:02:57 +08:00
parent 63fe51b597
commit 792d461844
2 changed files with 14 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ APPLICATION="${project.artifactId}"
APPLICATION_JAR="${project.build.finalName}.jar"
# 通过项目名称查找到PI然后kill -9 pid
PID=$(ps -ef | grep "${APPLICATION_JAR}" | grep -v grep | awk '{ print $2 }')
PID=$(ps -ef | grep java | grep "${APPLICATION_JAR}" | grep -v grep | awk '{ print $2 }')
if [[ -z "$PID" ]]
then
echo ${APPLICATION} is already stopped

View File

@@ -22,7 +22,7 @@ CONF_DIR=$DEPLOY_DIR/config
# 应用的端口号
SERVER_PORT=1157
PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'`
PIDS=`ps -ef | grep java | grep "$CONF_DIR" | awk '{print $2}'`
if [ "$1" = "status" ]; then
if [ -n "$PIDS" ]; then
echo "The $SERVER_NAME is running...!"
@@ -41,11 +41,21 @@ if [ -n "$PIDS" ]; then
fi
if [ -n "$SERVER_PORT" ]; then
SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
# linux 下查询端口是否占用
SERVER_PORT_COUNT=`netstat -tln | grep :$SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
echo "ERROR: netstat the $SERVER_NAME port $SERVER_PORT already used!"
exit 1
fi
# mac 下查询端口是否占用
LSOF_AVA=`command -v lsof | wc -l`
if [ $LSOF_AVA -gt 0 ]; then
SERVER_PORT_COUNT=`lsof -i:$SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: lsof the $SERVER_NAME port $SERVER_PORT already used!"
exit 1
fi
fi
fi
# 项目日志输出绝对路径