-
Notifications
You must be signed in to change notification settings - Fork 27
/
webui.py
76 lines (47 loc) · 2.18 KB
/
webui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# encoding:utf8
__author__ = 'brianyang'
import json
from flask import Flask, render_template, Response
from supervisor_manage import get_status, get_server_id_mapping, get_group_mapping, batch_group_opt, batch_server_opt
app = Flask(__name__)
server_id_mapping = get_server_id_mapping()
group_mapping = get_group_mapping()
def common_response(ret):
return Response(json.dumps({'ret': ret}), content_type='application/json')
@app.route('/')
def index():
return render_template('index.html', apps=get_status(group_mapping))
@app.route('/servers/')
def servers():
return render_template('servers.html', servers=server_id_mapping.values())
@app.route('/server/<server_id>/status/')
def server_status(server_id):
server = server_id_mapping.get(server_id)
uri = '%s@%s:%s' % (server.user, server.host, server.port)
return render_template('server_status.html', uri=uri, server_id=server_id, apps=server.get_all_process_info())
@app.route('/<server_id>/<group>/<app>/start/')
def start_app(server_id, group, app):
app_name = '%s:%s' % (group, app)
return common_response(server_id_mapping.get(server_id).start_process(app_name))
@app.route('/<server_id>/<group>/<app>/restart/')
def restart_app(server_id, group, app):
app_name = '%s:%s' % (group, app)
return common_response(server_id_mapping.get(server_id).restart_process(app_name))
@app.route('/<server_id>/<group>/<app>/stop/')
def stop_app(server_id, group, app):
app_name = '%s:%s' % (group, app)
return common_response(server_id_mapping.get(server_id).stop_process(app_name))
def format_log(log):
return '<div>%s</div>' % (log,)
@app.route('/<server>/<group>/<app>/tail/')
def tail_std_log(server, group, app):
app_name = '%s:%s' % (group, app)
return Response(server_id_mapping.get(server).tail_log(app_name, format_log))
@app.route('/group_batch/<group>/<opt>/')
def group_batch(group, opt):
return common_response(batch_group_opt(group_mapping.get(group, []), opt))
@app.route('/server_batch/<server_id>/<opt>/')
def server_batch(server_id, opt):
return common_response(batch_server_opt(server_id_mapping.get(server_id), opt))
if __name__ == '__main__':
app.run(debug=True)