diff --git a/LCU/Maintenance/MDB_tools/fabfile.py b/LCU/Maintenance/MDB_tools/fabfile.py index 8654a59c39baf6cab2b32f9043ef73bb5190d1b1..ebed623637548dab195cceffd51dfbbbbf47d77b 100644 --- a/LCU/Maintenance/MDB_tools/fabfile.py +++ b/LCU/Maintenance/MDB_tools/fabfile.py @@ -2,7 +2,7 @@ from invoke import task import fabric from fabric.connection import Connection - +import time import os @@ -12,15 +12,20 @@ REMOTE_DIR = '/data/mancini/deploy/' REMOTE_INSTALL_DIR = 'installed' PATH_SETTINGS_FILE = 'lib64/python3.6/site-packages/lofar/maintenance/django_postgresql/settings.py' BASE_SETTINGS_FILE_PATH = 'settings.py' +MANAGE_SCRIPT = 'maintenance_d.sh' + + +LOG_FILE = 'django_postgres.log' users = { - 'test' : 'mancini' + 'test': 'mancini' } servers = { - 'test':'lofarmonitortest' + 'test': 'lofarmonitortest' } + def rsync_compressed(c, from_path='address', to_path='address'): to_address = '{}@{}:{}'.format(c.user, c.host, to_path) command = 'rsync -avz {} {}'.format(from_path, to_address) @@ -42,6 +47,39 @@ def copy_to_remote_server(c, type): print('deploying on host {} directory {}'.format(c.host, deploy_dir)) rsync_compressed(c, LOCAL_DIR, deploy_dir) + +def _connection(type): + host = servers[type] + user = users[type] + return Connection(host, user=user) + +@task +def run_server(c, type): + deploy_dir = os.path.join(REMOTE_DIR, type) + start_script = os.path.join(deploy_dir, MANAGE_SCRIPT) + + with _connection(type) as c: + log_path = os.path.join(deploy_dir, LOG_FILE) + + with c.cd(deploy_dir): + cmd = 'sh {} start'.format(start_script) + print('executing command',cmd) + print(c.run(cmd, pty=False)) + + time.sleep(5) + print('log can be found at', log_path) + c.run('tail {}'.format(log_path)) + +@task +def tear_down_server(c, type): + deploy_dir = os.path.join(REMOTE_DIR, type) + log_path = os.path.join(deploy_dir, LOG_FILE) + with _connection(type) as c: + user = c.user + print(c.run('killall -u {} gunicorn'.format(user))) + print(log_path) + print(c.run('tail {}'.format(log_path))) + @task def deploy_to_server(c, type): if isinstance(c, fabric.Connection): @@ -56,7 +94,6 @@ def deploy_to_server(c, type): @task def update(c): - # make with c.cd(BUILD_DIR): c.run('pwd')