From 5fc0e8001b06e9b671f43ba01a9fc458d9085214 Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Wed, 19 Aug 2026 23:22:19 -0400 Subject: [PATCH 1/6] Add list-all capability to accumulo-service Currently the accumulo-service script only supports listing information for individual services. There are times when a user will want to retrieve the PIDs for all processes managed by Accumulo. Modify the accumulo-service script to: - Add the service `all` that can be combined with the list command to list all processes. - Add the sub-options `-p`, `--parseable` to make the list command print only the name, pid, and port of each process for consistently formatted output. - Forbid the use of the service `all` with the start, stop, or kill command. Closes #6507 --- assemble/bin/accumulo-service | 76 +++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/assemble/bin/accumulo-service b/assemble/bin/accumulo-service index 99cf38a9b7b..7e9f1901f18 100755 --- a/assemble/bin/accumulo-service +++ b/assemble/bin/accumulo-service @@ -29,12 +29,12 @@ Services: tserver Accumulo tserver compactor Accumulo compactor sserver Accumulo scan server - + all All services (list command only) Commands: start Starts service(s) stop [--all | []] Stops service(s) kill [--all | []] Kills service(s) - list List running service(s) + list [-p, --parseable ] List running service(s) EOF } @@ -143,6 +143,8 @@ function find_processes() { local filepath local expected_pid local found_pid + # Clear the array. + RUNNING_PROCESSES=() for filepath in "$ACCUMULO_PID_DIR"/*; do if [[ $filepath =~ ^.*/accumulo-("$service_type".*)[.]pid$ ]]; then file="${BASH_REMATCH[1]}" @@ -217,8 +219,12 @@ function kill_service() { function list_processes() { local service_type=$1 + local parseable_flag=$2 find_processes "$service_type" - echo "Currently running ${service_type} processes (fields: process pid port):" + # Print this only if the output does not need to be consistently formatted for parsing. + if [[ $parseable_flag == 'false' ]]; then + echo "Currently running ${service_type} processes (fields: process pid port):" + fi for process in "${RUNNING_PROCESSES[@]}"; do local pid_file local pid @@ -274,6 +280,7 @@ function main() { shift 2 local service_name="" local all_flag=false + local parseable_flag=false if [[ -f "${conf}/accumulo-env.sh" ]]; then #shellcheck source=../conf/accumulo-env.sh @@ -290,6 +297,8 @@ function main() { # The rest of the arguments are from a user if [[ $1 == "--all" ]]; then all_flag=true + elif [[ $1 == "-p" || $1 == "--parseable" ]]; then + parseable_flag=true else # A named service has been specified if [[ $1 != "-o" ]]; then @@ -298,33 +307,48 @@ function main() { fi fi - case "$service_type" in - gc | manager | monitor | tserver | compactor | sserver) - if [[ -z $command_name ]]; then - invalid_args " cannot be empty" - fi - case "$command_name" in - start) - start_service "$service_type" "$service_name" "$@" - ;; - stop) - stop_service "$service_type" "$service_name" $all_flag "$@" - ;; - kill) - kill_service "$service_type" "$service_name" $all_flag "$@" - ;; - list) - list_processes "$service_type" + local services + # If 'all' was specified, execute the command against all services. + if [[ $service_type == "all" ]]; then + if [[ -z $command_name ]]; then + invalid_args " cannot be empty" + elif [[ $command_name != "list" ]]; then + invalid_args "Service all can only be used with the list command" + fi + services=("gc" "manager" "monitor" "tserver" "compactor" "sserver") + else + services=("$service_type") + fi + + for service in "${services[@]}"; do + case "$service" in + gc | manager | monitor | tserver | compactor | sserver) + if [[ -z $command_name ]]; then + invalid_args " cannot be empty" + fi + case "$command_name" in + start) + start_service "$service" "$service_name" "$@" + ;; + stop) + stop_service "$service" "$service_name" $all_flag "$@" + ;; + kill) + kill_service "$service" "$service_name" $all_flag "$@" + ;; + list) + list_processes "$service" $parseable_flag + ;; + *) + invalid_args "'$command_name' is an invalid " + ;; + esac ;; *) - invalid_args "'$command_name' is an invalid " + invalid_args "'$service' is an invalid " ;; esac - ;; - *) - invalid_args "'$service_type' is an invalid " - ;; - esac + done } main "$@" From c041a43cf4edd200f763c76fd25596f65a10e750 Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Thu, 20 Aug 2026 12:19:03 -0400 Subject: [PATCH 2/6] Apply shfmt changes --- assemble/bin/accumulo-service | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/assemble/bin/accumulo-service b/assemble/bin/accumulo-service index 7e9f1901f18..f446d6b240b 100755 --- a/assemble/bin/accumulo-service +++ b/assemble/bin/accumulo-service @@ -322,32 +322,32 @@ function main() { for service in "${services[@]}"; do case "$service" in - gc | manager | monitor | tserver | compactor | sserver) - if [[ -z $command_name ]]; then - invalid_args " cannot be empty" - fi - case "$command_name" in - start) - start_service "$service" "$service_name" "$@" - ;; - stop) - stop_service "$service" "$service_name" $all_flag "$@" - ;; - kill) - kill_service "$service" "$service_name" $all_flag "$@" - ;; - list) - list_processes "$service" $parseable_flag - ;; - *) - invalid_args "'$command_name' is an invalid " - ;; - esac - ;; - *) - invalid_args "'$service' is an invalid " - ;; - esac + gc | manager | monitor | tserver | compactor | sserver) + if [[ -z $command_name ]]; then + invalid_args " cannot be empty" + fi + case "$command_name" in + start) + start_service "$service" "$service_name" "$@" + ;; + stop) + stop_service "$service" "$service_name" $all_flag "$@" + ;; + kill) + kill_service "$service" "$service_name" $all_flag "$@" + ;; + list) + list_processes "$service" $parseable_flag + ;; + *) + invalid_args "'$command_name' is an invalid " + ;; + esac + ;; + *) + invalid_args "'$service' is an invalid " + ;; + esac done } From 2a9061ebf31da1063189f531138b10d81c21c993 Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Fri, 21 Aug 2026 15:18:19 -0400 Subject: [PATCH 3/6] Add --json flag Add the flag --json for the accumulo-service list command. When specified, the caller will receive output formatted as json. --- assemble/bin/accumulo-service | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/assemble/bin/accumulo-service b/assemble/bin/accumulo-service index f446d6b240b..96791d59080 100755 --- a/assemble/bin/accumulo-service +++ b/assemble/bin/accumulo-service @@ -34,7 +34,7 @@ Commands: start Starts service(s) stop [--all | []] Stops service(s) kill [--all | []] Kills service(s) - list [-p, --parseable ] List running service(s) + list [--json] List running service(s) EOF } @@ -219,10 +219,10 @@ function kill_service() { function list_processes() { local service_type=$1 - local parseable_flag=$2 + local json_flag=$2 find_processes "$service_type" - # Print this only if the output does not need to be consistently formatted for parsing. - if [[ $parseable_flag == 'false' ]]; then + # Print this only if the caller doesn't want json. + if [[ $json_flag != 'true' ]]; then echo "Currently running ${service_type} processes (fields: process pid port):" fi for process in "${RUNNING_PROCESSES[@]}"; do @@ -235,7 +235,13 @@ function list_processes() { port=$(ss -tnlp 2>/dev/null | grep -wF "pid=$pid" | awk '{print $4}' | awk -F : '{print $NF}' | paste -sd,) if [[ $port =~ ^[1-9][0-9]{1,4}(,[1-9][0-9]{1,4})*$ ]]; then - echo "$process $pid $port" + + if [[ $json_flag != 'true' ]]; then + echo "$process $pid $port" + else + jq -n --arg process "$process" --arg pid "$pid" --arg port "$port" '$ARGS.named' + fi + else echo "ERROR unexpected port format $(hostname) process:$process pid:$pid ports:$port" >&2 loop_err=1 @@ -280,7 +286,7 @@ function main() { shift 2 local service_name="" local all_flag=false - local parseable_flag=false + local json_flag=false if [[ -f "${conf}/accumulo-env.sh" ]]; then #shellcheck source=../conf/accumulo-env.sh @@ -297,8 +303,9 @@ function main() { # The rest of the arguments are from a user if [[ $1 == "--all" ]]; then all_flag=true - elif [[ $1 == "-p" || $1 == "--parseable" ]]; then - parseable_flag=true + # The caller wants the output formatted as json. + elif [[ $1 == "--json" ]]; then + json_flag=true else # A named service has been specified if [[ $1 != "-o" ]]; then @@ -337,7 +344,7 @@ function main() { kill_service "$service" "$service_name" $all_flag "$@" ;; list) - list_processes "$service" $parseable_flag + list_processes "$service" $json_flag ;; *) invalid_args "'$command_name' is an invalid " From 8614b3dc52c79813b1adefe4a7d9c6b33946d270 Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Fri, 21 Aug 2026 16:38:21 -0400 Subject: [PATCH 4/6] Ensure --json outputs a json array --- assemble/bin/accumulo-service | 586 +++++++++++++++++----------------- 1 file changed, 296 insertions(+), 290 deletions(-) diff --git a/assemble/bin/accumulo-service b/assemble/bin/accumulo-service index 96791d59080..dc97bb2aeab 100755 --- a/assemble/bin/accumulo-service +++ b/assemble/bin/accumulo-service @@ -19,7 +19,7 @@ # function print_usage { - cat < Services: @@ -40,322 +40,328 @@ EOF } function invalid_args { - echo -e "Invalid arguments: $1\n" - print_usage 1>&2 - exit 1 + echo -e "Invalid arguments: $1\n" + print_usage 1>&2 + exit 1 } function rotate_log() { - logfile="$1" - max_retained="5" - if [[ -f $logfile ]]; then - while [[ $max_retained -gt 1 ]]; do - prev=$((max_retained - 1)) - [ -f "$logfile.$prev" ] && mv -f "$logfile.$prev" "$logfile.$max_retained" - max_retained=$prev - done - mv -f "$logfile" "$logfile.$max_retained" - fi + logfile="$1" + max_retained="5" + if [[ -f $logfile ]]; then + while [[ $max_retained -gt 1 ]]; do + prev=$((max_retained - 1)) + [ -f "$logfile.$prev" ] && mv -f "$logfile.$prev" "$logfile.$max_retained" + max_retained=$prev + done + mv -f "$logfile" "$logfile.$max_retained" + fi } function get_group() { - # Find the group parameter if any - local group="default" - local param - for param in "$@"; do - if [[ $param =~ ^[a-z]*[.]group=(.*)$ ]]; then - group="${BASH_REMATCH[1]}" - fi - done - echo "$group" + # Find the group parameter if any + local group="default" + local param + for param in "$@"; do + if [[ $param =~ ^[a-z]*[.]group=(.*)$ ]]; then + group="${BASH_REMATCH[1]}" + fi + done + echo "$group" } function start_service() { - local service_type=$1 - local service_name=$2 - shift 2 - - local build_service_name="false" - if [[ -n $service_name ]]; then - # if service_name is supplied, then we are only starting one instance - servers_per_host=1 - else - build_service_name="true" - servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} - fi - - for ((process_num = 1; process_num <= servers_per_host; process_num++)); do - if [[ ${build_service_name} == "true" ]]; then - service_name="${service_type}_${group}_${process_num}" - fi - # The ACCUMULO_SERVICE_INSTANCE variable is used in - # accumulo-env.sh to set parameters on the command - # line. - export ACCUMULO_SERVICE_INSTANCE="${service_name}" - - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - if [[ -f $pid_file ]]; then - pid=$(cat "$pid_file") - if kill -0 "$pid" 2>/dev/null; then - echo "$HOST : ${service_name} already running (${pid})" - continue - fi - fi - echo "Starting $service_name on $HOST" - - if [[ ${service_type} == "manager" ]]; then - "${bin}/accumulo" org.apache.accumulo.manager.state.SetGoalState NORMAL - fi - outfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.out" - errfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.err" - rotate_log "$outfile" - rotate_log "$errfile" - - nohup "${bin}/accumulo" "proc" "$service_type" "$@" >"$outfile" 2>"$errfile" "${pid_file}" - - done - - # Check the max open files limit and selectively warn - max_files_open=$(ulimit -n) - if [[ -n $max_files_open ]]; then - max_files_recommended=32768 - if ((max_files_open < max_files_recommended)); then - echo "WARN : Max open files on $HOST is $max_files_open, recommend $max_files_recommended" >&2 - fi - fi + local service_type=$1 + local service_name=$2 + shift 2 + + local build_service_name="false" + if [[ -n $service_name ]]; then + # if service_name is supplied, then we are only starting one instance + servers_per_host=1 + else + build_service_name="true" + servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} + fi + + for ((process_num = 1; process_num <= servers_per_host; process_num++)); do + if [[ ${build_service_name} == "true" ]]; then + service_name="${service_type}_${group}_${process_num}" + fi + # The ACCUMULO_SERVICE_INSTANCE variable is used in + # accumulo-env.sh to set parameters on the command + # line. + export ACCUMULO_SERVICE_INSTANCE="${service_name}" + + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + if [[ -f $pid_file ]]; then + pid=$(cat "$pid_file") + if kill -0 "$pid" 2>/dev/null; then + echo "$HOST : ${service_name} already running (${pid})" + continue + fi + fi + echo "Starting $service_name on $HOST" + + if [[ ${service_type} == "manager" ]]; then + "${bin}/accumulo" org.apache.accumulo.manager.state.SetGoalState NORMAL + fi + outfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.out" + errfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.err" + rotate_log "$outfile" + rotate_log "$errfile" + + nohup "${bin}/accumulo" "proc" "$service_type" "$@" >"$outfile" 2>"$errfile" "${pid_file}" + + done + + # Check the max open files limit and selectively warn + max_files_open=$(ulimit -n) + if [[ -n $max_files_open ]]; then + max_files_recommended=32768 + if ((max_files_open < max_files_recommended)); then + echo "WARN : Max open files on $HOST is $max_files_open, recommend $max_files_recommended" >&2 + fi + fi } function control_process() { - local kill_code=$1 - local service_name=$2 - local pid_file=$3 - if [[ -f $pid_file ]]; then - echo "Stopping $service_name on $HOST" - kill -s "$kill_code" "$(cat "$pid_file")" 2>/dev/null - rm -f "${pid_file}" 2>/dev/null - fi + local kill_code=$1 + local service_name=$2 + local pid_file=$3 + if [[ -f $pid_file ]]; then + echo "Stopping $service_name on $HOST" + kill -s "$kill_code" "$(cat "$pid_file")" 2>/dev/null + rm -f "${pid_file}" 2>/dev/null + fi } function find_processes() { - local service_type=$1 - local file - local filepath - local expected_pid - local found_pid - # Clear the array. - RUNNING_PROCESSES=() - for filepath in "$ACCUMULO_PID_DIR"/*; do - if [[ $filepath =~ ^.*/accumulo-("$service_type".*)[.]pid$ ]]; then - file="${BASH_REMATCH[1]}" - expected_pid=$(<"$filepath") - found_pid=$(pgrep -F "$filepath" -f "$file") - if [[ $found_pid != "$expected_pid" ]]; then - echo "removing stale pid file $filepath" >&2 - rm "$filepath" - else - RUNNING_PROCESSES+=("$file") - fi - fi - done + local service_type=$1 + local file + local filepath + local expected_pid + local found_pid + # Clear the array. + RUNNING_PROCESSES=() + for filepath in "$ACCUMULO_PID_DIR"/*; do + if [[ $filepath =~ ^.*/accumulo-("$service_type".*)[.]pid$ ]]; then + file="${BASH_REMATCH[1]}" + expected_pid=$(<"$filepath") + found_pid=$(pgrep -F "$filepath" -f "$file") + if [[ $found_pid != "$expected_pid" ]]; then + echo "removing stale pid file $filepath" >&2 + rm "$filepath" + else + RUNNING_PROCESSES+=("$file") + fi + fi + done } function stop_service() { - local service_type=$1 - local service_name=$2 - local all_flag=$3 - if [[ $all_flag == 'true' ]]; then - find_processes "$service_type" - for process in "${RUNNING_PROCESSES[@]}"; do - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" - control_process "TERM" "$process" "$pid_file" - done - elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then - - servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} - group=$(get_group "$@") - - for ((process_num = 1; process_num <= servers_per_host; process_num++)); do - service_name="${service_type}_${group}_${process_num}" - echo "Stopping service process: $service_name" - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "TERM" "$service_name" "$pid_file" - done - - else - echo "Stopping service process: $service_name" - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "TERM" "$service_name" "$pid_file" - fi + local service_type=$1 + local service_name=$2 + local all_flag=$3 + if [[ $all_flag == 'true' ]]; then + find_processes "$service_type" + for process in "${RUNNING_PROCESSES[@]}"; do + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" + control_process "TERM" "$process" "$pid_file" + done + elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then + + servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} + group=$(get_group "$@") + + for ((process_num = 1; process_num <= servers_per_host; process_num++)); do + service_name="${service_type}_${group}_${process_num}" + echo "Stopping service process: $service_name" + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "TERM" "$service_name" "$pid_file" + done + + else + echo "Stopping service process: $service_name" + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "TERM" "$service_name" "$pid_file" + fi } function kill_service() { - local service_type=$1 - local service_name=$2 - local all_flag=$3 - if [[ $all_flag == 'true' ]]; then - find_processes "$service_type" - for process in "${RUNNING_PROCESSES[@]}"; do - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" - control_process "KILL" "$process" "$pid_file" - done - elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then - - servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} - group=$(get_group "$@") - - for ((process_num = 1; process_num <= servers_per_host; process_num++)); do - service_name="${service_type}_${group}_${process_num}" - echo "Stopping service process: $service_name" - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "KILL" "$service_name" "$pid_file" - done - - else - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "KILL" "$service_name" "$pid_file" - fi + local service_type=$1 + local service_name=$2 + local all_flag=$3 + if [[ $all_flag == 'true' ]]; then + find_processes "$service_type" + for process in "${RUNNING_PROCESSES[@]}"; do + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" + control_process "KILL" "$process" "$pid_file" + done + elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then + + servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} + group=$(get_group "$@") + + for ((process_num = 1; process_num <= servers_per_host; process_num++)); do + service_name="${service_type}_${group}_${process_num}" + echo "Stopping service process: $service_name" + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "KILL" "$service_name" "$pid_file" + done + + else + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "KILL" "$service_name" "$pid_file" + fi } function list_processes() { - local service_type=$1 - local json_flag=$2 - find_processes "$service_type" - # Print this only if the caller doesn't want json. - if [[ $json_flag != 'true' ]]; then - echo "Currently running ${service_type} processes (fields: process pid port):" - fi - for process in "${RUNNING_PROCESSES[@]}"; do - local pid_file - local pid - local port - local loop_err - pid_file="$ACCUMULO_PID_DIR/accumulo-$process.pid" - pid=$(<"$pid_file") # read the contents of the file into the $pid variable - port=$(ss -tnlp 2>/dev/null | grep -wF "pid=$pid" | awk '{print $4}' | awk -F : '{print $NF}' | paste -sd,) - - if [[ $port =~ ^[1-9][0-9]{1,4}(,[1-9][0-9]{1,4})*$ ]]; then - - if [[ $json_flag != 'true' ]]; then - echo "$process $pid $port" - else - jq -n --arg process "$process" --arg pid "$pid" --arg port "$port" '$ARGS.named' - fi - - else - echo "ERROR unexpected port format $(hostname) process:$process pid:$pid ports:$port" >&2 - loop_err=1 - fi - done - [[ -z $loop_err ]] # return non-zero if any errors occurred during the loop + local service_type=$1 + local json_flag=$2 + find_processes "$service_type" + # Print this only if the caller doesn't want json. + if [[ $json_flag != 'true' ]]; then + echo "Currently running ${service_type} processes (fields: process pid port):" + fi + for process in "${RUNNING_PROCESSES[@]}"; do + local pid_file + local pid + local port + local loop_err + pid_file="$ACCUMULO_PID_DIR/accumulo-$process.pid" + pid=$(<"$pid_file") # read the contents of the file into the $pid variable + port=$(ss -tnlp 2>/dev/null | grep -wF "pid=$pid" | awk '{print $4}' | awk -F : '{print $NF}' | paste -sd,) + + if [[ $port =~ ^[1-9][0-9]{1,4}(,[1-9][0-9]{1,4})*$ ]]; then + + if [[ $json_flag != 'true' ]]; then + echo "$process $pid $port" + else + # If --json was specified, append the JSON to the output array. + JSON_OUTPUT+=$(jq -n -c --arg process "$process" --arg pid "$pid" --arg port "$port" '$ARGS.named') + fi + + else + echo "ERROR unexpected port format $(hostname) process:$process pid:$pid ports:$port" >&2 + loop_err=1 + fi + done + [[ -z $loop_err ]] # return non-zero if any errors occurred during the loop } function main() { - if [[ -z $1 ]]; then - invalid_args " cannot be empty" - fi - - # Create a global array for process tracking - declare -a RUNNING_PROCESSES - - # Resolve base directory - SOURCE="${BASH_SOURCE[0]}" - while [ -h "${SOURCE}" ]; do - bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" - SOURCE="$(readlink "${SOURCE}")" - [[ ${SOURCE} != /* ]] && SOURCE="${bin}/${SOURCE}" - done - # Set up variables needed by accumulo-env.sh - bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" - export bin - basedir=$(cd -P "${bin}"/.. && pwd) - export basedir - export conf="${ACCUMULO_CONF_DIR:-${basedir}/conf}" - export lib="${basedir}/lib" - - group=$(get_group "$@") - export ACCUMULO_RESOURCE_GROUP="$group" - - HOST="$(hostname)" - if [[ -z $HOST ]]; then - HOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') - fi - - local service_type="$1" - local command_name="$2" - shift 2 - local service_name="" - local all_flag=false - local json_flag=false - - if [[ -f "${conf}/accumulo-env.sh" ]]; then - #shellcheck source=../conf/accumulo-env.sh - source "${conf}/accumulo-env.sh" - fi - ACCUMULO_LOG_DIR="${ACCUMULO_LOG_DIR:-${basedir}/logs}" - ACCUMULO_PID_DIR="${ACCUMULO_PID_DIR:-${basedir}/run}" - - mkdir -p "$ACCUMULO_LOG_DIR" 2>/dev/null - mkdir -p "$ACCUMULO_PID_DIR" 2>/dev/null - - # Check and see if accumulo-cluster is calling this script - if [[ -z $ACCUMULO_CLUSTER_ARG ]]; then - # The rest of the arguments are from a user - if [[ $1 == "--all" ]]; then - all_flag=true - # The caller wants the output formatted as json. - elif [[ $1 == "--json" ]]; then - json_flag=true - else - # A named service has been specified - if [[ $1 != "-o" ]]; then - service_name="$1" - fi - fi - fi - - local services - # If 'all' was specified, execute the command against all services. - if [[ $service_type == "all" ]]; then - if [[ -z $command_name ]]; then - invalid_args " cannot be empty" - elif [[ $command_name != "list" ]]; then - invalid_args "Service all can only be used with the list command" - fi - services=("gc" "manager" "monitor" "tserver" "compactor" "sserver") - else - services=("$service_type") - fi - - for service in "${services[@]}"; do - case "$service" in - gc | manager | monitor | tserver | compactor | sserver) - if [[ -z $command_name ]]; then - invalid_args " cannot be empty" - fi - case "$command_name" in - start) - start_service "$service" "$service_name" "$@" - ;; - stop) - stop_service "$service" "$service_name" $all_flag "$@" - ;; - kill) - kill_service "$service" "$service_name" $all_flag "$@" - ;; - list) - list_processes "$service" $json_flag - ;; - *) - invalid_args "'$command_name' is an invalid " - ;; - esac - ;; - *) - invalid_args "'$service' is an invalid " - ;; - esac - done + if [[ -z $1 ]]; then + invalid_args " cannot be empty" + fi + + # Create a global array for process tracking + declare -a RUNNING_PROCESSES + + # Resolve base directory + SOURCE="${BASH_SOURCE[0]}" + while [ -h "${SOURCE}" ]; do + bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" + SOURCE="$(readlink "${SOURCE}")" + [[ ${SOURCE} != /* ]] && SOURCE="${bin}/${SOURCE}" + done + # Set up variables needed by accumulo-env.sh + bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" + export bin + basedir=$(cd -P "${bin}"/.. && pwd) + export basedir + export conf="${ACCUMULO_CONF_DIR:-${basedir}/conf}" + export lib="${basedir}/lib" + + group=$(get_group "$@") + export ACCUMULO_RESOURCE_GROUP="$group" + + HOST="$(hostname)" + if [[ -z $HOST ]]; then + HOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + fi + + local service_type="$1" + local command_name="$2" + shift 2 + local service_name="" + local all_flag=false + local json_flag=false + + if [[ -f "${conf}/accumulo-env.sh" ]]; then + #shellcheck source=../conf/accumulo-env.sh + source "${conf}/accumulo-env.sh" + fi + ACCUMULO_LOG_DIR="${ACCUMULO_LOG_DIR:-${basedir}/logs}" + ACCUMULO_PID_DIR="${ACCUMULO_PID_DIR:-${basedir}/run}" + + mkdir -p "$ACCUMULO_LOG_DIR" 2>/dev/null + mkdir -p "$ACCUMULO_PID_DIR" 2>/dev/null + + # Check and see if accumulo-cluster is calling this script + if [[ -z $ACCUMULO_CLUSTER_ARG ]]; then + # The rest of the arguments are from a user + if [[ $1 == "--all" ]]; then + all_flag=true + # The caller wants the output formatted as json. + elif [[ $1 == "--json" ]]; then + json_flag=true + else + # A named service has been specified + if [[ $1 != "-o" ]]; then + service_name="$1" + fi + fi + fi + + local services + # If 'all' was specified, execute the command against all services. + if [[ $service_type == "all" ]]; then + if [[ -z $command_name ]]; then + invalid_args " cannot be empty" + elif [[ $command_name != "list" ]]; then + invalid_args "Service all can only be used with the list command" + fi + services=("gc" "manager" "monitor" "tserver" "compactor" "sserver") + else + services=("$service_type") + fi + + for service in "${services[@]}"; do + case "$service" in + gc | manager | monitor | tserver | compactor | sserver) + if [[ -z $command_name ]]; then + invalid_args " cannot be empty" + fi + case "$command_name" in + start) + start_service "$service" "$service_name" "$@" + ;; + stop) + stop_service "$service" "$service_name" $all_flag "$@" + ;; + kill) + kill_service "$service" "$service_name" $all_flag "$@" + ;; + list) + list_processes "$service" $json_flag + ;; + *) + invalid_args "'$command_name' is an invalid " + ;; + esac + ;; + *) + invalid_args "'$service' is an invalid " + ;; + esac + done + + # If --json was specified, combine the json for each process into a single json object. + if [[ $json_flag == 'true' ]]; then + printf '%s\n' "${JSON_OUTPUT[@]}" | jq -s '.' + fi } main "$@" From 04bfc198ba710f856bc65f40ec0beb2d33d141a8 Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Fri, 21 Aug 2026 16:58:41 -0400 Subject: [PATCH 5/6] Fix script formatting --- assemble/bin/accumulo-service | 592 +++++++++++++++++----------------- 1 file changed, 296 insertions(+), 296 deletions(-) diff --git a/assemble/bin/accumulo-service b/assemble/bin/accumulo-service index dc97bb2aeab..4bf427b7a1a 100755 --- a/assemble/bin/accumulo-service +++ b/assemble/bin/accumulo-service @@ -19,7 +19,7 @@ # function print_usage { - cat < Services: @@ -40,328 +40,328 @@ EOF } function invalid_args { - echo -e "Invalid arguments: $1\n" - print_usage 1>&2 - exit 1 + echo -e "Invalid arguments: $1\n" + print_usage 1>&2 + exit 1 } function rotate_log() { - logfile="$1" - max_retained="5" - if [[ -f $logfile ]]; then - while [[ $max_retained -gt 1 ]]; do - prev=$((max_retained - 1)) - [ -f "$logfile.$prev" ] && mv -f "$logfile.$prev" "$logfile.$max_retained" - max_retained=$prev - done - mv -f "$logfile" "$logfile.$max_retained" - fi + logfile="$1" + max_retained="5" + if [[ -f $logfile ]]; then + while [[ $max_retained -gt 1 ]]; do + prev=$((max_retained - 1)) + [ -f "$logfile.$prev" ] && mv -f "$logfile.$prev" "$logfile.$max_retained" + max_retained=$prev + done + mv -f "$logfile" "$logfile.$max_retained" + fi } function get_group() { - # Find the group parameter if any - local group="default" - local param - for param in "$@"; do - if [[ $param =~ ^[a-z]*[.]group=(.*)$ ]]; then - group="${BASH_REMATCH[1]}" - fi - done - echo "$group" + # Find the group parameter if any + local group="default" + local param + for param in "$@"; do + if [[ $param =~ ^[a-z]*[.]group=(.*)$ ]]; then + group="${BASH_REMATCH[1]}" + fi + done + echo "$group" } function start_service() { - local service_type=$1 - local service_name=$2 - shift 2 - - local build_service_name="false" - if [[ -n $service_name ]]; then - # if service_name is supplied, then we are only starting one instance - servers_per_host=1 - else - build_service_name="true" - servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} - fi - - for ((process_num = 1; process_num <= servers_per_host; process_num++)); do - if [[ ${build_service_name} == "true" ]]; then - service_name="${service_type}_${group}_${process_num}" - fi - # The ACCUMULO_SERVICE_INSTANCE variable is used in - # accumulo-env.sh to set parameters on the command - # line. - export ACCUMULO_SERVICE_INSTANCE="${service_name}" - - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - if [[ -f $pid_file ]]; then - pid=$(cat "$pid_file") - if kill -0 "$pid" 2>/dev/null; then - echo "$HOST : ${service_name} already running (${pid})" - continue - fi - fi - echo "Starting $service_name on $HOST" - - if [[ ${service_type} == "manager" ]]; then - "${bin}/accumulo" org.apache.accumulo.manager.state.SetGoalState NORMAL - fi - outfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.out" - errfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.err" - rotate_log "$outfile" - rotate_log "$errfile" - - nohup "${bin}/accumulo" "proc" "$service_type" "$@" >"$outfile" 2>"$errfile" "${pid_file}" - - done - - # Check the max open files limit and selectively warn - max_files_open=$(ulimit -n) - if [[ -n $max_files_open ]]; then - max_files_recommended=32768 - if ((max_files_open < max_files_recommended)); then - echo "WARN : Max open files on $HOST is $max_files_open, recommend $max_files_recommended" >&2 - fi - fi + local service_type=$1 + local service_name=$2 + shift 2 + + local build_service_name="false" + if [[ -n $service_name ]]; then + # if service_name is supplied, then we are only starting one instance + servers_per_host=1 + else + build_service_name="true" + servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} + fi + + for ((process_num = 1; process_num <= servers_per_host; process_num++)); do + if [[ ${build_service_name} == "true" ]]; then + service_name="${service_type}_${group}_${process_num}" + fi + # The ACCUMULO_SERVICE_INSTANCE variable is used in + # accumulo-env.sh to set parameters on the command + # line. + export ACCUMULO_SERVICE_INSTANCE="${service_name}" + + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + if [[ -f $pid_file ]]; then + pid=$(cat "$pid_file") + if kill -0 "$pid" 2>/dev/null; then + echo "$HOST : ${service_name} already running (${pid})" + continue + fi + fi + echo "Starting $service_name on $HOST" + + if [[ ${service_type} == "manager" ]]; then + "${bin}/accumulo" org.apache.accumulo.manager.state.SetGoalState NORMAL + fi + outfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.out" + errfile="${ACCUMULO_LOG_DIR}/${service_name}_${HOST}.err" + rotate_log "$outfile" + rotate_log "$errfile" + + nohup "${bin}/accumulo" "proc" "$service_type" "$@" >"$outfile" 2>"$errfile" "${pid_file}" + + done + + # Check the max open files limit and selectively warn + max_files_open=$(ulimit -n) + if [[ -n $max_files_open ]]; then + max_files_recommended=32768 + if ((max_files_open < max_files_recommended)); then + echo "WARN : Max open files on $HOST is $max_files_open, recommend $max_files_recommended" >&2 + fi + fi } function control_process() { - local kill_code=$1 - local service_name=$2 - local pid_file=$3 - if [[ -f $pid_file ]]; then - echo "Stopping $service_name on $HOST" - kill -s "$kill_code" "$(cat "$pid_file")" 2>/dev/null - rm -f "${pid_file}" 2>/dev/null - fi + local kill_code=$1 + local service_name=$2 + local pid_file=$3 + if [[ -f $pid_file ]]; then + echo "Stopping $service_name on $HOST" + kill -s "$kill_code" "$(cat "$pid_file")" 2>/dev/null + rm -f "${pid_file}" 2>/dev/null + fi } function find_processes() { - local service_type=$1 - local file - local filepath - local expected_pid - local found_pid - # Clear the array. - RUNNING_PROCESSES=() - for filepath in "$ACCUMULO_PID_DIR"/*; do - if [[ $filepath =~ ^.*/accumulo-("$service_type".*)[.]pid$ ]]; then - file="${BASH_REMATCH[1]}" - expected_pid=$(<"$filepath") - found_pid=$(pgrep -F "$filepath" -f "$file") - if [[ $found_pid != "$expected_pid" ]]; then - echo "removing stale pid file $filepath" >&2 - rm "$filepath" - else - RUNNING_PROCESSES+=("$file") - fi - fi - done + local service_type=$1 + local file + local filepath + local expected_pid + local found_pid + # Clear the array. + RUNNING_PROCESSES=() + for filepath in "$ACCUMULO_PID_DIR"/*; do + if [[ $filepath =~ ^.*/accumulo-("$service_type".*)[.]pid$ ]]; then + file="${BASH_REMATCH[1]}" + expected_pid=$(<"$filepath") + found_pid=$(pgrep -F "$filepath" -f "$file") + if [[ $found_pid != "$expected_pid" ]]; then + echo "removing stale pid file $filepath" >&2 + rm "$filepath" + else + RUNNING_PROCESSES+=("$file") + fi + fi + done } function stop_service() { - local service_type=$1 - local service_name=$2 - local all_flag=$3 - if [[ $all_flag == 'true' ]]; then - find_processes "$service_type" - for process in "${RUNNING_PROCESSES[@]}"; do - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" - control_process "TERM" "$process" "$pid_file" - done - elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then - - servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} - group=$(get_group "$@") - - for ((process_num = 1; process_num <= servers_per_host; process_num++)); do - service_name="${service_type}_${group}_${process_num}" - echo "Stopping service process: $service_name" - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "TERM" "$service_name" "$pid_file" - done - - else - echo "Stopping service process: $service_name" - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "TERM" "$service_name" "$pid_file" - fi + local service_type=$1 + local service_name=$2 + local all_flag=$3 + if [[ $all_flag == 'true' ]]; then + find_processes "$service_type" + for process in "${RUNNING_PROCESSES[@]}"; do + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" + control_process "TERM" "$process" "$pid_file" + done + elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then + + servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} + group=$(get_group "$@") + + for ((process_num = 1; process_num <= servers_per_host; process_num++)); do + service_name="${service_type}_${group}_${process_num}" + echo "Stopping service process: $service_name" + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "TERM" "$service_name" "$pid_file" + done + + else + echo "Stopping service process: $service_name" + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "TERM" "$service_name" "$pid_file" + fi } function kill_service() { - local service_type=$1 - local service_name=$2 - local all_flag=$3 - if [[ $all_flag == 'true' ]]; then - find_processes "$service_type" - for process in "${RUNNING_PROCESSES[@]}"; do - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" - control_process "KILL" "$process" "$pid_file" - done - elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then - - servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} - group=$(get_group "$@") - - for ((process_num = 1; process_num <= servers_per_host; process_num++)); do - service_name="${service_type}_${group}_${process_num}" - echo "Stopping service process: $service_name" - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "KILL" "$service_name" "$pid_file" - done - - else - local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" - control_process "KILL" "$service_name" "$pid_file" - fi + local service_type=$1 + local service_name=$2 + local all_flag=$3 + if [[ $all_flag == 'true' ]]; then + find_processes "$service_type" + for process in "${RUNNING_PROCESSES[@]}"; do + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${process}.pid" + control_process "KILL" "$process" "$pid_file" + done + elif [[ -n $ACCUMULO_CLUSTER_ARG ]]; then + + servers_per_host=${ACCUMULO_CLUSTER_ARG:-1} + group=$(get_group "$@") + + for ((process_num = 1; process_num <= servers_per_host; process_num++)); do + service_name="${service_type}_${group}_${process_num}" + echo "Stopping service process: $service_name" + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "KILL" "$service_name" "$pid_file" + done + + else + local pid_file="${ACCUMULO_PID_DIR}/accumulo-${service_name}.pid" + control_process "KILL" "$service_name" "$pid_file" + fi } function list_processes() { - local service_type=$1 - local json_flag=$2 - find_processes "$service_type" - # Print this only if the caller doesn't want json. - if [[ $json_flag != 'true' ]]; then - echo "Currently running ${service_type} processes (fields: process pid port):" - fi - for process in "${RUNNING_PROCESSES[@]}"; do - local pid_file - local pid - local port - local loop_err - pid_file="$ACCUMULO_PID_DIR/accumulo-$process.pid" - pid=$(<"$pid_file") # read the contents of the file into the $pid variable - port=$(ss -tnlp 2>/dev/null | grep -wF "pid=$pid" | awk '{print $4}' | awk -F : '{print $NF}' | paste -sd,) - - if [[ $port =~ ^[1-9][0-9]{1,4}(,[1-9][0-9]{1,4})*$ ]]; then - - if [[ $json_flag != 'true' ]]; then - echo "$process $pid $port" - else - # If --json was specified, append the JSON to the output array. - JSON_OUTPUT+=$(jq -n -c --arg process "$process" --arg pid "$pid" --arg port "$port" '$ARGS.named') - fi - - else - echo "ERROR unexpected port format $(hostname) process:$process pid:$pid ports:$port" >&2 - loop_err=1 - fi - done - [[ -z $loop_err ]] # return non-zero if any errors occurred during the loop + local service_type=$1 + local json_flag=$2 + find_processes "$service_type" + # Print this only if the caller doesn't want json. + if [[ $json_flag != 'true' ]]; then + echo "Currently running ${service_type} processes (fields: process pid port):" + fi + for process in "${RUNNING_PROCESSES[@]}"; do + local pid_file + local pid + local port + local loop_err + pid_file="$ACCUMULO_PID_DIR/accumulo-$process.pid" + pid=$(<"$pid_file") # read the contents of the file into the $pid variable + port=$(ss -tnlp 2>/dev/null | grep -wF "pid=$pid" | awk '{print $4}' | awk -F : '{print $NF}' | paste -sd,) + + if [[ $port =~ ^[1-9][0-9]{1,4}(,[1-9][0-9]{1,4})*$ ]]; then + + if [[ $json_flag != 'true' ]]; then + echo "$process $pid $port" + else + # If --json was specified, append the JSON to the output array. + JSON_OUTPUT+=$(jq -n -c --arg process "$process" --arg pid "$pid" --arg port "$port" '$ARGS.named') + fi + + else + echo "ERROR unexpected port format $(hostname) process:$process pid:$pid ports:$port" >&2 + loop_err=1 + fi + done + [[ -z $loop_err ]] # return non-zero if any errors occurred during the loop } function main() { - if [[ -z $1 ]]; then - invalid_args " cannot be empty" - fi - - # Create a global array for process tracking - declare -a RUNNING_PROCESSES - - # Resolve base directory - SOURCE="${BASH_SOURCE[0]}" - while [ -h "${SOURCE}" ]; do - bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" - SOURCE="$(readlink "${SOURCE}")" - [[ ${SOURCE} != /* ]] && SOURCE="${bin}/${SOURCE}" - done - # Set up variables needed by accumulo-env.sh - bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" - export bin - basedir=$(cd -P "${bin}"/.. && pwd) - export basedir - export conf="${ACCUMULO_CONF_DIR:-${basedir}/conf}" - export lib="${basedir}/lib" - - group=$(get_group "$@") - export ACCUMULO_RESOURCE_GROUP="$group" - - HOST="$(hostname)" - if [[ -z $HOST ]]; then - HOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') - fi - - local service_type="$1" - local command_name="$2" - shift 2 - local service_name="" - local all_flag=false - local json_flag=false - - if [[ -f "${conf}/accumulo-env.sh" ]]; then - #shellcheck source=../conf/accumulo-env.sh - source "${conf}/accumulo-env.sh" - fi - ACCUMULO_LOG_DIR="${ACCUMULO_LOG_DIR:-${basedir}/logs}" - ACCUMULO_PID_DIR="${ACCUMULO_PID_DIR:-${basedir}/run}" - - mkdir -p "$ACCUMULO_LOG_DIR" 2>/dev/null - mkdir -p "$ACCUMULO_PID_DIR" 2>/dev/null - - # Check and see if accumulo-cluster is calling this script - if [[ -z $ACCUMULO_CLUSTER_ARG ]]; then - # The rest of the arguments are from a user - if [[ $1 == "--all" ]]; then - all_flag=true - # The caller wants the output formatted as json. - elif [[ $1 == "--json" ]]; then - json_flag=true - else - # A named service has been specified - if [[ $1 != "-o" ]]; then - service_name="$1" - fi - fi - fi - - local services - # If 'all' was specified, execute the command against all services. - if [[ $service_type == "all" ]]; then - if [[ -z $command_name ]]; then - invalid_args " cannot be empty" - elif [[ $command_name != "list" ]]; then - invalid_args "Service all can only be used with the list command" - fi - services=("gc" "manager" "monitor" "tserver" "compactor" "sserver") - else - services=("$service_type") - fi - - for service in "${services[@]}"; do - case "$service" in - gc | manager | monitor | tserver | compactor | sserver) - if [[ -z $command_name ]]; then - invalid_args " cannot be empty" - fi - case "$command_name" in - start) - start_service "$service" "$service_name" "$@" - ;; - stop) - stop_service "$service" "$service_name" $all_flag "$@" - ;; - kill) - kill_service "$service" "$service_name" $all_flag "$@" - ;; - list) - list_processes "$service" $json_flag - ;; - *) - invalid_args "'$command_name' is an invalid " - ;; - esac - ;; - *) - invalid_args "'$service' is an invalid " - ;; - esac - done - - # If --json was specified, combine the json for each process into a single json object. - if [[ $json_flag == 'true' ]]; then - printf '%s\n' "${JSON_OUTPUT[@]}" | jq -s '.' - fi + if [[ -z $1 ]]; then + invalid_args " cannot be empty" + fi + + # Create a global array for process tracking + declare -a RUNNING_PROCESSES + + # Resolve base directory + SOURCE="${BASH_SOURCE[0]}" + while [ -h "${SOURCE}" ]; do + bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" + SOURCE="$(readlink "${SOURCE}")" + [[ ${SOURCE} != /* ]] && SOURCE="${bin}/${SOURCE}" + done + # Set up variables needed by accumulo-env.sh + bin="$(cd -P "$(dirname "${SOURCE}")" && pwd)" + export bin + basedir=$(cd -P "${bin}"/.. && pwd) + export basedir + export conf="${ACCUMULO_CONF_DIR:-${basedir}/conf}" + export lib="${basedir}/lib" + + group=$(get_group "$@") + export ACCUMULO_RESOURCE_GROUP="$group" + + HOST="$(hostname)" + if [[ -z $HOST ]]; then + HOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + fi + + local service_type="$1" + local command_name="$2" + shift 2 + local service_name="" + local all_flag=false + local json_flag=false + + if [[ -f "${conf}/accumulo-env.sh" ]]; then + #shellcheck source=../conf/accumulo-env.sh + source "${conf}/accumulo-env.sh" + fi + ACCUMULO_LOG_DIR="${ACCUMULO_LOG_DIR:-${basedir}/logs}" + ACCUMULO_PID_DIR="${ACCUMULO_PID_DIR:-${basedir}/run}" + + mkdir -p "$ACCUMULO_LOG_DIR" 2>/dev/null + mkdir -p "$ACCUMULO_PID_DIR" 2>/dev/null + + # Check and see if accumulo-cluster is calling this script + if [[ -z $ACCUMULO_CLUSTER_ARG ]]; then + # The rest of the arguments are from a user + if [[ $1 == "--all" ]]; then + all_flag=true + # The caller wants the output formatted as json. + elif [[ $1 == "--json" ]]; then + json_flag=true + else + # A named service has been specified + if [[ $1 != "-o" ]]; then + service_name="$1" + fi + fi + fi + + local services + # If 'all' was specified, execute the command against all services. + if [[ $service_type == "all" ]]; then + if [[ -z $command_name ]]; then + invalid_args " cannot be empty" + elif [[ $command_name != "list" ]]; then + invalid_args "Service all can only be used with the list command" + fi + services=("gc" "manager" "monitor" "tserver" "compactor" "sserver") + else + services=("$service_type") + fi + + for service in "${services[@]}"; do + case "$service" in + gc | manager | monitor | tserver | compactor | sserver) + if [[ -z $command_name ]]; then + invalid_args " cannot be empty" + fi + case "$command_name" in + start) + start_service "$service" "$service_name" "$@" + ;; + stop) + stop_service "$service" "$service_name" $all_flag "$@" + ;; + kill) + kill_service "$service" "$service_name" $all_flag "$@" + ;; + list) + list_processes "$service" $json_flag + ;; + *) + invalid_args "'$command_name' is an invalid " + ;; + esac + ;; + *) + invalid_args "'$service' is an invalid " + ;; + esac + done + + # If --json was specified, combine the json for each process into a single json object. + if [[ $json_flag == 'true' ]]; then + printf '%s\n' "${JSON_OUTPUT[@]}" | jq -s '.' + fi } main "$@" From 9af14146c2dfbed374df1d82809a4635d39a7565 Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Fri, 21 Aug 2026 17:26:41 -0400 Subject: [PATCH 6/6] Verify jq is installed if --json given --- assemble/bin/accumulo-service | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/assemble/bin/accumulo-service b/assemble/bin/accumulo-service index 4bf427b7a1a..17da2f8b547 100755 --- a/assemble/bin/accumulo-service +++ b/assemble/bin/accumulo-service @@ -306,6 +306,11 @@ function main() { all_flag=true # The caller wants the output formatted as json. elif [[ $1 == "--json" ]]; then + # Make sure jq is installed. + if ! jq -h >&/dev/null; then + echo "Missing jq. Unable to continue." + exit 1 + fi json_flag=true else # A named service has been specified