Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restart & stop shell script #3374

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions dist/src/main/amoro-bin/bin/restart-all.sh
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions dist/src/main/amoro-bin/bin/stop-all.sh
Original file line number Diff line number Diff line change
@@ -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
Loading