Skip to content

Commit

Permalink
HDDS-12011. Show PID of running service. (apache#7648)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvekshayr authored Jan 6, 2025
1 parent ab161dd commit 3d35b01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion hadoop-ozone/dist/src/shell/ozone/ozone
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ function check_running_ozone_services
for service in "${services[@]}"; do
for pid_file in ${OZONE_PID_DIR}/ozone-*-${service}.pid; do
if [[ -f "${pid_file}" ]]; then
if kill -0 "$(cat "${pid_file}")" 2>/dev/null; then
pid=$(cat "${pid_file}")
if kill -0 "${pid}" 2>/dev/null; then
export "OZONE_${service^^}_RUNNING=true"
export "OZONE_${service^^}_PID=${pid}"
fi
fi
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ public final Void call() throws Exception {
}

protected boolean checkIfServiceIsRunning(String serviceName) {
String envVariable = String.format("OZONE_%s_RUNNING", serviceName);
String runningServices = System.getenv(envVariable);
if ("true".equals(runningServices)) {
String runningEnvVar = String.format("OZONE_%s_RUNNING", serviceName);
String pidEnvVar = String.format("OZONE_%s_PID", serviceName);
String isServiceRunning = System.getenv(runningEnvVar);
String servicePid = System.getenv(pidEnvVar);
if ("true".equals(isServiceRunning)) {
if (!force) {
error("Error: %s is currently running on this host. " +
"Stop the service before running the repair tool.", serviceName);
error("Error: %s is currently running on this host with PID %s. " +
"Stop the service before running the repair tool.", serviceName, servicePid);
return true;
} else {
info("Warning: --force flag used. Proceeding despite %s being detected as running.", serviceName);
info("Warning: --force flag used. Proceeding despite %s being detected as running with PID %s.",
serviceName, servicePid);
}
} else {
info("No running %s service detected. Proceeding with repair.", serviceName);
Expand Down

0 comments on commit 3d35b01

Please sign in to comment.