This repository has been archived by the owner on Oct 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
fabfile.py
64 lines (47 loc) · 1.61 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
import time
from fabric.api import run, execute, env
environment = "production"
env.use_ssh_config = True
env.hosts = ["shaaaaa"]
branch = "master"
repo = "[email protected]:konklone/shaaaaaaaaaaaaa.git"
username = "shaaaaa"
home = "/home/%s/%s" % (username, username)
shared_path = "%s/shared" % home
versions_path = "%s/versions" % home
version_path = "%s/%s" % (versions_path, time.strftime("%Y%m%d%H%M%S"))
current_path = "%s/current" % home
logs = "/home/%s" % username
keep = 5
def checkout():
run('git clone -q -b %s %s %s' % (branch, repo, version_path))
def dependencies():
run('cd %s && npm install' % version_path)
# TODO: why did I do this? (cp instead of ln)
def make_current():
# run('rm -f %s && ln -s %s %s' % (current_path, version_path, current_path))
run('rm -rf %s && cp -r %s %s' % (current_path, version_path, current_path))
def cleanup():
versions = run("ls -x %s" % versions_path).split()
destroy = versions[:-keep]
for version in destroy:
command = "rm -rf %s/%s" % (versions_path, version)
run(command)
## can be run on their own
def start():
# run("cd %s && NODE_ENV=%s forever -l %s/forever.log -a start app.js -p 3000" % (current_path, environment, logs))
run(("cd %s && " +
"NODE_ENV=%s forever -l %s/forever.log -a start app.js 3000 && " +
"NODE_ENV=%s forever -l %s/forever.log -a start app.js 3001") %
(current_path, environment, logs, environment, logs)
)
def stop():
run("forever stop app.js")
def restart():
run("forever restart app.js")
def deploy():
execute(checkout)
execute(dependencies)
execute(make_current)
execute(restart)
execute(cleanup)