From 4f580e0df81f27125f2c78b90795659a4b753c85 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 24 Oct 2018 10:53:00 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jms | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/jms b/jms index 244fff826..9cbf020e8 100755 --- a/jms +++ b/jms @@ -42,10 +42,26 @@ try: except: pass +def check_database_connection(): + os.chdir(os.path.join(BASE_DIR, 'apps')) + for i in range(60): + print("Check database connection ...") + code = subprocess.call("python manage.py showmigrations users ", shell=True) + if code == 0: + print("Database connect success") + return + time.sleep(1) + print("Connection database failed, exist") + sys.exit(10) + def make_migrations(): print("Check database structure change ...") os.chdir(os.path.join(BASE_DIR, 'apps')) + if len(os.listdir('assets/migrations')) < 4: + print("Make database migrations ...") + subprocess.call('python3 manage.py makemigrations', shell=True) + print("Migrate model change to database ...") subprocess.call('python3 manage.py migrate', shell=True) @@ -56,6 +72,7 @@ def collect_static(): def prepare(): + check_database_connection() make_migrations() collect_static() @@ -112,7 +129,6 @@ def parse_service(s): def start_gunicorn(): print("\n- Start Gunicorn WSGI HTTP Server") - prepare() service = 'gunicorn' bind = '{}:{}'.format(HTTP_HOST, HTTP_PORT) log_format = '%(h)s %(t)s "%(r)s" %(s)s %(b)s ' @@ -205,6 +221,7 @@ def start_service(s): print(time.ctime()) print('Jumpserver version {}, more see https://www.jumpserver.org'.format( __version__)) + prepare() services_handler = { "gunicorn": start_gunicorn,