From cc4cef8609109560323bdae5fdbd43b805010ed8 Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Mon, 8 Apr 2024 11:13:16 +0200 Subject: [PATCH] Ensure CrateDB process gets terminated on cr8 sigterm The CrateDB process leaked if `cr8 run-crate` was killed via a SIGTERM. For example, in a bash script like: cr8 run-crate latest-nightly & N1=$! while ! crash --hosts localhost:4200 -c "select 1" > /dev/null 2>&1; do sleep 1 done jps kill $N1 jps --- cr8/run_crate.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cr8/run_crate.py b/cr8/run_crate.py index b6d426a..de72c8b 100644 --- a/cr8/run_crate.py +++ b/cr8/run_crate.py @@ -18,12 +18,13 @@ import socket import ssl import platform +import signal from datetime import datetime from hashlib import sha1 from pathlib import Path from functools import partial from itertools import cycle -from typing import Optional, Dict, Any, List, NamedTuple +from typing import Dict, Any, List, NamedTuple from urllib.request import urlopen from cr8.java_magic import find_java_home @@ -790,6 +791,12 @@ def run_crate( keep_data, java_magic=not disable_java_magic, ) as n: + + def stop(signum, frame): + n.stop() + sys.exit(0) + + signal.signal(signal.SIGTERM, stop) try: n.start() n.process.wait()