processes: add a way to control processes via gunicorn control.
- allows web based adding/removing workers
This commit is contained in:
parent
c36b8f3d79
commit
e12af2ef40
5 changed files with 66 additions and 1 deletions
|
|
@ -75,6 +75,9 @@ def admin_routes(config):
|
|||
config.add_route(
|
||||
name='admin_settings_process_management_signal',
|
||||
pattern='/settings/process_management/signal')
|
||||
config.add_route(
|
||||
name='admin_settings_process_management_master_signal',
|
||||
pattern='/settings/process_management/master_signal')
|
||||
|
||||
# default settings
|
||||
config.add_route(
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
import logging
|
||||
|
||||
import psutil
|
||||
import signal
|
||||
from pyramid.view import view_config
|
||||
|
||||
from rhodecode.apps._base import BaseAppView
|
||||
|
|
@ -101,3 +102,32 @@ class AdminProcessManagementView(BaseAppView):
|
|||
p.kill()
|
||||
|
||||
return {'result': result}
|
||||
|
||||
@LoginRequired()
|
||||
@HasPermissionAllDecorator('hg.admin')
|
||||
@CSRFRequired()
|
||||
@view_config(
|
||||
route_name='admin_settings_process_management_master_signal',
|
||||
request_method='POST', renderer='json_ext')
|
||||
def process_management_master_signal(self):
|
||||
pid_data = self.request.json.get('pid_data', {})
|
||||
pid = safe_int(pid_data['pid'])
|
||||
action = pid_data['action']
|
||||
if pid:
|
||||
try:
|
||||
proc = psutil.Process(pid)
|
||||
except psutil.NoSuchProcess:
|
||||
return {'result': 'failure_no_such_process'}
|
||||
|
||||
children = proc.children(recursive=True)
|
||||
if children:
|
||||
# master process
|
||||
if action == '+' and len(children) <= 20:
|
||||
proc.send_signal(signal.SIGTTIN)
|
||||
elif action == '-' and len(children) >= 2:
|
||||
proc.send_signal(signal.SIGTTOU)
|
||||
else:
|
||||
return {'result': 'failure_wrong_action'}
|
||||
return {'result': 'success'}
|
||||
|
||||
return {'result': 'failure_not_master'}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ function registerRCRoutes() {
|
|||
pyroutes.register('admin_settings_process_management', '/_admin/settings/process_management', []);
|
||||
pyroutes.register('admin_settings_process_management_data', '/_admin/settings/process_management/data', []);
|
||||
pyroutes.register('admin_settings_process_management_signal', '/_admin/settings/process_management/signal', []);
|
||||
pyroutes.register('admin_settings_process_management_master_signal', '/_admin/settings/process_management/master_signal', []);
|
||||
pyroutes.register('admin_defaults_repositories', '/_admin/defaults/repositories', []);
|
||||
pyroutes.register('admin_defaults_repositories_update', '/_admin/defaults/repositories/update', []);
|
||||
pyroutes.register('admin_settings', '/_admin/settings', []);
|
||||
|
|
|
|||
|
|
@ -105,5 +105,34 @@ disableAutoRefresh = function() {
|
|||
autoRefresh(false)
|
||||
};
|
||||
|
||||
masterAction = function(pid, action) {
|
||||
$.ajax({
|
||||
url: pyroutes.url('admin_settings_process_management_master_signal'),
|
||||
headers: {
|
||||
"X-CSRF-Token": CSRF_TOKEN,
|
||||
},
|
||||
data: JSON.stringify({'pid_data': {'pid': pid, 'action': action}}),
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
contentType: "application/json; charset=utf-8",
|
||||
success: function (data) {
|
||||
|
||||
},
|
||||
failure: function (data) {
|
||||
|
||||
},
|
||||
error: function (data) {
|
||||
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
addWorker = function(pid) {
|
||||
masterAction(pid, '+');
|
||||
};
|
||||
|
||||
removeWorker = function(pid) {
|
||||
masterAction(pid, '-');
|
||||
};
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@
|
|||
</td>
|
||||
<td>
|
||||
MASTER
|
||||
% if request.GET.get('dev'):
|
||||
| <a href="#addWorker" onclick="addWorker(${proc.pid}); return false">ADD</a> | <a href="#removeWorker" onclick="removeWorker(${proc.pid}); return false">REMOVE</a>
|
||||
% endif
|
||||
</td>
|
||||
</tr>
|
||||
<% mem_sum = 0 %>
|
||||
|
|
@ -87,7 +90,6 @@
|
|||
<td></td>
|
||||
</tr>
|
||||
<tr><td> <code> -- </code> </td></tr>
|
||||
|
||||
% endif
|
||||
% endfor
|
||||
</table>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue