Skip to content

Commit

Permalink
Add ability to run as root (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
NyakudyaA authored Sep 17, 2023
1 parent 844c7a2 commit a27e040
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
35 changes: 22 additions & 13 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,34 @@ export JAVA_OPTS="${JAVA_OPTS} ${GEOSERVER_OPTS}"


# Chown again - seems to fix issue with resolving all created directories
dir_ownership=(${CATALINA_HOME} /home/"${USER_NAME}"/ "${COMMUNITY_PLUGINS_DIR}"
"${STABLE_PLUGINS_DIR}" "${GEOSERVER_HOME}" /usr/share/fonts/ /tomcat_apps.zip
/tmp/ "${FOOTPRINTS_DATA_DIR}" "${CERT_DIR}" "${FONTS_DIR}" /scripts/
"${EXTRA_CONFIG_DIR}")
for directory in "${dir_ownership[@]}"; do
if [[ $(stat -c '%U' ${directory}) != "${USER_NAME}" ]] && [[ $(stat -c '%G' ${directory}) != "${GEO_GROUP_NAME}" ]];then
chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" ${directory}
fi
done

if [[ ${RUN_AS_ROOT} =~ [Ff][Aa][Ll][Ss][Ee] ]];then
dir_ownership=(${CATALINA_HOME} /home/"${USER_NAME}"/ "${COMMUNITY_PLUGINS_DIR}"
"${STABLE_PLUGINS_DIR}" "${GEOSERVER_HOME}" /usr/share/fonts/ /tomcat_apps.zip
/tmp/ "${FOOTPRINTS_DATA_DIR}" "${CERT_DIR}" "${FONTS_DIR}" /scripts/
"${EXTRA_CONFIG_DIR}")
for directory in "${dir_ownership[@]}"; do
if [[ $(stat -c '%U' ${directory}) != "${USER_NAME}" ]] && [[ $(stat -c '%G' ${directory}) != "${GEO_GROUP_NAME}" ]];then
chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" ${directory}
fi
done
fi

chmod o+rw "${CERT_DIR}";gwc_file_perms ;chmod 400 ${CATALINA_HOME}/conf/*

if [[ ${SAMPLE_DATA} =~ [Tt][Rr][Uu][Ee] ]]; then
chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" "${GEOSERVER_DATA_DIR}"
fi

if [[ -f ${GEOSERVER_HOME}/start.jar ]]; then
exec gosu ${USER_NAME} ${GEOSERVER_HOME}/bin/startup.sh
if [[ ${RUN_AS_ROOT} =~ [Ff][Aa][Ll][Ss][Ee] ]];then
if [[ -f ${GEOSERVER_HOME}/start.jar ]]; then
exec gosu ${USER_NAME} ${GEOSERVER_HOME}/bin/startup.sh
else
exec gosu ${USER_NAME} /usr/local/tomcat/bin/catalina.sh run
fi
else
exec gosu ${USER_NAME} /usr/local/tomcat/bin/catalina.sh run
if [[ -f ${GEOSERVER_HOME}/start.jar ]]; then
exec ${GEOSERVER_HOME}/bin/startup.sh
else
exec /usr/local/tomcat/bin/catalina.sh run
fi
fi
4 changes: 4 additions & 0 deletions scripts/env-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,7 @@ if [ -z "${SHOW_PASSWORD}" ]; then
# For runtime only, do not change at build-time.
SHOW_PASSWORD=true
fi

if [ -z "${RUN_AS_ROOT}" ]; then
RUN_AS_ROOT=false
fi

0 comments on commit a27e040

Please sign in to comment.