bitflicker64 commented on issue #3043:
URL: https://github.com/apache/hugegraph/issues/3043#issuecomment-4582925686
## Implementation Plan
Breaking the work into independently reviewable and testable chunks. Each
chunk has its own test script, can be reviewed in isolation, and builds on the
previous one.
---
### Chunk 1 — Fix `start-hugegraph.sh` foreground mode
**File:**
`hugegraph-server/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh`
**Problem:** All post-branch logic (`PID="$!"`, pid file write, `trap`,
`wait_for_startup`, `disown`, `OPEN_MONITOR`) runs unconditionally after the
daemon/foreground if/else block. In foreground mode the script blocks at
`hugegraph-server.sh` until Java exits, then all those lines run with `$!`
empty/stale, `wait_for_startup` immediately fails (Java already dead), and the
script exits 0 losing Java's exit code entirely.
**Fix:** Move all post-branch logic inside the `DAEMON == "true"` branch.
Add `exit $?` to the foreground branch so Java's exit code propagates out.
**Test:**
`hugegraph-server/hugegraph-dist/src/assembly/travis/test-start-hugegraph.sh`
---
### Chunk 2 — Add `-d` flag to `start-hugegraph-pd.sh`
**File:**
`hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh`
**Problem:** No foreground mode exists — Java is always backgrounded
unconditionally with `exec java ... &`. No `-d` flag. `wait_for_startup` exists
in pd's `util.sh` but is never called — daemon startup has no health polling at
all, callers compensate with hardcoded `sleep 10`.
**Fix:** Add `DAEMON="true"` default (consistent with existing style in this
file), add `-d` to `getopts`, split the `exec java` block into
daemon/foreground branches, wire up `wait_for_startup` in daemon mode, add
`exit $?` to foreground branch.
**Test:**
`hugegraph-pd/hg-pd-dist/src/assembly/travis/test-start-hugegraph-pd.sh`
---
### Chunk 3 — Add `-d` flag to `start-hugegraph-store.sh`
**File:**
`hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh`
**Problem:** Identical to chunk 2 — no foreground mode, always backgrounds
Java unconditionally.
**Fix:** Identical structure to chunk 2.
**Test:**
`hugegraph-store/hg-store-dist/src/assembly/travis/test-start-hugegraph-store.sh`
---
### Chunk 4 — Fix pd entrypoint
**File:** `hugegraph-pd/hg-pd-dist/docker/docker-entrypoint.sh`
**Problem:**
```bash
./bin/start-hugegraph-pd.sh -j "${JAVA_OPTS:-}"
tail -f /dev/null # ← zero supervision
```
**Fix:** Pass `-d false` now that pd has foreground mode. Remove `tail -f
/dev/null`. When Java exits the script exits, container exits, restart policy
fires.
```bash
./bin/start-hugegraph-pd.sh -d false -j "${JAVA_OPTS:-}"
# no tail needed — blocks until Java exits, exits with Java's exit code
```
---
### Chunk 5 — Fix store entrypoint
**File:** `hugegraph-store/hg-store-dist/docker/docker-entrypoint.sh`
**Problem:** Same as chunk 4.
**Fix:** Same as chunk 4 but for store.
---
### Chunk 6 — Fix server entrypoint
**File:** `hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh`
**Problem:**
```bash
./bin/start-hugegraph.sh -j "${JAVA_OPTS:-}" -t 120
# post-startup checks including wait-partition.sh for hstore...
tail -f /dev/null # ← zero supervision
```
**Why `-d false` alone doesn't work here:** `wait-partition.sh` must run
after the server is already up in the background. The structure must stay:
start in background → post-startup checks → then supervise.
**Fix:** Keep the background start and all post-startup checks unchanged.
Replace only `tail -f /dev/null` with `wait $(cat ./bin/pid)`. When Java exits
`wait` returns immediately, entrypoint exits with non-zero, container exits,
restart policy fires.
```bash
./bin/start-hugegraph.sh -j "${JAVA_OPTS:-}" -t 120
# post-startup checks preserved exactly as-is
ACTUAL_BACKEND=$(...)
if [[ "${ACTUAL_BACKEND}" == "hstore" ]]; then
./bin/wait-partition.sh || log "WARN: partitions not assigned yet"
fi
# replace tail -f /dev/null:
wait "$(cat ./bin/pid)"
exit $?
```
---
### Chunk 7 — Add `HEALTHCHECK` to all four Dockerfiles
**Files:** `hugegraph-server/Dockerfile`,
`hugegraph-server/Dockerfile-hstore`, `hugegraph-pd/Dockerfile`,
`hugegraph-store/Dockerfile`
**Problem:** No `HEALTHCHECK` in any Dockerfile. Health checks only exist in
`docker-compose.yml`. Plain `docker run` has no health reporting. `depends_on:
condition: service_healthy` relies on compose injecting the check at runtime
rather than it being baked into the image.
**Fix:** Add `HEALTHCHECK` to each Dockerfile before `ENTRYPOINT`, mirroring
the exact values already in `docker-compose.yml`:
```dockerfile
# hugegraph-pd/Dockerfile
HEALTHCHECK --interval=10s --timeout=5s --retries=12 --start-period=30s \
CMD curl -fsS http://localhost:8620/v1/health >/dev/null || exit 1
# hugegraph-store/Dockerfile
HEALTHCHECK --interval=10s --timeout=10s --retries=30 --start-period=60s \
CMD curl -fsS http://localhost:8520/v1/health >/dev/null || exit 1
# hugegraph-server/Dockerfile + Dockerfile-hstore
HEALTHCHECK --interval=10s --timeout=5s --retries=30 --start-period=60s \
CMD curl -fsS http://localhost:8080/versions >/dev/null || exit 1
```
---
### Chunk 8 — Remove `cron` from all four Dockerfiles
**Files:** All four Dockerfiles
**Problem:** `cron` is installed but `crond` is never started — it has no
purpose in the image now that supervision is Docker-native.
**Fix:** Remove `cron` from the `apt-get install` step in all four
Dockerfiles. Keep `dumb-init`, `procps`, `curl`, `lsof`.
**What stays untouched:**
- `monitor-hugegraph.sh` — preserved, still valid for VM deployments
- `start-monitor.sh` — preserved, still valid for VM deployments
- `docker-compose.yml` healthcheck definitions — already correct, no changes
needed
---
### Chunk 9 — Fix default `restserver.url` scheme
**File:**
`hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties`
**Problem:** Shipped default is `restserver.url=127.0.0.1:8080` — no
`http://` scheme. `wait_for_startup` passes this raw value to curl. On macOS,
curl fails with "Protocol not supported" causing `start-hugegraph.sh` to always
exit 1 on local development even though the server starts correctly. On Linux,
curl happens to handle scheme-less URLs by defaulting to HTTP — masking the bug.
Every other config in the repo uses `http://` explicitly: raft CI configs,
the Dockerfile `sed` patch, cluster test templates, and Java `ServerOptions`
default. The shipped default is the only inconsistency.
**Fix:** Change line 3 of `rest-server.properties` from `127.0.0.1:8080` to
`http://127.0.0.1:8080`.
---
### Chunk 10 — Docs
Update relevant README or `docker/` docs to explain:
- Docker deployments use native process supervision — the entrypoint watches
the Java process and exits when it dies, triggering `restart: unless-stopped`
- `HEALTHCHECK` is now baked into the Dockerfiles so `docker ps` reports
health without needing compose
- `start-hugegraph.sh -m true` (cron-based monitor) is for VM/bare-metal
deployments only — unchanged and fully functional
---
### Blast radius
All existing callers of `start-hugegraph.sh`, `start-hugegraph-pd.sh`, and
`start-hugegraph-store.sh` pass no `-d` flag and rely on the default
`DAEMON="true"`. Daemon mode behavior is completely unchanged. Only new callers
that explicitly pass `-d false` (the Docker entrypoints after this PR) are
affected by chunks 1-3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]