Просмотр исходного кода

Update v-list-sys-services (#4070)

Fixed issue when getting pids from pgrep and then using awk to get the main pid
sahsanu 2 лет назад
Родитель
Сommit
059f7d6fcd
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      bin/v-list-sys-services

+ 7 - 1
bin/v-list-sys-services

@@ -91,8 +91,10 @@ get_srv_state() {
 	else
 	else
 		pids=$(pidof -x $name | tr ' ' '|')
 		pids=$(pidof -x $name | tr ' ' '|')
 	fi
 	fi
+	used_pgrep=0
 	if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then
 	if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then
 		pids=$(pgrep $name | tr '\n' '|')
 		pids=$(pgrep $name | tr '\n' '|')
+		used_pgrep=1
 	fi
 	fi
 
 
 	# Prevent from an SSH false positive when there is a TTY or SFTP connection but service is down
 	# Prevent from an SSH false positive when there is a TTY or SFTP connection but service is down
@@ -102,7 +104,11 @@ get_srv_state() {
 
 
 	# Checking pid
 	# Checking pid
 	if [ -n "$pids" ]; then
 	if [ -n "$pids" ]; then
-		pid=$(echo "$pids" | awk -F '|' '{print $NF}')
+		if [[ "$used_pgrep" -eq 1 ]]; then
+			pid=$(echo "$pids" | awk -F '|' '{print $1}')
+		else
+			pid=$(echo "$pids" | awk -F '|' '{print $NF}')
+		fi
 		pids=${pids%|}
 		pids=${pids%|}
 		pids=$(egrep "$pids" $tmp_file)
 		pids=$(egrep "$pids" $tmp_file)