Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ USER guacamole
# Environment variable defaults
ENV BAN_ENABLED=true \
ENABLE_FILE_ENVIRONMENT_PROPERTIES=true \
GUACAMOLE_HOME=/etc/guacamole
GUACAMOLE_HOME=/etc/guacamole \
HEALTH_CHECK_VALVE_ENABLED=true

# Start Guacamole under Tomcat, listening on 0.0.0.0:8080
EXPOSE 8080
HEALTHCHECK --interval=60s --timeout=10s --start-period=30s \
CMD ["/opt/guacamole/bin/healthcheck.sh"]
CMD ["/opt/guacamole/bin/entrypoint.sh" ]
40 changes: 40 additions & 0 deletions guacamole-docker/bin/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash -e
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

##
## @fn healthcheck.sh
##
## Performs a health check for the Guacamole container. If HEALTH_CHECK_VALVE_ENABLED
## is set to "true", this script will check the actual health endpoint. Otherwise,
## it will simply return success and log that health checks are disabled.
##


# Check if health check valve is enabled
if [ "$HEALTH_CHECK_VALVE_ENABLED" = "true" ]; then
# Default health check path (/health)
HEALTH_CHECK_PATH="${HEALTH_CHECK_VALVE_PATH:-/health}"
# Perform actual health check via curl
curl --fail --silent --show-error "http://localhost:8080${HEALTH_CHECK_PATH}" || exit 1
Comment on lines +31 to +35
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of concerns about the HEALTH_CHECK_VALVE_PATH variable:

  • It looks like it assumes that an absolute path will be provided?
  • What happens if the user provides a relative path (no leading /), both here and in the server.xml file?

Copy link
Author

Choose a reason for hiding this comment

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

I assumed an absolute path would be provided since it looks like tomcat only supports absolute paths:
https://github.com/apache/tomcat/blob/eaea7503163e44ba7260c9c7b3af3f4ba387d072/java/org/apache/catalina/valves/HealthCheckValve.java#L82

If the user provides a relative path, the health check won't be reachable and curl will complain: "curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535\n"

Maybe a check can be added when loading the variables to warn the user if the path is not absolute.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I would think checking the variable would be the right way to go...

else
# Health check valve is disabled - just return OK
echo "Health check valve is disabled. Reporting healthy without actual check."
exit 0
fi
54 changes: 54 additions & 0 deletions guacamole-docker/environment/HEALTH_CHECK_VALVE_/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

##
## @fn HEALTH_CHECK_VALVE_/configure.sh
##
## Configures Tomcat HealthCheckValve to provide a basic health check endpoint if
## the HEALTH_CHECK_VALVE_ENABLED environment variable is set to "true".

##
## Array of all xmlstarlet command-line options necessary to add the
## HealthCheckValve attributes that correspond to various "HEALTH_CHECK_VALVE_*"
## environment variables.
##

declare -a VALVE_ATTRIBUTES=( --insert '/Server/Service/Engine/Host/Valve[not(@className)]' --type attr -n className -v org.apache.catalina.valves.HealthCheckValve )

# Translate all properties supported by HealthCheckValve into corresponding
# environment variables
for ATTRIBUTE in \
path \
checkContainersAvailable; do

VAR_NAME="HEALTH_CHECK_VALVE_$(echo "$ATTRIBUTE" | sed 's/\([a-z]\)\([A-Z]\)/\1_\2/g' | tr 'a-z' 'A-Z')"
if [ -n "${!VAR_NAME}" ]; then
VALVE_ATTRIBUTES+=( --insert '/Server/Service/Engine/Host/Valve[@className="org.apache.catalina.valves.HealthCheckValve"]' --type attr -n "$ATTRIBUTE" -v "${!VAR_NAME}" )
else
echo "Using default HealthCheckValve value for \"$ATTRIBUTE\" attribute."
fi

done

# Programmatically add requested HealthCheckValve entry
xmlstarlet edit --inplace \
--insert '/Server/Service/Engine/Host/*' --type elem -n Valve \
"${VALVE_ATTRIBUTES[@]}" \
"$CATALINA_BASE/conf/server.xml"