diff --git a/dist/src/main/amoro-bin/bin/restart-all.sh b/dist/src/main/amoro-bin/bin/restart-all.sh new file mode 100644 index 0000000000..7452e01499 --- /dev/null +++ b/dist/src/main/amoro-bin/bin/restart-all.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Check for JAVA_HOME and set JPS_PATH accordingly +if [[ -d $JAVA_HOME ]]; then + JPS_PATH="$JAVA_HOME/bin/jps" +else + JPS_PATH="jps" # Fallback to system's PATH +fi + +# Log file +LOG_FILE="restart_process.log" + +# Define an array of target process names +TARGET_PROCESSES=("AmoroServiceContainer" "StandaloneOptimizer") + +# Iterate over each target process name +for TARGET_PROCESS in "${TARGET_PROCESSES[@]}"; do + echo "$(date): Checking for process '$TARGET_PROCESS'..." | tee -a "$LOG_FILE" + + # Find the PID of the target process + PID=$($JPS_PATH | grep "$TARGET_PROCESS" | awk '{print $1}') + + if [[ -z "$PID" ]]; then + echo "$(date): No process found matching '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + continue + fi + + echo "$(date): Found process '$TARGET_PROCESS' with PID $PID." | tee -a "$LOG_FILE" + + # Retrieve the command line using ps + CMDLINE=$(ps -o args= -p "$PID") + + if [[ -z "$CMDLINE" ]]; then + echo "$(date): Failed to retrieve command line for PID $PID." | tee -a "$LOG_FILE" + continue + fi + + echo "$(date): Retrieved command line for '$TARGET_PROCESS': $CMDLINE" | tee -a "$LOG_FILE" + + # Kill the process + echo "$(date): Attempting to kill process with PID $PID for '$TARGET_PROCESS'..." | tee -a "$LOG_FILE" + kill "$PID" + + # Check if the process was successfully killed + if [[ $? -eq 0 ]]; then + echo "$(date): Successfully killed process with PID $PID for '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + else + echo "$(date): Failed to kill process with PID $PID for '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + continue + fi + + # Restart the process + echo "$(date): Restarting process '$TARGET_PROCESS' with original command line..." | tee -a "$LOG_FILE" + eval "$CMDLINE" & + + # Check if the restart was successful + if [[ $? -eq 0 ]]; then + echo "$(date): Successfully restarted process '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + else + echo "$(date): Failed to restart process '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + fi +done \ No newline at end of file diff --git a/dist/src/main/amoro-bin/bin/stop-all.sh b/dist/src/main/amoro-bin/bin/stop-all.sh new file mode 100644 index 0000000000..15a2f766af --- /dev/null +++ b/dist/src/main/amoro-bin/bin/stop-all.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Check for JAVA_HOME and set JPS_PATH accordingly +if [[ -d $JAVA_HOME ]]; then + JPS_PATH="$JAVA_HOME/bin/jps" +else + JPS_PATH="jps" # Fallback to system's PATH +fi + +# Define an array of target process names +TARGET_PROCESSES=("StandaloneOptimizer" "AmoroServiceContainer") + +# Specify the log file +LOG_FILE="kill_process.log" + +# Iterate over each target process name +for TARGET_PROCESS in "${TARGET_PROCESSES[@]}"; do + # Get the PIDs of all matching target processes using jps + PIDS=$($JPS_PATH | grep "$TARGET_PROCESS" | awk '{print $1}') + + # Check if any PIDs were found + if [ -z "$PIDS" ]; then + echo "$(date): No processes found matching '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + continue + fi + + # Iterate through each PID and attempt to kill the process + echo "$(date): Found processes matching '$TARGET_PROCESS': $PIDS." | tee -a "$LOG_FILE" + for PID in $PIDS; do + echo "$(date): Attempting to kill process with PID $PID for '$TARGET_PROCESS'..." | tee -a "$LOG_FILE" + kill "$PID" + + # Check the kill status + if [ $? -eq 0 ]; then + echo "$(date): Successfully killed process with PID $PID for '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + else + echo "$(date): Failed to kill process with PID $PID for '$TARGET_PROCESS'." | tee -a "$LOG_FILE" + fi + done +done \ No newline at end of file