mirror of https://github.com/MISP/MISP
new: [zmq] Allow to manager ZMQ process by supervisor
parent
7f200f6f17
commit
77d2aa5dc9
|
@ -109,6 +109,9 @@ class AdminShell extends AppShell
|
|||
$parser->addSubcommand('configLint', [
|
||||
'help' => __('Check if settings has correct value.'),
|
||||
]);
|
||||
$parser->addSubcommand('createZmqConfig', [
|
||||
'help' => __('Create config file for ZeroMQ server.'),
|
||||
]);
|
||||
$parser->addSubcommand('scanAttachment', [
|
||||
'help' => __('Scan attachments with AV.'),
|
||||
'parser' => [
|
||||
|
@ -1251,4 +1254,10 @@ class AdminShell extends AppShell
|
|||
$this->Job->saveField('message', __('Database truncated: ' . $table));
|
||||
}
|
||||
}
|
||||
|
||||
public function createZmqConfig()
|
||||
{
|
||||
$this->Server->getPubSubTool()->createConfigFile();
|
||||
$this->err("Config file created in " . PubSubTool::SCRIPTS_TMP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,8 +178,12 @@ class PubSubTool
|
|||
|
||||
public function killService()
|
||||
{
|
||||
if ($this->checkIfRunning()) {
|
||||
$settings = $this->getSetSettings();
|
||||
if ($settings['supervisor_managed']) {
|
||||
throw new RuntimeException('ZeroMQ server is managed by supervisor, it is not possible to restart it.');
|
||||
}
|
||||
|
||||
if ($this->checkIfRunning()) {
|
||||
$redis = $this->createRedisConnection($settings);
|
||||
$redis->rPush('command', 'kill');
|
||||
sleep(1);
|
||||
|
@ -213,12 +217,16 @@ class PubSubTool
|
|||
|
||||
public function restartServer()
|
||||
{
|
||||
$settings = $this->getSetSettings();
|
||||
if ($settings['supervisor_managed']) {
|
||||
throw new RuntimeException('ZeroMQ server is managed by supervisor, it is not possible to restart it.');
|
||||
}
|
||||
|
||||
if (!$this->checkIfRunning()) {
|
||||
if (!$this->killService()) {
|
||||
return 'Could not kill the previous instance of the ZeroMQ script.';
|
||||
}
|
||||
}
|
||||
$settings = $this->getSetSettings();
|
||||
$this->setupPubServer($settings);
|
||||
if ($this->checkIfRunning() === false) {
|
||||
return 'Failed starting the ZeroMQ script.';
|
||||
|
@ -226,12 +234,22 @@ class PubSubTool
|
|||
return true;
|
||||
}
|
||||
|
||||
public function createConfigFile()
|
||||
{
|
||||
$settings = $this->getSetSettings();
|
||||
$this->saveSettingToFile($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $settings
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setupPubServer(array $settings)
|
||||
{
|
||||
if ($settings['supervisor_managed']) {
|
||||
return; // server is managed by supervisor, we don't need to check if is running or start it when not
|
||||
}
|
||||
|
||||
if ($this->checkIfRunning() === false) {
|
||||
if ($this->checkIfRunning(self::OLD_PID_LOCATION)) {
|
||||
// Old version is running, kill it and start again new one.
|
||||
|
@ -250,6 +268,7 @@ class PubSubTool
|
|||
* @param string|array $data
|
||||
* @return bool
|
||||
* @throws JsonException
|
||||
* @throws RedisException
|
||||
*/
|
||||
private function pushToRedis($ns, $data)
|
||||
{
|
||||
|
@ -295,9 +314,12 @@ class PubSubTool
|
|||
FileAccessTool::writeToFile($settingFilePath, JsonTool::encode($settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getSetSettings()
|
||||
{
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'redis_host' => 'localhost',
|
||||
'redis_port' => 6379,
|
||||
'redis_password' => '',
|
||||
|
@ -307,7 +329,8 @@ class PubSubTool
|
|||
'port' => '50000',
|
||||
'username' => null,
|
||||
'password' => null,
|
||||
);
|
||||
'supervisor_managed' => false,
|
||||
];
|
||||
|
||||
$pluginConfig = Configure::read('Plugin');
|
||||
foreach ($settings as $key => $setting) {
|
||||
|
|
Loading…
Reference in New Issue