2018-07-13 14:51:00 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-03-29 22:37:28 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-04-05 14:36:01 +02:00
|
|
|
from bgpranking.libs.helpers import get_homedir, check_running
|
2018-03-29 22:37:28 +02:00
|
|
|
from subprocess import Popen
|
|
|
|
import time
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
def launch_cache(storage_directory: Path=None):
|
|
|
|
if not storage_directory:
|
|
|
|
storage_directory = get_homedir()
|
2018-04-05 14:36:01 +02:00
|
|
|
if not check_running('ris') and not check_running('prefixes'):
|
2018-03-30 14:33:33 +02:00
|
|
|
Popen(["./run_redis.sh"], cwd=(storage_directory / 'cache'))
|
2018-03-29 22:37:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
def shutdown_cache(storage_directory: Path=None):
|
|
|
|
if not storage_directory:
|
|
|
|
storage_directory = get_homedir()
|
|
|
|
Popen(["./shutdown_redis.sh"], cwd=(storage_directory / 'cache'))
|
|
|
|
|
|
|
|
|
|
|
|
def launch_temp(storage_directory: Path=None):
|
|
|
|
if not storage_directory:
|
|
|
|
storage_directory = get_homedir()
|
2018-04-05 14:36:01 +02:00
|
|
|
if not check_running('intake') and not check_running('prepare'):
|
2018-03-30 14:33:33 +02:00
|
|
|
Popen(["./run_redis.sh"], cwd=(storage_directory / 'temp'))
|
2018-03-29 22:37:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
def shutdown_temp(storage_directory: Path=None):
|
|
|
|
if not storage_directory:
|
|
|
|
storage_directory = get_homedir()
|
|
|
|
Popen(["./shutdown_redis.sh"], cwd=(storage_directory / 'temp'))
|
|
|
|
|
|
|
|
|
|
|
|
def launch_storage(storage_directory: Path=None):
|
|
|
|
if not storage_directory:
|
|
|
|
storage_directory = get_homedir()
|
2018-04-05 14:36:01 +02:00
|
|
|
if not check_running('storage'):
|
2018-03-30 14:33:33 +02:00
|
|
|
Popen(["./run_ardb.sh"], cwd=(storage_directory / 'storage'))
|
2018-03-29 22:37:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
def shutdown_storage(storage_directory: Path=None):
|
|
|
|
if not storage_directory:
|
|
|
|
storage_directory = get_homedir()
|
|
|
|
Popen(["./shutdown_ardb.sh"], cwd=(storage_directory / 'storage'))
|
|
|
|
|
|
|
|
|
|
|
|
def launch_all():
|
|
|
|
launch_cache()
|
|
|
|
launch_temp()
|
|
|
|
launch_storage()
|
|
|
|
|
|
|
|
|
|
|
|
def check_all(stop=False):
|
2018-04-05 14:36:01 +02:00
|
|
|
backends = [['ris', False], ['prefixes', False], ['storage', False],
|
|
|
|
['intake', False], ['prepare', False]]
|
2018-03-29 22:37:28 +02:00
|
|
|
while True:
|
|
|
|
for b in backends:
|
|
|
|
try:
|
2018-04-05 14:36:01 +02:00
|
|
|
b[1] = check_running(b[0])
|
2018-03-29 22:37:28 +02:00
|
|
|
except Exception:
|
2018-04-05 14:36:01 +02:00
|
|
|
b[1] = False
|
2018-03-29 22:37:28 +02:00
|
|
|
if stop:
|
2018-04-05 14:36:01 +02:00
|
|
|
if not any(b[1] for b in backends):
|
2018-03-29 22:37:28 +02:00
|
|
|
break
|
|
|
|
else:
|
2018-04-05 14:36:01 +02:00
|
|
|
if all(b[1] for b in backends):
|
2018-03-29 22:37:28 +02:00
|
|
|
break
|
|
|
|
for b in backends:
|
2018-04-05 14:36:01 +02:00
|
|
|
if not stop and not b[1]:
|
2018-04-10 00:20:59 +02:00
|
|
|
print(f"Waiting on {b[0]}")
|
2018-04-05 14:36:01 +02:00
|
|
|
if stop and b[1]:
|
2018-04-10 00:20:59 +02:00
|
|
|
print(f"Waiting on {b[0]}")
|
2018-03-29 22:37:28 +02:00
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
def stop_all():
|
|
|
|
shutdown_cache()
|
|
|
|
shutdown_temp()
|
|
|
|
shutdown_storage()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description='Manage backend DBs.')
|
|
|
|
parser.add_argument("--start", action='store_true', default=False, help="Start all")
|
|
|
|
parser.add_argument("--stop", action='store_true', default=False, help="Stop all")
|
|
|
|
parser.add_argument("--status", action='store_true', default=True, help="Show status")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.start:
|
|
|
|
launch_all()
|
|
|
|
if args.stop:
|
|
|
|
stop_all()
|
|
|
|
if not args.stop and args.status:
|
|
|
|
check_all()
|