blob: b1c2f1dc46f331c7018ee8984cace7f39596bc5e [file] [log] [blame]
Chris Matthews4d39f842017-08-17 20:26:33 +00001""" Script to control the deployment of LNT to Google Cloud Instance.
2
3
4"""
5
6import os
7from os.path import expanduser
8
9from fabric.api import env, cd, task, run, put
10from fabric.api import sudo
11
12here = os.path.dirname(os.path.realpath(__file__))
13
14home = expanduser("~")
15
16env.use_ssh_config = True
17
18# The remote LNT venv location.
19LNT_VENV = "/srv/lnt/sandbox"
20
21# Prefix a command with this to get to the venv.
22IN_VENV = "source " + LNT_VENV + "/bin/activate; "
23
24
25def in_venv(command):
26 """Run the command inside the LNT venv."""
27 return IN_VENV + command
28
29
30# The remote location of the LNT repo checkout.
31LNT_PATH = "/srv/lnt/src/lnt/"
32LNT_CONF_PATH = "/srv/lnt/install"
33
34
35@task
36def update():
37 """Update the svn repo, then reinstall LNT."""
38 with cd(LNT_PATH):
39 with cd(LNT_PATH + "/docs/"):
40 sudo('rm -rf _build')
41 with cd(LNT_PATH + "/lnt/server/ui/static"):
42 sudo('rm -rf docs')
43 sudo('git checkout docs')
44
45 sudo("git pull --rebase")
46 run("git log -1 --pretty=%B")
47 with cd(LNT_PATH + "/docs/"):
48 sudo(in_venv("make"))
49 sudo(IN_VENV + "python setup.py install --server")
50
51 put(here + "/blacklist", "/tmp/blacklist")
52 sudo("mv /tmp/blacklist /srv/lnt/install/blacklist")
53 put(here + "/kill_zombies.py", "/tmp/kill_zombies.py")
54 sudo("mv /tmp/kill_zombies.py /etc/cron.hourly/kill_zombies")
55 sudo("chmod +x /etc/cron.hourly/kill_zombies")
56
57 service_restart()
58
59
60@task
61def log():
62 sudo('tail -n 500 /srv/lnt/install/lnt.log')
63
64
65@task
66def ps():
67 sudo('ps auxxxf | grep gunicorn')
68
69
70@task
71def df():
72 sudo('df -h')
73
74
75@task
76def kill_zombies():
77 import re
78 out = sudo("ps auxxxf")
79 stranded = re.compile(r"^lnt\s+(?P<pid>\d+).*00\sgunicorn:\swork")
80 pids = []
81 for line in out.split('\n'):
82 m = stranded.match(line)
83 if m:
84 pid = m.groupdict()['pid']
85 pids.append(pid)
86 else:
87 print ">", line
88 for pid in pids:
89 sudo("kill -9 {}".format(pid))
90
91
92@task
93def service_restart():
94 """Restarting LNT service with Launchctl"""
95 sudo("systemctl restart gunicorn")