Skip to content

Commit

Permalink
Gracefully handle cases where the selected USER_ID and/or GROUP_ID exist
Browse files Browse the repository at this point in the history
  • Loading branch information
julienchastang committed Jul 29, 2024
1 parent eb703d9 commit 872a091
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ if [ "$1" = 'startram.sh' ]; then
###
# Tomcat user
###
groupadd -r tomcat -g ${GROUP_ID} && \
useradd -u ${USER_ID} -g tomcat -d ${CATALINA_HOME} -s /sbin/nologin \
-c "Tomcat user" tomcat
# create group for GROUP_ID if one doesn't already exist
if ! getent group $GROUP_ID &> /dev/null; then
groupadd -r tomcat -g $GROUP_ID
fi
# create user for USER_ID if one doesn't already exist
if ! getent passwd $USER_ID &> /dev/null; then
useradd -u $USER_ID -g $GROUP_ID tomcat
fi
# alter USER_ID with nologin shell and CATALINA_HOME home directory
usermod -d "${CATALINA_HOME}" -s /sbin/nologin $(id -u -n $USER_ID)

###
# Change CATALINA_HOME ownership to tomcat user and tomcat group
# Restrict permissions on conf
# Ensure RAMADDA data directory is owned by tomcat
###

chown -R tomcat:tomcat ${CATALINA_HOME} && \
chown -R tomcat:tomcat ${DATA_DIR} && \
chmod 400 ${CATALINA_HOME}/conf/*
chown -R $USER_ID:$GROUP_ID ${CATALINA_HOME} ${DATA_DIR} && find ${CATALINA_HOME}/conf \
-type d -exec chmod 755 {} \; -o -type f -exec chmod 400 {} \;

sync
exec gosu tomcat "$@"
Expand Down

0 comments on commit 872a091

Please sign in to comment.