-
Notifications
You must be signed in to change notification settings - Fork 2
/
fabfile.py
96 lines (78 loc) · 2.11 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from tempfile import NamedTemporaryFile
from invoke import task
import os
@task
def install(c):
"""
Clone or pull latest changes from the repo
"""
with c.cd("src/"):
if not c.run("test -d stream-lnd-htlcs-bot", warn=True).ok:
c.run("git clone https://github.com/routablespace/stream-lnd-htlcs-bot.git")
with c.cd("stream-lnd-htlcs-bot"):
c.run("git pull")
@task
def install_supervisord(c):
"""
Install supervisord
"""
c.sudo("apt-get install supervisor -y")
@task
def install_supervisord_conf(c, tg_token):
"""
Install supervisord config
"""
with open("confs/stream-lnd-htlcs-bot.conf") as f:
conf = f.read()
if tg_token:
conf = conf.replace("{OPTIONS}", f"--tg-token={tg_token}")
tf = NamedTemporaryFile(mode="w")
tf.write(conf)
tf.flush()
c.put(tf.name, "/tmp/stream-lnd-htlcs-bot.conf")
tf.close()
c.sudo("cp /tmp/stream-lnd-htlcs-bot.conf /etc/supervisor/conf.d/")
c.sudo("supervisorctl update all")
@task
def start(c):
"""
Start the app
"""
c.sudo("supervisorctl start stream-lnd-htlcs-bot")
@task
def stop(c):
"""
Stop the app
"""
c.sudo("supervisorctl stop stream-lnd-htlcs-bot")
@task
def restart(c):
"""
Restart the app
"""
stop(c)
start(c)
@task
def clear_logs(c):
"""
Clear the logs
"""
c.run("rm /home/ubuntu/logs/stream-lnd-htlcs-bot.*")
@task
def logs(c):
"""
Tail the logs
"""
c.run("tail -f /home/ubuntu/logs/stream-lnd-htlcs-bot.*")
@task
def sync(c, env=dict(KEYPEM=os.environ["KEYPEM"])):
"""
Perform an rsync to test latest changes
"""
c.run(f"mkdir -p /home/{c.user}/src/stream-lnd-htlcs-bot/")
cmd = f"""rsync -azv -e 'ssh -i {env["KEYPEM"]}' . {c.user}@{c.host}:/home/{c.user}/src/stream-lnd-htlcs-bot/ --exclude stream-lnd-htlcs-bot.db"""
c.run(f"mkdir -p /home/{c.user}/src/stream-lnd-htlcs-bot/")
print(cmd)
c.local(cmd)
with c.cd(f"/home/{c.user}/src/stream-lnd-htlcs-bot/"):
c.run("pip3 install -r requirements.txt")