Some changes to the workers

- some fixes with the previous iteration of the background workers
- PID now checked using ps -p instead of looking for it in /proc
pull/577/head
Iglocska 2015-07-17 15:06:38 +02:00
parent 93f9a01c87
commit b089cf077f
3 changed files with 16 additions and 12 deletions

View File

@ -421,8 +421,8 @@ class ServersController extends AppController {
if (!$this->_isSiteAdmin() || !$this->request->is('Post')) throw new MethodNotAllowedException();
$validTypes = array('default', 'email', 'scheduler', 'cache');
if (!in_array($type, $validTypes)) throw new MethodNotAllowedException('Invalid worker type.');
if ($type != 'scheduler') shell_exec(APP . 'Console' . DS . 'cake ' . DS . 'CakeResque.CakeResque start --interval 5 --queue ' . $type .' > /dev/null &');
else shell_exec(APP . 'Console' . DS . 'cake ' . DS . 'CakeResque.CakeResque startscheduler -i 5 > /dev/null &');
if ($type != 'scheduler') shell_exec(APP . 'Console' . DS . 'cake ' . DS . 'CakeResque.CakeResque start --interval 5 --queue ' . $type .' > /dev/null 2>&1 &');
else shell_exec(APP . 'Console' . DS . 'cake ' . DS . 'CakeResque.CakeResque startscheduler -i 5 > /dev/null 2>&1 &');
$this->redirect('/servers/serverSettings/workers');
}
@ -560,7 +560,7 @@ class ServersController extends AppController {
public function restartWorkers() {
if (!$this->_isSiteAdmin() || !$this->request->is('post')) throw new MethodNotAllowedException();
$this->Server->workerRemoveDead($this->Auth->user());
shell_exec(APP . 'Console' . DS . 'worker' . DS . 'start.sh > /dev/null &');
shell_exec(APP . 'Console' . DS . 'worker' . DS . 'start.sh > /dev/null 2>&1 &');
$this->redirect(array('controller' => 'servers', 'action' => 'serverSettings', 'workers'));
}

View File

@ -1534,9 +1534,10 @@ class Server extends AppModel {
'scheduler' => array('ok' => true)
);
foreach ($workers as $pid => $worker) {
$alive = file_exists("/proc/$pid");
$entry = ($worker['type'] == 'regular') ? $worker['queue'] : $worker['type'];
$correct_user = ($currentUser === $worker['user']);
if (!is_numeric($pid)) throw new MethodNotAllowedException('Non numeric PID found.');
$alive = $correct_user ? (substr_count(trim(shell_exec('ps -p ' . $pid)), PHP_EOL) > 0) : false;
$ok = true;
if (!$alive || !$correct_user) {
$ok = false;
@ -1569,13 +1570,14 @@ class Server extends AppModel {
}
public function killWorker($pid, $user) {
if (!is_numeric($pid)) throw new MethodNotAllowedException('Non numeric PID found!');
$this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
$workers = $this->ResqueStatus->getWorkers();
$this->Log = ClassRegistry::init('Log');
if (isset($workers[$pid])) {
$worker = $workers[$pid];
if (file_exists("/proc/$pid")) {
shell_exec('kill ' . $pid . ' > /dev/null &');
if (substr_count(trim(shell_exec('ps -p ' . $pid)), PHP_EOL) > 0 ? true : false) {
shell_exec('kill ' . $pid . ' > /dev/null 2>&1 &');
$this->Log->create();
$this->Log->save(array(
'org' => $user['org'],
@ -1609,9 +1611,11 @@ class Server extends AppModel {
$this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
$workers = $this->ResqueStatus->getWorkers();
$this->Log = ClassRegistry::init('Log');
$currentUser = get_current_user();
foreach ($workers as $pid => $worker) {
$test = $pid;
if (!file_exists("/proc/$pid")) {
if (!is_numeric($pid)) throw new MethodNotAllowedException('Non numeric PID found!');
$pidTest = substr_count(trim(shell_exec('ps -p ' . $pid)), PHP_EOL) > 0 ? true : false;
if ($worker['user'] == $currentUser && !$pidTest) {
$this->ResqueStatus->removeWorker($pid);
$this->Log->create();
$this->Log->save(array(

View File

@ -47,16 +47,16 @@
$message = 'The worker appears to be healthy.';
$icon_modifier = '';
if (!$worker['correct_user']) {
$message = 'The worker was started with a user other than the apache user.';
$message = 'The worker was started with a user other than the apache user. MISP cannot check whether the worker is alive or not.';
$style = "color:white;background-color:red;";
$icon_modifier = ' icon-white';
}
if (!$worker['alive']) {
$process = 'Unknown';
} else if (!$worker['alive']) {
$process = 'Dead';
$message = 'The Worker appears to be dead.';
$style = "color:white;background-color:red;";
$icon_modifier = ' icon-white';
}
}
$status = '<span style="color:green;">OK</span>';
?>