mybuilder/supervisor-bundle

Symfony 3/4/5的bundle,允许您使用@Supervisor注释来配置Supervisor如何运行您的控制台命令。

2.2.0 2022-09-29 12:48 UTC

This package is auto-updated.

Last update: 2024-08-29 05:12:29 UTC


README

Build Status

用于Symfony 4/5的bundle,允许您使用@Supervisor注释来配置Supervisor如何运行您的控制台命令。

安装

使用composer安装

运行composer require命令

$ php composer.phar require mybuilder/supervisor-bundle

启用bundle

在Symfony的config/bundles.php中启用此bundle

return [
    MyBuilder\Bundle\SupervisorBundle\MyBuilderSupervisorBundle::class => ['all' => true],
];

配置bundle

您可以将以下内容添加到packages/my_builder_supervisor.yaml中,为Symfony定义全局导出配置

my_builder_supervisor:
    exporter:
        # any Supervisor program options can be specified within this block
        program:
            autostart: 'true'
        
        # allows you to specify a program that all commands should be passed to
        executor: php 
        
        # allows you to specify the console that all commands should be passed to
        console: bin/console

使用方法

第一步是将注释的使用场景添加到您想要使用@Supervisor注释的命令的顶部。

use MyBuilder\Bundle\SupervisorBundle\Annotation\Supervisor;

然后在命令的PHPDoc中定义@Supervisor注释,告诉Supervisor如何配置此程序。以下示例声明在名为'web'的服务器上始终运行此命令的三个实例,并提供参数--send

/**
 * Command for sending our email messages from the database.
 *
 * @Supervisor(processes=3, params="--send", server="web")
 */
class SendQueuedEmailsCommand extends Command {}

导出Supervisor配置

您应该运行bin/console supervisor:dump并查看基于当前指定定义的Supervisor配置将如何显示。如果您对此满意,可以将配置写入到conf文件。

$ bin/console supervisor:dump --user=mybuilder --server=web > "/etc/supervisor.d/symfony.conf"

然后重新加载Supervisor

$ kill -SIGHUP $(supervisorctl pid)

环境

您可以选择在Supervisor下运行命令的环境,如下所示

$ bin/console supervisor:dump --server=web --env=prod

MyBuilder创建 - 查看我们的博客,了解更多关于这个和其他我们发布的开源项目的信息。