Files
datastore/ci/jobs/scripts/server_cleanup.py
zeekayandHanzo Dev ee284e8075 finish the rebrand where a person actually reads it
The fork already renamed its internals - the built binary is datastore, the
packages are datastore-server and friends, and the shipped config.xml already
says Datastore - but the surfaces a human reads still said ClickHouse. Issue
templates asked which ClickHouse version was affected, the PR template told
contributors to close upstream's issues, and CI job names, log lines, error
messages and argparse descriptions named a product this repo does not ship.

Only prose moved: display names, log and error messages, comments, docstrings
and form labels. Everything a machine resolves stayed exactly as it was,
because renaming those breaks a build rather than a sentence - binary and path
tokens such as clickhouse-client and /etc/clickhouse-server, python and shell
identifiers, CLICKHOUSE_* environment variables, the /ClickHouse container
mount, docker images in a namespace we do not own, S3 buckets, maven and pypi
coordinates, and every URL pointing at upstream. The attribution in NOTICE and
README is untouched.

Two links were wrong rather than merely stale, so they are corrected here. The
PR template's Closes and Related placeholders sent contributors to upstream's
tracker instead of this one, and an earlier pass had rewritten a source
reference to github.com/Datastore/Datastore, which does not resolve.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-14 14:07:52 -07:00

45 lines
1.8 KiB
Python

from ci.praktika.info import Info
from ci.praktika.utils import Shell, Utils
def kill_leftover_server_processes():
"""Kill Datastore server processes leaked by a previous CI job.
Runners are reused across jobs, and a job that is cancelled or times out
can leave its clickhouse-server running or slowly shutting down. Such a
leftover keeps the server ports, so the next job's server fails every
listen with `Address already in use` and its `wait_ready` times out with
an opaque `Connection refused`.
Call this from every entry point that starts the job's own server on the
host, right before the first start. At that moment the current job has not
started any server yet, so anything matching here is a leftover from a
previous job and is stale by definition. Never runs locally: a local run
may share the machine with a developer's own server that must not be
touched.
"""
if Info().is_local_run:
return
# The bracket in the pattern also keeps pkill from matching the shell that
# runs it: the literal `clickhouse[- ]server` in that shell's own cmdline
# does not match the regex it denotes.
pattern = "clickhouse[- ]server"
leftovers = Shell.get_output(f"pgrep -a -f '{pattern}'").strip()
if not leftovers:
return
print(
"WARNING: killing leftover datastore server processes"
f" from a previous job:\n{leftovers}"
)
Shell.check(f"pkill -9 -f '{pattern}'", verbose=True)
for _ in range(10):
if not Shell.get_output(f"pgrep -f '{pattern}'").strip():
break
Utils.sleep(1)
else:
print("WARNING: leftover datastore server processes survived SIGKILL")
Info().add_workflow_warning(
"Leftover datastore server processes from a previous job"
" were found and killed, see job.log"
)