Browse Source

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

Fixed issue when getting pids from pgrep and then using awk to get the main pid
sahsanu 2 years ago
parent
commit
3eb4c8b031
1 changed files with 7 additions and 1 deletions
  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
 
 
 	# Correctly handle hestia-web-terminal service
 	# Correctly handle hestia-web-terminal service
@@ -107,7 +109,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)