Skip to content

Commit

Permalink
ws进程单独分开
Browse files Browse the repository at this point in the history
  • Loading branch information
yangmv authored and yangmv committed Feb 22, 2019
1 parent 51af821 commit dd27b13
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 15 deletions.
Binary file modified apps/assets/views/__pycache__/server.cpython-36.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions apps/assets/views/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Binary file modified apps/ws/__pycache__/handler.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 13 additions & 4 deletions docs/nginx_cmdb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ upstream cmdb{
server 127.0.0.1:9002;
}

upstream ws{
server 127.0.0.1:9901;
}


server
{
listen 80;
Expand All @@ -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/ {
Expand Down
14 changes: 13 additions & 1 deletion docs/supervisor_cmdb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pyte==0.8.0
paramiko==2.4.2
shortuuid==0.5.0
PyJWT==1.7.1
oss2==2.6.0
oss2==2.6.0
fire
28 changes: 20 additions & 8 deletions startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
fire.Fire(My)

0 comments on commit dd27b13

Please sign in to comment.