diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d5f211b..cf519e6 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); @@ -51,14 +52,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() @@ -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..9d3cf49 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); @@ -59,6 +65,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/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..a9d0704 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%" @@ -16,7 +17,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..ec29195 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 */ @@ -52,7 +57,7 @@ class RabbitMqSupervisor /** * @var string */ - private $rootDir; + private $projectDir; /** * @var string @@ -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 @@ -76,13 +82,14 @@ 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 $inet_http_server, array $commands, $consumers, $multipleConsumers, $batchConsumers, $rpcServers, $config, $sockFilePermissions, $projectDir, $environment) { $this->supervisor = $supervisor; $this->paths = $paths; + $this->inet_http_server = $inet_http_server; $this->commands = $commands; $this->consumers = $consumers; $this->multipleConsumers = $multipleConsumers; @@ -90,7 +97,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; } @@ -289,8 +296,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 @@ -316,7 +322,16 @@ public function generateSupervisorConfiguration() array_keys($this->rpcServers) )) ) - )); + ); + + $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 @@ -328,7 +343,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 +351,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];