diff --git a/rhodecode/apps/admin/__init__.py b/rhodecode/apps/admin/__init__.py --- a/rhodecode/apps/admin/__init__.py +++ b/rhodecode/apps/admin/__init__.py @@ -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( diff --git a/rhodecode/apps/admin/views/process_management.py b/rhodecode/apps/admin/views/process_management.py --- a/rhodecode/apps/admin/views/process_management.py +++ b/rhodecode/apps/admin/views/process_management.py @@ -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(BaseApp 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'} diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -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', []); diff --git a/rhodecode/templates/admin/settings/settings_process_management.mako b/rhodecode/templates/admin/settings/settings_process_management.mako --- a/rhodecode/templates/admin/settings/settings_process_management.mako +++ b/rhodecode/templates/admin/settings/settings_process_management.mako @@ -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, '-'); +}; diff --git a/rhodecode/templates/admin/settings/settings_process_management_data.mako b/rhodecode/templates/admin/settings/settings_process_management_data.mako --- a/rhodecode/templates/admin/settings/settings_process_management_data.mako +++ b/rhodecode/templates/admin/settings/settings_process_management_data.mako @@ -43,6 +43,9 @@
--