From 7c219f360070ecc9b7e4fc082ff2e61f9067277c Mon Sep 17 00:00:00 2001 From: Jachim Coudenys Date: Mon, 4 Mar 2019 13:30:46 +0100 Subject: [PATCH 1/2] Add a config option to configure an optional inet_http_server --- DependencyInjection/Configuration.php | 23 ++++++++++++++++++ .../RabbitMqSupervisorExtension.php | 1 + Resources/config/services.yml | 1 + Services/RabbitMqSupervisor.php | 24 +++++++++++++++---- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d5f211b..9aaa1d0 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -32,6 +32,7 @@ public function getConfigTreeBuilder() ->scalarNode('sock_file_permissions')->defaultValue('0700')->end() ->end(); $this->addPaths($rootNode); + $this->addInetHttpServer($rootNode); $this->addCommands($rootNode); $this->addConsumer($rootNode); @@ -66,6 +67,28 @@ protected function addPaths(ArrayNodeDefinition $node) ; } + /** + * Add inet_http_server configuration + * + * @param ArrayNodeDefinition $node + */ + protected function addInetHttpServer(ArrayNodeDefinition $node) + { + $node + ->children() + ->arrayNode('inet_http_server') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('enabled')->defaultFalse()->end() + ->scalarNode('port')->defaultNull()->end() + ->scalarNode('username')->defaultNull()->end() + ->scalarNode('password')->defaultNull()->end() + ->end() + ->end() + ->end() + ; + } + /** * Add commands configuration * diff --git a/DependencyInjection/RabbitMqSupervisorExtension.php b/DependencyInjection/RabbitMqSupervisorExtension.php index 88b5fb2..0529e2c 100644 --- a/DependencyInjection/RabbitMqSupervisorExtension.php +++ b/DependencyInjection/RabbitMqSupervisorExtension.php @@ -59,6 +59,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('phobetor_rabbitmq_supervisor.supervisor_instance_identifier', $config['supervisor_instance_identifier']); $container->setParameter('phobetor_rabbitmq_supervisor.sock_file_permissions', $config['sock_file_permissions']); $container->setParameter('phobetor_rabbitmq_supervisor.paths', $config['paths']); + $container->setParameter('phobetor_rabbitmq_supervisor.inet_http_server', $config['inet_http_server']); $container->setParameter('phobetor_rabbitmq_supervisor.workspace', $config['paths']['workspace_directory']); $container->setParameter('phobetor_rabbitmq_supervisor.configuration_file', $config['paths']['configuration_file']); $container->setParameter('phobetor_rabbitmq_supervisor.commands', $config['commands']); diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 1374d6b..fbc077a 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -9,6 +9,7 @@ services: arguments: - "@phobetor_rabbitmq_supervisor.supervisor_service" - "%phobetor_rabbitmq_supervisor.paths%" + - "%phobetor_rabbitmq_supervisor.inet_http_server%" - "%phobetor_rabbitmq_supervisor.commands%" - "%phobetor_rabbitmq_supervisor.consumers%" - "%phobetor_rabbitmq_supervisor.multiple_consumers%" diff --git a/Services/RabbitMqSupervisor.php b/Services/RabbitMqSupervisor.php index b3b32e2..328ee30 100644 --- a/Services/RabbitMqSupervisor.php +++ b/Services/RabbitMqSupervisor.php @@ -19,6 +19,11 @@ class RabbitMqSupervisor */ private $paths; + /** + * @var array + */ + private $inet_http_server; + /** * @var array */ @@ -69,6 +74,7 @@ class RabbitMqSupervisor * * @param \Phobetor\RabbitMqSupervisorBundle\Services\Supervisor $supervisor * @param array $paths + * @param array $inet_http_server * @param array $commands * @param array $consumers * @param array $multipleConsumers @@ -79,10 +85,12 @@ class RabbitMqSupervisor * @param string $kernelRootDir * @param string $environment */ - public function __construct(Supervisor $supervisor, array $paths, array $commands, $consumers, $multipleConsumers, $batchConsumers, $rpcServers, $config, $sockFilePermissions, $kernelRootDir, $environment) + + public function __construct(Supervisor $supervisor, array $paths, array $inet_http_server, array $commands, $consumers, $multipleConsumers, $batchConsumers, $rpcServers, $config, $sockFilePermissions, $kernelRootDir, $environment) { $this->supervisor = $supervisor; $this->paths = $paths; + $this->inet_http_server = $inet_http_server; $this->commands = $commands; $this->consumers = $consumers; $this->multipleConsumers = $multipleConsumers; @@ -289,8 +297,7 @@ private function createPathDirectories() public function generateSupervisorConfiguration() { - $configurationHelper = new ConfigurationHelper(); - $content = $configurationHelper->getConfigurationStringFromDataArray(array( + $configuration = array( 'unix_http_server' => array( 'file' => $this->paths['sock_file'], 'chmod' => $this->sockFilePermissions @@ -308,7 +315,16 @@ public function generateSupervisorConfiguration() 'include' => array( 'files' => sprintf('%s*.conf', $this->paths['worker_configuration_directory']) ) - )); + ); + + $inetHttpServer = $this->inet_http_server; + if ($inetHttpServer['enabled']) { + unset($inetHttpServer['enabled']); + $configuration['inet_http_server'] = $inetHttpServer; + } + + $configurationHelper = new ConfigurationHelper(); + $content = $configurationHelper->getConfigurationStringFromDataArray($configuration); file_put_contents( $this->createSupervisorConfigurationFilePath(), $content From 26662dd5cc6167b1daf44519f5b59e3c6ddd4d64 Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Thu, 14 Apr 2022 11:55:05 +0200 Subject: [PATCH 2/2] fix: use project_dir if available (Symfony 3+) --- DependencyInjection/Configuration.php | 16 ++++++++-------- .../RabbitMqSupervisorExtension.php | 6 ++++++ README.md | 4 +--- Resources/config/services.yml | 2 +- Services/RabbitMqSupervisor.php | 12 ++++++------ 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d5f211b..ea83cad 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -51,14 +51,14 @@ protected function addPaths(ArrayNodeDefinition $node) ->arrayNode('paths') ->addDefaultsIfNotSet() ->children() - ->scalarNode('workspace_directory')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/')->end() - ->scalarNode('configuration_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisord.conf')->end() - ->scalarNode('pid_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisor.pid')->end() - ->scalarNode('sock_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisor.sock')->end() - ->scalarNode('log_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisord.log')->end() - ->scalarNode('worker_configuration_directory')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/worker/')->end() - ->scalarNode('worker_output_log_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stdout.log')->end() - ->scalarNode('worker_error_log_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stderr.log')->end() + ->scalarNode('workspace_directory')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/')->end() + ->scalarNode('configuration_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisord.conf')->end() + ->scalarNode('pid_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisor.pid')->end() + ->scalarNode('sock_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisor.sock')->end() + ->scalarNode('log_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisord.log')->end() + ->scalarNode('worker_configuration_directory')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/worker/')->end() + ->scalarNode('worker_output_log_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/logs/stdout.log')->end() + ->scalarNode('worker_error_log_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/logs/stderr.log')->end() ->scalarNode('php_executable')->defaultValue('php')->end() ->end() ->end() diff --git a/DependencyInjection/RabbitMqSupervisorExtension.php b/DependencyInjection/RabbitMqSupervisorExtension.php index 88b5fb2..1d93243 100644 --- a/DependencyInjection/RabbitMqSupervisorExtension.php +++ b/DependencyInjection/RabbitMqSupervisorExtension.php @@ -19,6 +19,12 @@ class RabbitMqSupervisorExtension extends Extension implements PrependExtensionI */ public function load(array $configs, ContainerBuilder $container) { + if ($container->hasParameter('kernel.root_dir')) { + $container->setParameter('phobetor_rabbitmq_supervisor.project_dir', '%kernel.root_dir%/..'); + } else { + $container->setParameter('phobetor_rabbitmq_supervisor.project_dir', '%kernel.project_dir%'); + } + $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/README.md b/README.md index f6dab7f..32d96fa 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,8 @@ supervisor/ ├── queue3.conf └── queue4.conf ``` -In symfony 2 and 3 this will be placed inside your `app/` directory. -Caution with symfony 4: to not have this inside of your `src/` directory you need to set the paths to suit your needs. -E. g. to use the standard structure inside of the `var/` directory, use this: +If you want to use the standard structure inside of the `var/` directory, change the configuration like this: ```yml rabbit_mq_supervisor: paths: diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 1374d6b..e7ad7ce 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -16,7 +16,7 @@ services: - "%phobetor_rabbitmq_supervisor.rpc_servers%" - "%phobetor_rabbitmq_supervisor.config%" - "%phobetor_rabbitmq_supervisor.sock_file_permissions%" - - "%kernel.root_dir%" + - "%phobetor_rabbitmq_supervisor.project_dir%" - "%kernel.environment%" phobetor_rabbitmq_supervisor.supervisor_service: diff --git a/Services/RabbitMqSupervisor.php b/Services/RabbitMqSupervisor.php index 636a038..3a10ac4 100644 --- a/Services/RabbitMqSupervisor.php +++ b/Services/RabbitMqSupervisor.php @@ -52,7 +52,7 @@ class RabbitMqSupervisor /** * @var string */ - private $rootDir; + private $projectDir; /** * @var string @@ -76,10 +76,10 @@ class RabbitMqSupervisor * @param array $rpcServers * @param array $config * @param $sockFilePermissions - * @param string $kernelRootDir + * @param string $projectDir * @param string $environment */ - public function __construct(Supervisor $supervisor, array $paths, array $commands, $consumers, $multipleConsumers, $batchConsumers, $rpcServers, $config, $sockFilePermissions, $kernelRootDir, $environment) + public function __construct(Supervisor $supervisor, array $paths, array $commands, $consumers, $multipleConsumers, $batchConsumers, $rpcServers, $config, $sockFilePermissions, $projectDir, $environment) { $this->supervisor = $supervisor; $this->paths = $paths; @@ -90,7 +90,7 @@ public function __construct(Supervisor $supervisor, array $paths, array $command $this->rpcServers = $rpcServers; $this->config = $config; $this->sockFilePermissions = $sockFilePermissions; - $this->rootDir = dirname($kernelRootDir); + $this->projectDir = $projectDir; $this->environment = $environment; } @@ -328,7 +328,7 @@ private function generateWorkerConfigurations($names, $baseCommand) // try different possible console paths (realpath() will throw away the not existing ones) $consolePaths = []; foreach (['bin', 'app'] as $consoleDirectory) { - $consolePath = sprintf('%s/%s/console', $this->rootDir, $consoleDirectory); + $consolePath = sprintf('%s/%s/console', $this->projectDir, $consoleDirectory); if (!empty(realpath($consolePath))) { $consolePaths[] = $consolePath; } @@ -336,7 +336,7 @@ private function generateWorkerConfigurations($names, $baseCommand) // fall back to standard console path if none of the paths was valid if (empty($consolePaths)) { - $consolePaths[] = sprintf('%s/%s/console', $this->rootDir, 'bin'); + $consolePaths[] = sprintf('%s/%s/console', $this->projectDir, 'bin'); } $executablePath = $consolePaths[0];