Browse Source

fix: 修改启动脚本

pull/6619/head
Bai 3 years ago committed by Jiangjie.Bai
parent
commit
7959f84bba
  1. 15
      apps/common/management/commands/services/services/base.py
  2. 21
      jms

15
apps/common/management/commands/services/services/base.py

@ -117,11 +117,6 @@ class BaseService(object):
sig = 9 if force else 15
os.kill(self.pid, sig)
try:
self.process.wait(2)
except:
pass
for i in range(self.STOP_TIMEOUT):
if i == self.STOP_TIMEOUT - 1:
print("\033[31m Error\033[0m")
@ -143,14 +138,10 @@ class BaseService(object):
def _check(self):
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(f"{now} Check service status: {self.name} -> ", end='')
try:
self.process.wait(timeout=1) # 不wait,子进程可能无法回收
except subprocess.TimeoutExpired:
pass
if self.is_running:
print(f'running at {self.process.pid}')
print(f'running at {self.pid}')
else:
print(f'stopped with code: {self.process.returncode}({self.process.pid})')
print(f'stopped at {self.pid}')
def _restart(self):
if self.retry > self.max_retry:
@ -158,7 +149,7 @@ class BaseService(object):
self.EXIT_EVENT.set()
return
self.retry += 1
logging.info(f'> Find {self.name} stopped, retry {self.retry}, {self.process.pid}')
logging.info(f'> Find {self.name} stopped, retry {self.retry}, {self.pid}')
self.start()
def _rotate_log(self):

21
jms

@ -56,7 +56,7 @@ def check_database_connection():
logging.info("Database connect success")
return
time.sleep(1)
logging.error("Connection database failed, exist")
logging.error("Connection database failed, exit")
sys.exit(10)
@ -85,7 +85,11 @@ def perform_db_migrate():
logging.info("Check database structure change ...")
os.chdir(os.path.join(BASE_DIR, 'apps'))
logging.info("Migrate model change to database ...")
subprocess.call('python3 manage.py migrate', shell=True)
_code = subprocess.call('python3 manage.py migrate', shell=True)
if _code == 0:
return
logging.error('Perform migrate failed, exit')
sys.exit(11)
def collect_static():
@ -96,18 +100,19 @@ def collect_static():
logging.info("Collect static files done")
def upgrade_db():
collect_static()
perform_db_migrate()
def prepare():
# installer(check) & k8s(no check)
check_database_connection()
check_migrations()
upgrade_db()
expire_caches()
def upgrade_db():
collect_static()
perform_db_migrate()
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="""
@ -139,7 +144,7 @@ if __name__ == '__main__':
upgrade_db()
else:
services = args.services if isinstance(args.services, list) else [args.services]
if action == 'start' and ({'gunicorn', 'all'} & set(services)):
if action == 'start' and {'all', 'web'} & set(services):
prepare()
services_string = ' '.join(services)

Loading…
Cancel
Save