ddanielr commented on code in PR #4763:
URL: https://github.com/apache/accumulo/pull/4763#discussion_r1693746975


##########
assemble/bin/accumulo-service:
##########
@@ -159,10 +210,13 @@ function main() {
           start_service "${@:3}"
           ;;
         stop)
-          stop_service
+          stop_service "${@:3:1}"
           ;;
         kill)
-          kill_service
+          kill_service "${@:3:1}"

Review Comment:
   Removed all of this in favor of local variables and passing vars between the 
bash functions.



##########
assemble/bin/accumulo-service:
##########
@@ -91,27 +91,78 @@ function start_service() {
   fi
 }
 
-function stop_service() {
+function control_process() {
+  kill_code=${1}
   if [[ -f $pid_file ]]; then
     echo "Stopping $service on $host"
-    kill -s TERM "$(cat "$pid_file")" 2>/dev/null
+    kill -s "$kill_code" "$(cat "$pid_file")" 2>/dev/null
     rm -f "${pid_file}" 2>/dev/null
   fi
 }
 
+function stop_service() {
+  if [[ -n $1 ]]; then
+    case $1 in
+      "--all")
+        find_processes
+        for process in "${RUNNING_PROCESSES[@]}"; do
+          pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid"
+          control_process "TERM"
+        done
+        ;;
+      *"$service"*)
+        echo "Stopping service process: $1"
+        pid_file="${ACCUMULO_PID_DIR}/accumulo-${1}.pid"
+        ;;
+    esac
+  fi
+  control_process "TERM"
+}
+
 function kill_service() {
-  if [[ -f $pid_file ]]; then
-    echo "Killing $service on $host"
-    kill -s KILL "$(cat "$pid_file")" 2>/dev/null
-    rm -f "${pid_file}" 2>/dev/null
+  if [[ -n $1 ]]; then
+    case $1 in
+      "--all")
+        find_processes
+        for process in "${RUNNING_PROCESSES[@]}"; do
+          pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid"
+          control_process "KILL"
+        done
+        ;;
+      *"$service"*)
+        pid_file="${ACCUMULO_PID_DIR}/accumulo-${1}.pid"
+        ;;
+    esac
   fi
+  control_process "KILL"
+}
+
+function find_processes() {
+  files=$(echo "${ACCUMULO_PID_DIR}"/*)
+  for file in $files; do
+    if [[ $file == *$service* ]]; then
+      stripped_file=${file%.pid}
+      RUNNING_PROCESSES+=("${stripped_file##*accumulo-}")
+    fi

Review Comment:
   Removed all of this in favor of local variables and passing vars between the 
bash functions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to