Skip to content

Modify MySQL healthcheck to wait for script completion. Updated the d…#570

Open
savemyfiles wants to merge 4 commits intowso2:masterfrom
savemyfiles:master
Open

Modify MySQL healthcheck to wait for script completion. Updated the d…#570
savemyfiles wants to merge 4 commits intowso2:masterfrom
savemyfiles:master

Conversation

@savemyfiles
Copy link
Copy Markdown

@savemyfiles savemyfiles commented Jan 9, 2026

…ocker-compose healthcheck for MySQL to ensure dependent services like IS-AS-KM start only after the database initialization scripts have completed.

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • Chores
    • Tightened MySQL health checks across Compose setups: readiness now requires both initialization and a successful in-database verification, with existing cadence preserved—improving accuracy of service readiness and reducing false-positive healthy states during startup.

✏️ Tip: You can customize this high-level summary in your review settings.

…ocker-compose healthcheck for MySQL to ensure dependent services like IS-AS-KM start only after the database initialization scripts have completed.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 9, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 9, 2026

Walkthrough

MySQL healthchecks in three docker-compose files now require successful mysqladmin ping, presence of /var/lib/mysql/initialization-complete.flag, and execution of SELECT 1 FROM UM_ORG LIMIT 1 against WSO2AM_SHARED_DB. One file also added an explicit interval: 30s line.

Changes

Cohort / File(s) Summary
apim-is-as-km-with-analytics docker-compose
docker-compose/apim-is-as-km-with-analytics/docker-compose.yml
Healthcheck now requires: mysqladmin ping, presence of /var/lib/mysql/initialization-complete.flag, and mysql -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1'.
apim-with-analytics docker-compose
docker-compose/apim-with-analytics/docker-compose.yml
Healthcheck updated to include SELECT 1 FROM UM_ORG LIMIT 1 in addition to mysqladmin ping and the init flag; timing and retries unchanged.
apim-with-mi docker-compose
docker-compose/apim-with-mi/docker-compose.yml
Healthcheck updated to require mysqladmin ping, init flag, and SELECT 1 FROM UM_ORG LIMIT 1. An interval: 30s line was added (may duplicate existing interval).

Sequence Diagram(s)

(omitted — changes are confined to container healthchecks and do not introduce multi-component control flow requiring a sequence diagram)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hop through compose at break of day,

I ping and peek where flags do lay.
A tiny SELECT, brave and spry,
Says databases wake — oh my! 🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only the template structure with placeholder text and no substantive content in any required sections (Goals, Approach, User stories, etc.), making it largely unfilled. Fill in all required sections with concrete information: Goals, Approach, User stories, Release note, Documentation, Security checks, and Test environment details.
Title check ❓ Inconclusive The title is truncated and incomplete ('Modify MySQL healthcheck to wait for script completion. Updated the d…'), making it unclear and difficult to understand the full intent of the change. Provide a complete, clear title that fully describes the main change without truncation.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0223abe and 34695db.

📒 Files selected for processing (2)
  • docker-compose/apim-is-as-km-with-analytics/docker-compose.yml
  • docker-compose/apim-with-mi/docker-compose.yml
🚧 Files skipped from review as they are similar to previous changes (2)
  • docker-compose/apim-with-mi/docker-compose.yml
  • docker-compose/apim-is-as-km-with-analytics/docker-compose.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef6bb79 and 0b5ebf2.

📒 Files selected for processing (1)
  • docker-compose/apim-is-as-km-with-analytics/docker-compose.yml

