summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-09-24 11:05:51 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-09-24 11:05:51 +0200
commit969382fabf7eb7f673058e0e4c6c18bb5eb46ac1 (patch)
tree655947aba3dfed0f754d6401826e9fbe39a9d67a /container-core
parent9dabf1ce317325a334fd5f6aac531456acea17c4 (diff)
Extend find-pid to accept service by name
Diffstat (limited to 'container-core')
-rwxr-xr-xcontainer-core/src/main/sh/find-pid28
1 files changed, 17 insertions, 11 deletions
diff --git a/container-core/src/main/sh/find-pid b/container-core/src/main/sh/find-pid
index e1c2195c805..2535bdbe8a9 100755
--- a/container-core/src/main/sh/find-pid
+++ b/container-core/src/main/sh/find-pid
@@ -77,20 +77,26 @@ findhost
set -euo pipefail
if (( $# != 1 )); then
- echo "Usage: $0 <service-config-id>" >&2
+ echo "Usage: $0 <service-name-or-config-id>" >&2
exit 1
fi
-readonly config_id=$1
-status=$(vespa-sentinel-cmd list 2>/dev/null | grep "id=\"${config_id}\"")
-if [ -z "${status}" ]; then
- echo "No service named '${config_id}'" >&2
- exit 1
-fi
-readonly pid=$(echo ${status} | cut -d " " -f 4 | cut -d "=" -f 2)
-if ! [[ "${pid}" =~ ^[0-9]+$ ]]; then
- echo "Could not find valid pid for '${config_id}' (pid='${pid}')" >&2
- exit 1
+readonly service=$1
+readonly pid_file="$VESPA_HOME/var/run/$service.pid"
+if [ -f "$VESPA_HOME/var/run/$service.pid" ]; then
+ parent_pid=$(cat "$pid_file")
+ pid=$(pgrep --parent $parent_pid)
+else
+ status=$(vespa-sentinel-cmd list 2>/dev/null | grep --perl-regexp "($service state=|id=\"$service\")")
+ if [ -z "${status}" ]; then
+ echo "No service with name or config id '${service}'" >&2
+ exit 1
+ fi
+ pid=$(echo ${status} | cut -d " " -f 4 | cut -d "=" -f 2)
+ if ! [[ "${pid}" =~ ^[0-9]+$ ]]; then
+ echo "Could not find valid pid for '${service}' (pid='${pid}')" >&2
+ exit 1
+ fi
fi
if [ -z "$(ps -p ${pid} -o pid=)" ]; then
echo "Could not find process for '${pid}'" >&2