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 @@ ...@@ -2,7 +2,7 @@
from invoke import task from invoke import task
import fabric import fabric
from fabric.connection import Connection from fabric.connection import Connection
import time
import os import os
...@@ -12,6 +12,10 @@ REMOTE_DIR = '/data/mancini/deploy/' ...@@ -12,6 +12,10 @@ REMOTE_DIR = '/data/mancini/deploy/'
REMOTE_INSTALL_DIR = 'installed' REMOTE_INSTALL_DIR = 'installed'
PATH_SETTINGS_FILE = 'lib64/python3.6/site-packages/lofar/maintenance/django_postgresql/settings.py' PATH_SETTINGS_FILE = 'lib64/python3.6/site-packages/lofar/maintenance/django_postgresql/settings.py'
BASE_SETTINGS_FILE_PATH = 'settings.py' BASE_SETTINGS_FILE_PATH = 'settings.py'
MANAGE_SCRIPT = 'maintenance_d.sh'
LOG_FILE = 'django_postgres.log'
users = { users = {
'test': 'mancini' 'test': 'mancini'
...@@ -21,6 +25,7 @@ servers = { ...@@ -21,6 +25,7 @@ servers = {
'test': 'lofarmonitortest' 'test': 'lofarmonitortest'
} }
def rsync_compressed(c, from_path='address', to_path='address'): def rsync_compressed(c, from_path='address', to_path='address'):
to_address = '{}@{}:{}'.format(c.user, c.host, to_path) to_address = '{}@{}:{}'.format(c.user, c.host, to_path)
command = 'rsync -avz {} {}'.format(from_path, to_address) command = 'rsync -avz {} {}'.format(from_path, to_address)
...@@ -42,6 +47,39 @@ def copy_to_remote_server(c, type): ...@@ -42,6 +47,39 @@ def copy_to_remote_server(c, type):
print('deploying on host {} directory {}'.format(c.host, deploy_dir)) print('deploying on host {} directory {}'.format(c.host, deploy_dir))
rsync_compressed(c, LOCAL_DIR, 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 @task
def deploy_to_server(c, type): def deploy_to_server(c, type):
if isinstance(c, fabric.Connection): if isinstance(c, fabric.Connection):
...@@ -56,7 +94,6 @@ def deploy_to_server(c, type): ...@@ -56,7 +94,6 @@ def deploy_to_server(c, type):
@task @task
def update(c): def update(c):
# make # make
with c.cd(BUILD_DIR): with c.cd(BUILD_DIR):
c.run('pwd') c.run('pwd')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment