Skip to content
Snippets Groups Projects
Commit 77f113b9 authored by Mattia Mancini's avatar Mattia Mancini
Browse files

Story SW-300: fixing deploying scripts

parent a3c750a2
No related branches found
No related tags found
2 merge requests!89Monitoring maintenance Epic branch merge,!1Resolve OSB-13 "Monitoringmaintenance "
......@@ -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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment