##// END OF EJS Templates
processes: add a way to control processes via gunicorn control....
marcink -
r2503:01410cf4 default
parent child Browse files
Show More
@@ -75,6 +75,9 b' def admin_routes(config):'
75 75 config.add_route(
76 76 name='admin_settings_process_management_signal',
77 77 pattern='/settings/process_management/signal')
78 config.add_route(
79 name='admin_settings_process_management_master_signal',
80 pattern='/settings/process_management/master_signal')
78 81
79 82 # default settings
80 83 config.add_route(
@@ -21,6 +21,7 b''
21 21 import logging
22 22
23 23 import psutil
24 import signal
24 25 from pyramid.view import view_config
25 26
26 27 from rhodecode.apps._base import BaseAppView
@@ -101,3 +102,32 b' class AdminProcessManagementView(BaseApp'
101 102 p.kill()
102 103
103 104 return {'result': result}
105
106 @LoginRequired()
107 @HasPermissionAllDecorator('hg.admin')
108 @CSRFRequired()
109 @view_config(
110 route_name='admin_settings_process_management_master_signal',
111 request_method='POST', renderer='json_ext')
112 def process_management_master_signal(self):
113 pid_data = self.request.json.get('pid_data', {})
114 pid = safe_int(pid_data['pid'])
115 action = pid_data['action']
116 if pid:
117 try:
118 proc = psutil.Process(pid)
119 except psutil.NoSuchProcess:
120 return {'result': 'failure_no_such_process'}
121
122 children = proc.children(recursive=True)
123 if children:
124 # master process
125 if action == '+' and len(children) <= 20:
126 proc.send_signal(signal.SIGTTIN)
127 elif action == '-' and len(children) >= 2:
128 proc.send_signal(signal.SIGTTOU)
129 else:
130 return {'result': 'failure_wrong_action'}
131 return {'result': 'success'}
132
133 return {'result': 'failure_not_master'}
@@ -50,6 +50,7 b' function registerRCRoutes() {'
50 50 pyroutes.register('admin_settings_process_management', '/_admin/settings/process_management', []);
51 51 pyroutes.register('admin_settings_process_management_data', '/_admin/settings/process_management/data', []);
52 52 pyroutes.register('admin_settings_process_management_signal', '/_admin/settings/process_management/signal', []);
53 pyroutes.register('admin_settings_process_management_master_signal', '/_admin/settings/process_management/master_signal', []);
53 54 pyroutes.register('admin_defaults_repositories', '/_admin/defaults/repositories', []);
54 55 pyroutes.register('admin_defaults_repositories_update', '/_admin/defaults/repositories/update', []);
55 56 pyroutes.register('admin_settings', '/_admin/settings', []);
@@ -105,5 +105,34 b' disableAutoRefresh = function() {'
105 105 autoRefresh(false)
106 106 };
107 107
108 masterAction = function(pid, action) {
109 $.ajax({
110 url: pyroutes.url('admin_settings_process_management_master_signal'),
111 headers: {
112 "X-CSRF-Token": CSRF_TOKEN,
113 },
114 data: JSON.stringify({'pid_data': {'pid': pid, 'action': action}}),
115 dataType: 'json',
116 type: 'POST',
117 contentType: "application/json; charset=utf-8",
118 success: function (data) {
119
120 },
121 failure: function (data) {
122
123 },
124 error: function (data) {
125
126 }
127 })
128 };
129
130 addWorker = function(pid) {
131 masterAction(pid, '+');
132 };
133
134 removeWorker = function(pid) {
135 masterAction(pid, '-');
136 };
108 137
109 138 </script>
@@ -43,6 +43,9 b''
43 43 </td>
44 44 <td>
45 45 MASTER
46 % if request.GET.get('dev'):
47 | <a href="#addWorker" onclick="addWorker(${proc.pid}); return false">ADD</a> | <a href="#removeWorker" onclick="removeWorker(${proc.pid}); return false">REMOVE</a>
48 % endif
46 49 </td>
47 50 </tr>
48 51 <% mem_sum = 0 %>
@@ -87,7 +90,6 b''
87 90 <td></td>
88 91 </tr>
89 92 <tr><td> <code> -- </code> </td></tr>
90
91 93 % endif
92 94 % endfor
93 95 </table>
General Comments 0
You need to be logged in to leave comments. Login now