Skip to content

Commit

Permalink
[PLAT-16669] Check the exit status of semanage command in node agent …
Browse files Browse the repository at this point in the history
…installer

Summary: Minor change to check the exit code of the command.

Test Plan: Tested manually by creating a CSP universe.

Reviewers: anijhawan, svarshney

Reviewed By: svarshney

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D41700
  • Loading branch information
nkhogen committed Feb 5, 2025
1 parent ddbe2e6 commit 5c3ca57
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions managed/node-agent/resources/node-agent-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ run_as_super_user() {
else
sudo "$@"
fi
return $?
}

check_run_as_super_user() {
run_as_super_user "$@"
exit_code=$?
if [ "$exit_code" -ne 0 ]; then
echo "Command failed with exit code $exit_code - $@"
exit $exit_code
fi
}

# Function to run systemd commands as the target user
Expand Down Expand Up @@ -282,17 +292,17 @@ modify_selinux() {
if command -v semanage >/dev/null 2>&1; then
run_as_super_user semanage port -lC | grep -F "$NODE_PORT" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
run_as_super_user semanage port -a -t http_port_t -p tcp "$NODE_PORT"
check_run_as_super_user semanage port -a -t http_port_t -p tcp "$NODE_PORT"
fi
run_as_super_user semanage fcontext -lC | grep -F "$NODE_AGENT_HOME(/.*)?" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
run_as_super_user semanage fcontext -a -t bin_t "$NODE_AGENT_HOME(/.*)?"
check_run_as_super_user semanage fcontext -a -t bin_t "$NODE_AGENT_HOME(/.*)?"
fi
run_as_super_user restorecon -ir "$NODE_AGENT_HOME"
check_run_as_super_user restorecon -ir "$NODE_AGENT_HOME"
else
# Let it proceed as there can be policies to allow.
echo "Command semanage does not exist. Defaulting to using chcon"
run_as_super_user chcon -R -t bin_t "$NODE_AGENT_HOME"
check_run_as_super_user chcon -R -t bin_t "$NODE_AGENT_HOME"
fi
set -e
}
Expand Down

0 comments on commit 5c3ca57

Please sign in to comment.