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

Update v-list-sys-services to avoid 0 min uptime (#3962)

Modify pidof command to use -d option to assign a delimiter so there is no need to use tr to change spaces by pipes.

In services with several pids, the script is taking the first pid in the list, but the first pid is the pid for last process, not the main process so a lot of times you can see an uptime of 0 mins instead of the actual uptime for the main/master process. So, I've modified it to get the last pid in the list instead of the first.
sahsanu 2 лет назад
Родитель
Сommit
17789b70fe
1 измененных файлов с 3 добавлено и 3 удалено
  1. 3 3
      bin/v-list-sys-services

+ 3 - 3
bin/v-list-sys-services

@@ -87,9 +87,9 @@ get_srv_state() {
 
 
 	# Searching related pids
 	# Searching related pids
 	if [ -z $3 ]; then
 	if [ -z $3 ]; then
-		pids=$(pidof $name | tr ' ' '|')
+		pids=$(pidof -d '|' $name)
 	else
 	else
-		pids=$(pidof -x $name | tr ' ' '|')
+		pids=$(pidof -d '|' -x $name)
 	fi
 	fi
 	if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then
 	if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then
 		pids=$(pgrep $name | tr '\n' '|')
 		pids=$(pgrep $name | tr '\n' '|')
@@ -107,7 +107,7 @@ get_srv_state() {
 
 
 	# Checking pid
 	# Checking pid
 	if [ -n "$pids" ]; then
 	if [ -n "$pids" ]; then
-		pid=$(echo "$pids" | cut -f 1 -d '|')
+		pid=$(echo "$pids" | awk -F '|' '{print $NF}')
 		pids=${pids%|}
 		pids=${pids%|}
 		pids=$(egrep "$pids" $tmp_file)
 		pids=$(egrep "$pids" $tmp_file)