| | |
| | import os, signal, socket, subprocess, sys, time |
| |
|
| | DBOPS_ROOT = os.environ.get('DBOPS_ROOT', '/data/adaptai/platform/dbops') |
| | CFG = os.path.join(DBOPS_ROOT, 'run', 'janusgraph', 'gremlin-server.runtime.yaml') |
| | BIN_DIR = os.path.join(DBOPS_ROOT, 'binaries', 'janusgraph', 'bin') |
| | STARTER = os.path.join(DBOPS_ROOT, 'tools', 'start_janusgraph_daemon.sh') |
| |
|
| | stop_requested = False |
| |
|
| | def handle_signal(signum, frame): |
| | global stop_requested |
| | stop_requested = True |
| |
|
| | signal.signal(signal.SIGTERM, handle_signal) |
| | signal.signal(signal.SIGINT, handle_signal) |
| |
|
| | def port_open(host='127.0.0.1', port=17002, timeout=1.0): |
| | try: |
| | with socket.create_connection((host, port), timeout=timeout): |
| | return True |
| | except Exception: |
| | return False |
| |
|
| | def stop_jg(): |
| | for name in ('gremlin-server.sh', 'janusgraph-server.sh'): |
| | p = os.path.join(BIN_DIR, name) |
| | if os.path.exists(p): |
| | try: |
| | subprocess.run([p, 'stop', CFG], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| | except Exception: |
| | pass |
| |
|
| | def ensure_started(): |
| | |
| | subprocess.run([STARTER], check=True) |
| |
|
| | def main(): |
| | ensure_started() |
| | |
| | while not stop_requested: |
| | if not port_open(): |
| | |
| | sys.exit(1) |
| | time.sleep(2) |
| | |
| | stop_jg() |
| | sys.exit(0) |
| |
|
| | if __name__ == '__main__': |
| | main() |
| |
|
| |
|