Skip to content

Commit dd27b13

Browse files
yangmvyangmv
authored andcommitted
ws进程单独分开
1 parent 51af821 commit dd27b13

File tree

8 files changed

+50
-15
lines changed

8 files changed

+50
-15
lines changed
10 Bytes
Binary file not shown.

apps/assets/views/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def get(self, request ,format=None):
263263
# username = request.query_params.get('username')
264264
# 改用后端验证登录用户信息
265265
auth_key = request.COOKIES.get('auth_key', None)
266+
# print(auth_key)
266267
if not auth_key:return Response('未登陆',status=401)
267268
user_info = jwt.decode(auth_key, verify=False)
268269
username = user_info['data']['username'] if 'data' in user_info else 'guest'
0 Bytes
Binary file not shown.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmdb:
44
volumes:
55
- /var/log/supervisor/:/var/log/supervisor/
66
- /var/www/SuperCMDB/:/var/www/CMDB/
7-
# - /root/.ssh/:/root/.ssh/
7+
- /root/.ssh/:/root/.ssh/
88
- /sys/fs/cgroup:/sys/fs/cgroup
99
ports:
1010
- "8002:80"

docs/nginx_cmdb.conf

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ upstream cmdb{
44
server 127.0.0.1:9002;
55
}
66

7+
upstream ws{
8+
server 127.0.0.1:9901;
9+
}
10+
11+
712
server
813
{
914
listen 80;
@@ -23,15 +28,19 @@ server
2328

2429
location /v1/cmdb/ws/ {
2530
# proxy_set_header Host $http_host;
26-
proxy_redirect off;
31+
# proxy_redirect off;
2732
proxy_set_header X-Real-IP $remote_addr;
2833
proxy_set_header X-Scheme $scheme;
29-
proxy_pass http://cmdb;
34+
proxy_pass http://ws;
3035
proxy_http_version 1.1;
3136
proxy_set_header Upgrade websocket;
3237
proxy_set_header Connection Upgrade;
33-
#proxy_set_header Upgrade $http_upgrade;
34-
#proxy_set_header Connection "upgrade";
38+
# proxy_set_header Upgrade $http_upgrade;
39+
# proxy_set_header Connection "upgrade";
40+
proxy_connect_timeout 600s;
41+
proxy_read_timeout 36000s;
42+
proxy_send_timeout 600s;
43+
3544
}
3645

3746
location /v1/cmdb/ {

docs/supervisor_cmdb.conf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
nodaemon=true
33

44
[program:cmdb]
5-
command=python3 startup.py --port=90%(process_num)02d
5+
command=python3 startup.py --service=cmdb --port=90%(process_num)02d
66
process_name=%(program_name)s_%(process_num)02d
77
numprocs=3
88
directory=/var/www/CMDB
@@ -15,6 +15,18 @@ loglevel=info
1515
logfile_maxbytes=100MB
1616
logfile_backups=3
1717

18+
[program:ws]
19+
command=python3 startup.py --service=ws --port=9901
20+
directory=/var/www/CMDB
21+
user=root
22+
autostart=true
23+
autorestart=true
24+
redirect_stderr=true
25+
stdout_logfile=/var/log/supervisor/cmdb_ws.log
26+
loglevel=info
27+
logfile_maxbytes=100MB
28+
logfile_backups=3
29+
1830
[program:nginx]
1931
command=/usr/sbin/nginx -g "daemon off;"
2032
autostart=true

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ pyte==0.8.0
1010
paramiko==2.4.2
1111
shortuuid==0.5.0
1212
PyJWT==1.7.1
13-
oss2==2.6.0
13+
oss2==2.6.0
14+
fire

startup.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
'''
88
import tornado.web
99
import tornado.wsgi
10+
from tornado.options import define
1011
import os
12+
import fire
1113
from apps.ws.handler import ws_urls
1214
from ops.settings import DEBUG
1315
from libs.tornado_libs.application import Application as myapplication
@@ -19,19 +21,29 @@ def __init__(self,**settings):
1921
wsgi_app = get_wsgi_application()
2022
container = tornado.wsgi.WSGIContainer(wsgi_app)
2123
urls = []
22-
urls.extend(ws_urls)
24+
#urls.extend(ws_urls)
2325
urls.extend([
2426
("/static/(.*)", tornado.web.StaticFileHandler,dict(path=os.path.join(os.path.dirname(__file__), "static"))),
2527
('.*', tornado.web.FallbackHandler, dict(fallback=container))
2628
])
2729
super(Application,self).__init__(urls,**settings)
2830

29-
def main():
30-
settings = {
31-
'debug' : DEBUG
32-
}
33-
app = Application(**settings)
34-
app.start_server()
31+
class WsApplication(myapplication):
32+
def __init__(self,**settings):
33+
urls = []
34+
urls.extend(ws_urls)
35+
super(WsApplication,self).__init__(urls,**settings)
36+
37+
define("service", default='api', help="start service flag", type=str)
38+
settings = {'debug' : DEBUG}
39+
40+
class My():
41+
def __init__(self,service):
42+
if service == 'cmdb':
43+
self.app = Application(**settings)
44+
elif service == 'ws':
45+
self.app = WsApplication(**settings)
46+
self.app.start_server()
3547

3648
if __name__ == '__main__':
37-
main()
49+
fire.Fire(My)

0 commit comments

Comments
 (0)