2016-09-01 15:09:58 +00:00
|
|
|
#!/usr/bin/env python
|
2016-09-01 15:10:28 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
|
|
|
|
|
|
|
from threading import Thread
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
try:
|
|
|
|
from config import config as env_config, env
|
|
|
|
|
|
|
|
CONFIG = env_config.get(env, 'default')()
|
|
|
|
except ImportError:
|
|
|
|
CONFIG = type('_', (), {'__getattr__': None})()
|
|
|
|
|
|
|
|
|
|
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
apps_dir = os.path.join(BASE_DIR, 'apps')
|
|
|
|
|
|
|
|
|
|
|
|
def start_django():
|
2017-01-07 12:07:33 +00:00
|
|
|
http_host = CONFIG.HTTP_BIND_HOST or '127.0.0.1'
|
2016-09-02 16:39:06 +00:00
|
|
|
http_port = CONFIG.HTTP_LISTEN_PORT or '8080'
|
2016-09-01 15:10:28 +00:00
|
|
|
os.chdir(apps_dir)
|
|
|
|
print('start django')
|
2017-04-07 11:11:27 +00:00
|
|
|
subprocess.call('python ./manage.py runserver %s:%s' % (http_host, http_port), shell=True)
|
2016-09-01 15:10:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def start_celery():
|
|
|
|
os.chdir(apps_dir)
|
2016-11-09 15:49:10 +00:00
|
|
|
os.environ.setdefault('C_FORCE_ROOT', '1')
|
2017-03-14 06:15:13 +00:00
|
|
|
os.environ.setdefault('PYTHONOPTIMIZE', '1')
|
2016-09-01 15:10:28 +00:00
|
|
|
print('start celery')
|
2017-04-05 11:09:51 +00:00
|
|
|
subprocess.call('celery -A common worker -B -s /tmp/celerybeat-schedule -l debug', shell=True)
|
2016-09-01 15:10:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
t1 = Thread(target=start_django, args=())
|
|
|
|
t2 = Thread(target=start_celery, args=())
|
|
|
|
|
|
|
|
t1.start()
|
|
|
|
t2.start()
|
|
|
|
|
|
|
|
t1.join()
|
|
|
|
t2.join()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|
2016-09-01 15:09:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|