-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.py
executable file
·85 lines (70 loc) · 2.04 KB
/
manage.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
#!/usr/bin/env python
import sys
import os
import sh
import pwd
from scripts.utils import *
def create_site(site):
'''
Create the site directory from the template
1. copy the template
2. change permissions
/ rwxr-xr-x site:site_grp
|-- app rwx------ site:site_grp
`-- static rwxr-s--- site:web
'''
ss = loc_site(site)
gid = pwd.getpwnam(site).pw_gid
print "Create site dir for %s..." % site,
if os.path.exists(ss):
print 'Already existing'
else:
sh.cp('-a', PATH_SITE_TEMPLATE, ss)
print "OK"
# process root
print 'chown %s:%s %s ...' % (site, gid, ss),
sh.chown('-R', '%s:%s' % (site, gid), ss)
print 'Ok'
print 'chmod 755 %s ...' % ss,
sh.chmod('755', ss)
print 'Ok'
# process app dir
app_dir = loc_app_dir(site)
print 'chmod 700 %s ...' % app_dir,
sh.chmod('700', app_dir)
print 'Ok'
# process static dir
static_dir = loc_static_dir(site)
print 'chown %s:%s %s ...' % (site, WEB_GID, static_dir),
sh.chown('-R', '%s:%s' % (site, WEB_GID), static_dir)
print 'Ok'
print 'chmod 2750 %s ...' % static_dir,
sh.chmod('2750', static_dir)
print 'Ok'
def enable_site(site):
uc = loc_uwsgi_conf(site)
ss = loc_site(site)
if not os.path.exists(ss):
print "%s does not exist" % site
elif os.path.exists(uc):
print "%s is already enabled" % site
else:
sh.ln('-s', PATH_VASSAL_CONF, uc)
print "Successfully enabled %s" % site
def disable_site(site):
uc = loc_uwsgi_conf(site)
if not os.path.exists(uc):
print "%s is not enabled" % site
else:
sh.rm(uc)
print "Successfully disabled %s" % site
if __name__ == "__main__":
if len(sys.argv) != 3:
print "Usage: ./manage.py <site> <command>"
exit(1)
if sh.whoami().strip() != 'root':
print sh.whoami().strip(), "you must be root !"
exit(1)
site,cmd = sys.argv[1::]
func = locals()[cmd+'_site']
func(site)