command: [--ssl=0]
healthcheck:
test: ["CMD", "sh", "-c", "mysqladmin ping -uroot -proot && [ -f /var/lib/mysql/initialization-complete.flag ]"]
test: ["CMD", "mysql", "-h", "localhost", "-uroot", "-proot", "-D", "WSO2AM_SHARED_DB", "-e", "SELECT 1 FROM UM_ORG LIMIT 1;"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's explore the structure and find the initialization scripts
find . -type f -name "docker-compose*.yml" | head -20

Repository: wso2/docker-apim

Length of output: 229


🏁 Script executed:

# Find SQL and shell scripts in the conf directory
fd -e sql -e sh . ./conf --max-results 20

Repository: wso2/docker-apim

Length of output: 153


🏁 Script executed:

# Check if the conf/mysql/scripts directory exists and what's in it
ls -la docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts 2>/dev/null || echo "Path not found, searching..."
find . -path "*conf/mysql/scripts*" -type f

Repository: wso2/docker-apim

Length of output: 1039


🏁 Script executed:

# Examine the mysql_shared.sql file to see if WSO2AM_SHARED_DB and UM_ORG are created
cat "./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/mysql_shared.sql" | head -100

Repository: wso2/docker-apim

Length of output: 4978


🏁 Script executed:

# Check the z_health_check.sh script
cat "./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/z_health_check.sh"

Repository: wso2/docker-apim

Length of output: 924


🏁 Script executed:

# Search for initialization-complete.flag references
rg -n "initialization-complete.flag" 2>/dev/null || echo "No matches found"

Repository: wso2/docker-apim

Length of output: 781


🏁 Script executed:

# Check if the docker-compose.yml file has the healthcheck at line 32
sed -n '25,40p' "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml"

Repository: wso2/docker-apim

Length of output: 599


🏁 Script executed:

# Search for UM_ORG table in the SQL files
rg -n "UM_ORG" ./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/

Repository: wso2/docker-apim

Length of output: 4160


🏁 Script executed:

# Check the full mysql_shared.sql file to see where UM_ORG is created (if at all)
wc -l ./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/mysql_shared.sql

Repository: wso2/docker-apim

Length of output: 145


🏁 Script executed:

# Search for UM_ORG in ALL SQL files across all docker-compose directories
rg -n "UM_ORG" --type sql

Repository: wso2/docker-apim

Length of output: 11556


🏁 Script executed:

# Check if z_health_check.sh is mounted in the reviewed docker-compose file
sed -n '15,35p' "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml"

Repository: wso2/docker-apim

Length of output: 620


🏁 Script executed:

# Check the mysql service volumes section in the reviewed file
rg -n "volumes:" -A 10 "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml" | grep -E "^[0-9]+:" | head -30

Repository: wso2/docker-apim

Length of output: 107


🏁 Script executed:

# Compare all three docker-compose files' mysql healthcheck sections
echo "=== apim-is-as-km-with-analytics ===" && \
sed -n '32p' "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml" && \
echo "=== apim-with-analytics ===" && \
sed -n '32p' "./docker-compose/apim-with-analytics/docker-compose.yml" && \
echo "=== apim-with-mi ===" && \
sed -n '32p' "./docker-compose/apim-with-mi/docker-compose.yml"

Repository: wso2/docker-apim

Length of output: 516


Inconsistent healthcheck implementation across docker-compose files.

The new SQL-based healthcheck in this file differs from the other docker-compose configurations, which still use mysqladmin ping && [ -f /var/lib/mysql/initialization-complete.flag ]. This creates maintenance burden and potential confusion.

Additionally, z_health_check.sh still exists and creates /var/lib/mysql/initialization-complete.flag as the final initialization step (the z_ prefix ensures it runs last), but this flag is no longer checked by the healthcheck. Either:

  1. Update all docker-compose files (apim-with-analytics, apim-with-mi) to use the SQL query approach, or
  2. Keep the flag-based approach consistently across all setups and remove the SQL query healthcheck

The z_health_check.sh script should not create an unused flag file.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In @docker-compose/apim-is-as-km-with-analytics/docker-compose.yml:
- Line 32: The healthcheck block currently has the `test` and `interval` on the
same line causing a YAML syntax error; update the `healthcheck` entry so that
`test:` remains a single key (with its array value) and `interval:` is moved to
its own line indented at the same level as `test:` (e.g., under `healthcheck:`
alongside `test:`) so `test` and `interval` are separate keys; ensure
indentation matches other healthcheck keys (like `retries` or `timeout`) to
restore valid docker-compose YAML.

In @docker-compose/apim-with-analytics/docker-compose.yml:
- Line 32: The YAML has a syntax error because the healthcheck `test` array and
the `interval` key are on the same line; in the `healthcheck` block split
`test:` and `interval:` onto separate lines with `interval:` indented at the
same level as `test:` (e.g., under `healthcheck`), keeping the existing `["CMD",
"sh", "-c", "mysqladmin ping -uroot -proot && [ -f
/var/lib/mysql/initialization-complete.flag ] && mysql -h localhost -uroot
-proot -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"]` value for
`test` and placing `interval: 30s` on its own line beneath it so the YAML parses
correctly.

In @docker-compose/apim-with-mi/docker-compose.yml:
- Line 32: The healthcheck in docker-compose.yml has `test` and `interval` on
the same line causing a YAML syntax error; edit the `healthcheck` block so
`test:` remains as the array value (the current ["CMD", "sh", "-c", "..."]) and
move `interval:` onto its own line with the same indentation level as `test`
(e.g., under `healthcheck`), ensuring `interval: 30s` is a separate mapping
entry; verify the block uses proper YAML indentation so `test` and `interval`
are sibling keys within `healthcheck`.
- Around line 32-33: The healthcheck block defines the same key twice: remove
the duplicate "interval" entry so only a single "interval" exists under the
healthcheck for the service that contains the "test" command (the healthcheck
with test ["CMD", "sh", "-c", "mysqladmin ping -uroot -proot && [ -f
/var/lib/mysql/initialization-complete.flag ] && mysql -h localhost -uroot
-proot -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"]). Ensure you
keep one "interval" line (the correct value) and delete the other to avoid YAML
parsing errors.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b5ebf2 and 76a4346.

📒 Files selected for processing (3)
  • docker-compose/apim-is-as-km-with-analytics/docker-compose.yml
  • docker-compose/apim-with-analytics/docker-compose.yml
  • docker-compose/apim-with-mi/docker-compose.yml
🧰 Additional context used
🪛 YAMLlint (1.37.1)
docker-compose/apim-with-mi/docker-compose.yml

[error] 32-32: syntax error: expected , but found ''

(syntax)

docker-compose/apim-with-analytics/docker-compose.yml

[error] 32-32: syntax error: expected , but found ''

(syntax)

docker-compose/apim-is-as-km-with-analytics/docker-compose.yml

[error] 32-32: syntax error: expected , but found ''

(syntax)

🔇 Additional comments (3)
docker-compose/apim-is-as-km-with-analytics/docker-compose.yml (1)

32-32: The healthcheck is correctly implemented.

The UM_ORG table is created and populated in the mysql_shared.sql initialization script. The table is defined with proper schema and includes an initial 'Super' organization record, ensuring the SELECT 1 FROM UM_ORG LIMIT 1; query will succeed once initialization completes.

docker-compose/apim-with-mi/docker-compose.yml (1)

32-32: The UM_ORG table is correctly created during initialization.

Confirmed: The initialization script docker-compose/apim-with-mi/conf/mysql/scripts/mysql_shared.sql creates the UM_ORG table with CREATE TABLE IF NOT EXISTS UM_ORG, along with initial data (Super organization). The healthcheck properly waits for the /var/lib/mysql/initialization-complete.flag before running the SELECT query, ensuring the table exists before dependent services start.

docker-compose/apim-with-analytics/docker-compose.yml (1)

32-32: Verify that the UM_ORG table exists after initialization.

The healthcheck queries SELECT 1 FROM UM_ORG LIMIT 1; from the WSO2AM_SHARED_DB database. The initialization script at ./conf/mysql/scripts/mysql_shared.sql creates this table with CREATE TABLE IF NOT EXISTS UM_ORG (...) and populates it with initial data. The api-manager service will not start until the MySQL healthcheck passes, ensuring the table exists before dependent services attempt to connect.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @docker-compose/apim-is-as-km-with-analytics/docker-compose.yml:
- Around line 33-34: The mysql service healthcheck contains a duplicate key
"interval: 30s"; remove the redundant entry so the healthcheck block for the
mysql service only declares interval once (locate the mysql service's
healthcheck section in the docker-compose.yml and delete the extra "interval:
30s" line).
🧹 Nitpick comments (2)
docker-compose/apim-with-analytics/docker-compose.yml (1)

31-33: Harden the MySQL healthcheck (timeouts + reduce password exposure) and verify UM_ORG is always present.

The new query check is directionally good for “init scripts completed”, but it can (a) hang longer than needed without client connect timeouts, and (b) fail forever if UM_ORG isn’t guaranteed for the targeted product/version/profile. Also, -proot leaks in process listings.

Proposed update
 healthcheck:
-  test: ["CMD", "sh", "-c", "mysqladmin ping -uroot -proot && [ -f /var/lib/mysql/initialization-complete.flag ] && mysql -h localhost -uroot -proot -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"]
+  test: ["CMD", "sh", "-c", "MYSQL_PWD=$$MYSQL_ROOT_PASSWORD mysqladmin ping -uroot --silent --connect-timeout=5 && [ -f /var/lib/mysql/initialization-complete.flag ] && MYSQL_PWD=$$MYSQL_ROOT_PASSWORD mysql -h localhost -uroot --connect-timeout=5 -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"]
   interval: 30s
docker-compose/apim-is-as-km-with-analytics/docker-compose.yml (1)

31-33: Same healthcheck hardening concerns as the other compose file (timeouts/password) + validate UM_ORG assumption.

Consider the same MYSQL_PWD + --connect-timeout adjustments here as well (see suggested diff in the other file’s comment) to avoid long hangs and reduce password exposure, and confirm UM_ORG is always created by the init scripts for the versions/profiles you ship.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76a4346 and 0223abe.

📒 Files selected for processing (3)
  • docker-compose/apim-is-as-km-with-analytics/docker-compose.yml
  • docker-compose/apim-with-analytics/docker-compose.yml
  • docker-compose/apim-with-mi/docker-compose.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • docker-compose/apim-with-mi/docker-compose.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants