-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetect_uwsgi.py
41 lines (38 loc) · 1.28 KB
/
detect_uwsgi.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
#!/usr/bin/env python
#coding: utf-8
import os
import nginx
import supervisord
import socket
import logging
import config
def detect_apps(srv_dir, dry_run=False):
dirs = os.listdir(srv_dir)
os.chdir(srv_dir)
for d in dirs:
# Check if domain is active (DNS check)
try:
ip = socket.gethostbyname(d)
except socket.gaierror:
logging.warning("Wrong directory name: %s" % d)
continue
if "uwsgi.ini" in os.listdir(d):
# We've found uWSGI app!
# Now create nginx vhost based on dir name
if dry_run:
logging.info("uWSGI app found in %s" % d)
else:
app_dir = "%s/%s" % (srv_dir, d)
if nginx.vhost_exists(d):
logging.info("Virtualhost %s already exists on nginx" % d)
continue
nginx.add_uwsgi_vhost(
domain_name=d,
document_root=app_dir
)
# Enable supervisord for uWSGI process
supervisord.new_app(app_name=d, app_dir=app_dir)
nginx.enable_vhost(d)
logging.info("Added new app: %s" % d)
if __name__ == "__main__":
detect_apps(config.APP_DIR)