diff --git a/apps/assets/views/__pycache__/server.cpython-36.pyc b/apps/assets/views/__pycache__/server.cpython-36.pyc index d1c25d6..80e09bb 100644 Binary files a/apps/assets/views/__pycache__/server.cpython-36.pyc and b/apps/assets/views/__pycache__/server.cpython-36.pyc differ diff --git a/apps/assets/views/server.py b/apps/assets/views/server.py index 255eaaf..7d07d9a 100644 --- a/apps/assets/views/server.py +++ b/apps/assets/views/server.py @@ -263,6 +263,7 @@ def get(self, request ,format=None): # username = request.query_params.get('username') # 改用后端验证登录用户信息 auth_key = request.COOKIES.get('auth_key', None) + # print(auth_key) if not auth_key:return Response('未登陆',status=401) user_info = jwt.decode(auth_key, verify=False) username = user_info['data']['username'] if 'data' in user_info else 'guest' diff --git a/apps/ws/__pycache__/handler.cpython-36.pyc b/apps/ws/__pycache__/handler.cpython-36.pyc index 34c8408..2af80c6 100644 Binary files a/apps/ws/__pycache__/handler.cpython-36.pyc and b/apps/ws/__pycache__/handler.cpython-36.pyc differ diff --git a/docker-compose.yml b/docker-compose.yml index 1990b1b..ba19984 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ cmdb: volumes: - /var/log/supervisor/:/var/log/supervisor/ - /var/www/SuperCMDB/:/var/www/CMDB/ - # - /root/.ssh/:/root/.ssh/ + - /root/.ssh/:/root/.ssh/ - /sys/fs/cgroup:/sys/fs/cgroup ports: - "8002:80" diff --git a/docs/nginx_cmdb.conf b/docs/nginx_cmdb.conf index a1e3a1f..1e64587 100644 --- a/docs/nginx_cmdb.conf +++ b/docs/nginx_cmdb.conf @@ -4,6 +4,11 @@ upstream cmdb{ server 127.0.0.1:9002; } +upstream ws{ + server 127.0.0.1:9901; +} + + server { listen 80; @@ -23,15 +28,19 @@ server location /v1/cmdb/ws/ { # proxy_set_header Host $http_host; - proxy_redirect off; + # proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; - proxy_pass http://cmdb; + proxy_pass http://ws; proxy_http_version 1.1; proxy_set_header Upgrade websocket; proxy_set_header Connection Upgrade; - #proxy_set_header Upgrade $http_upgrade; - #proxy_set_header Connection "upgrade"; + # proxy_set_header Upgrade $http_upgrade; + # proxy_set_header Connection "upgrade"; + proxy_connect_timeout 600s; + proxy_read_timeout 36000s; + proxy_send_timeout 600s; + } location /v1/cmdb/ { diff --git a/docs/supervisor_cmdb.conf b/docs/supervisor_cmdb.conf index c383e18..8947ddb 100644 --- a/docs/supervisor_cmdb.conf +++ b/docs/supervisor_cmdb.conf @@ -2,7 +2,7 @@ nodaemon=true [program:cmdb] -command=python3 startup.py --port=90%(process_num)02d +command=python3 startup.py --service=cmdb --port=90%(process_num)02d process_name=%(program_name)s_%(process_num)02d numprocs=3 directory=/var/www/CMDB @@ -15,6 +15,18 @@ loglevel=info logfile_maxbytes=100MB logfile_backups=3 +[program:ws] +command=python3 startup.py --service=ws --port=9901 +directory=/var/www/CMDB +user=root +autostart=true +autorestart=true +redirect_stderr=true +stdout_logfile=/var/log/supervisor/cmdb_ws.log +loglevel=info +logfile_maxbytes=100MB +logfile_backups=3 + [program:nginx] command=/usr/sbin/nginx -g "daemon off;" autostart=true diff --git a/requirements.txt b/requirements.txt index 81e8f3f..1e2a219 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ pyte==0.8.0 paramiko==2.4.2 shortuuid==0.5.0 PyJWT==1.7.1 -oss2==2.6.0 \ No newline at end of file +oss2==2.6.0 +fire \ No newline at end of file diff --git a/startup.py b/startup.py index 8695873..2bc880a 100644 --- a/startup.py +++ b/startup.py @@ -7,7 +7,9 @@ ''' import tornado.web import tornado.wsgi +from tornado.options import define import os +import fire from apps.ws.handler import ws_urls from ops.settings import DEBUG from libs.tornado_libs.application import Application as myapplication @@ -19,19 +21,29 @@ def __init__(self,**settings): wsgi_app = get_wsgi_application() container = tornado.wsgi.WSGIContainer(wsgi_app) urls = [] - urls.extend(ws_urls) + #urls.extend(ws_urls) urls.extend([ ("/static/(.*)", tornado.web.StaticFileHandler,dict(path=os.path.join(os.path.dirname(__file__), "static"))), ('.*', tornado.web.FallbackHandler, dict(fallback=container)) ]) super(Application,self).__init__(urls,**settings) -def main(): - settings = { - 'debug' : DEBUG - } - app = Application(**settings) - app.start_server() +class WsApplication(myapplication): + def __init__(self,**settings): + urls = [] + urls.extend(ws_urls) + super(WsApplication,self).__init__(urls,**settings) + +define("service", default='api', help="start service flag", type=str) +settings = {'debug' : DEBUG} + +class My(): + def __init__(self,service): + if service == 'cmdb': + self.app = Application(**settings) + elif service == 'ws': + self.app = WsApplication(**settings) + self.app.start_server() if __name__ == '__main__': - main() \ No newline at end of file + fire.Fire(My) \ No newline at end of file