-
Notifications
You must be signed in to change notification settings - Fork 791
GUACAMOLE-2086: Add Tomcat HealthCheckValve #1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmunozv04
wants to merge
3
commits into
apache:main
Choose a base branch
from
dmunozv04:GUACAMOLE-2086-HealthCheckValve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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
54
guacamole-docker/environment/HEALTH_CHECK_VALVE_/configure.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_PATHvariable:There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...