Skip to content

Commit 3eb4c8b

Browse files
authored
Update v-list-sys-services (hestiacp#4070)
Fixed issue when getting pids from pgrep and then using awk to get the main pid
1 parent c2472a5 commit 3eb4c8b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

bin/v-list-sys-services

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ get_srv_state() {
9191
else
9292
pids=$(pidof -x $name | tr ' ' '|')
9393
fi
94+
used_pgrep=0
9495
if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then
9596
pids=$(pgrep $name | tr '\n' '|')
97+
used_pgrep=1
9698
fi
9799

98100
# Correctly handle hestia-web-terminal service
@@ -107,7 +109,11 @@ get_srv_state() {
107109

108110
# Checking pid
109111
if [ -n "$pids" ]; then
110-
pid=$(echo "$pids" | awk -F '|' '{print $NF}')
112+
if [[ "$used_pgrep" -eq 1 ]]; then
113+
pid=$(echo "$pids" | awk -F '|' '{print $1}')
114+
else
115+
pid=$(echo "$pids" | awk -F '|' '{print $NF}')
116+
fi
111117
pids=${pids%|}
112118
pids=$(egrep "$pids" $tmp_file)
113119

0 commit comments

Comments
 (0)