Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ COMMAND="${JAVA_BIN} ${JAVA_ARGS} ${LOG_APPENDER} \
${TK_ARGS} \
${@}"

pushd "${INSTALL_DIR}" &> /dev/null
if [ "$EUID" = "0" ] && command -v runuser &> /dev/null; then
runuser "${USER}" -s /bin/bash -c "$COMMAND"
elif [ "$EUID" = "$(id -u ${USER})" ]; then
/bin/bash -c "$COMMAND"
elif command -v sudo &> /dev/null; then
sudo -H -u "${USER}" $COMMAND
else
su "${USER}" -s /bin/bash -c "$COMMAND"
cd "${INSTALL_DIR}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a new behaviour, previously pushd also assumed INSTALL_DIR to exist, but the error happened silently (&> /dev/null). Since there is no set -e here it'd continue either way, using cd or not, except that right now it's visible due to no redirection of stderr.

Also, the reason I swapped to cd was that popd was unreachable anyways, exec replaces the shell with the JVM. popd/pushd does not make sense here. Going to edit my PR body to mention this.

if [ "$EUID" = "0" ] && [ -n "${USER}" ] && command -v runuser &> /dev/null; then
# started as root: drop to the service user
exec runuser "${USER}" -s /bin/bash -c "$COMMAND"
fi
Comment thread
dotconfig404 marked this conversation as resolved.
popd &> /dev/null
# containers set the runtime UID before this script runs (USER directive,
# --user, runAsUser), so run as the current user - whatever UID that is
exec /bin/bash -c "$COMMAND"