Skip to content

Commit

Permalink
[KYUUBI #4515] Capturing process id for kyuubi server launched using …
Browse files Browse the repository at this point in the history
…run command
  • Loading branch information
Madhukar98 committed May 8, 2024
1 parent 78e104d commit bbee33a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bin/kyuubi
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,20 @@ cmd="${RUNNER} ${KYUUBI_JAVA_OPTS} -cp ${KYUUBI_CLASSPATH} $CLASS"

pid="${KYUUBI_PID_DIR}/kyuubi-$USER-$CLASS.pid"

function get_pid(){
if [[ ! -w ${KYUUBI_PID_DIR} ]]; then
echo "${USER} does not have 'w' permission to ${KYUUBI_PID_DIR}"
exit 1
fi

run_pid="$(ps -ef | grep kyuubi | grep java | grep -v grep | awk '{print $2}')"
if [[ -n $run_pid ]]; then
echo "$run_pid" > "$pid"
fi
}

function start_kyuubi() {
get_pid
if [[ ! -w ${KYUUBI_PID_DIR} ]]; then
echo "${USER} does not have 'w' permission to ${KYUUBI_PID_DIR}"
exit 1
Expand Down Expand Up @@ -156,6 +169,14 @@ function start_kyuubi() {
}

function run_kyuubi() {
if [ -f "$pid" ]; then
TARGET_ID="$(cat "$pid")"
if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
echo "$CLASS running as process $TARGET_ID Stop it first."
exit 1
fi
fi

echo "Starting $CLASS"
exec nice -n "${KYUUBI_NICENESS:-0}" ${cmd}
}
Expand Down Expand Up @@ -206,6 +227,7 @@ function stop_kyuubi() {
}

function check_kyuubi() {
get_pid
if [[ -f ${pid} ]]; then
TARGET_ID="$(cat "$pid")"
if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
Expand Down

0 comments on commit bbee33a

Please sign in to comment.