Skip to content

Commit 17789b7

Browse files
authored
Update v-list-sys-services to avoid 0 min uptime (hestiacp#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.
1 parent e910ab8 commit 17789b7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bin/v-list-sys-services

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ get_srv_state() {
8787

8888
# Searching related pids
8989
if [ -z $3 ]; then
90-
pids=$(pidof $name | tr ' ' '|')
90+
pids=$(pidof -d '|' $name)
9191
else
92-
pids=$(pidof -x $name | tr ' ' '|')
92+
pids=$(pidof -d '|' -x $name)
9393
fi
9494
if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then
9595
pids=$(pgrep $name | tr '\n' '|')
@@ -107,7 +107,7 @@ get_srv_state() {
107107

108108
# Checking pid
109109
if [ -n "$pids" ]; then
110-
pid=$(echo "$pids" | cut -f 1 -d '|')
110+
pid=$(echo "$pids" | awk -F '|' '{print $NF}')
111111
pids=${pids%|}
112112
pids=$(egrep "$pids" $tmp_file)
113113

0 commit comments

Comments
 (0)