Laravel Workers – AWS Beanstalkd 实例终止

huangapple go评论51阅读模式
英文:

Laravel Workers - AWS Beanstalkd Instance Termination

问题

我目前在AWS Beanstalk上运行我的Laravel应用程序,并配置了负载均衡器。这个设置允许最少1个和最多2个实例同时运行。到目前为止,一切都按预期运行,负载均衡器在第一个实例的负载过高时会添加第二个实例。

然而,当第二个实例被终止时,我的担忧就出现了。在我的.platform配置中,监管程序已经设置好,因此第二个实例也开始运行工作进程。当这些工作进程在其实例被终止时仍在处理任务时会发生什么情况?将工作进程分离到另一个实例中是否更可行?

不幸的是,我尚未能测试或复制这种情况。然而,我假设系统应该等待监管程序完成其进程,然后再终止实例。

英文:

I am currently running my Laravel application on AWS Beanstalk with a load balancer configured. The setup allows for a minimum of 1 and a maximum of 2 instances to be running. So far, everything functions as expected, with the load balancer adding a second instance when the load on the first one becomes too high.

However, my concern arises when the second instance gets terminated. In my .platform configuration, the supervisor is set up and consequently, the second instance also starts running the workers. What will happen to these workers that are still processing jobs when their instance gets terminated? Would it be more feasible to separate the workers into another instance?

Unfortunately, I have not been able to test or replicate this situation. However, my assumption is that the system should wait for the supervisor to complete its processes before terminating the instance.

答案1

得分: 0

我已经为手头的问题实现了一个解决方案。然而,我并不完全确定这是否是最佳方法。

最初,我为HTTP_SERVER创建了两个环境属性。然而,其中一个将用于HTTP_SERVER,另一个用于工作环境。然后,从环境设置中,我设置了两个"环境属性"。这些属性将决定当前部署是在生产环境还是测试环境,并且是一个HTTP服务器还是一个工作进程。

依据这些设置,我创建了bash脚本来控制操作。

以下是我为预构建准备的脚本中的一部分:

SERVER_VER=$(/opt/elasticbeanstalk/bin/get-config environment -k SERVER_VER); # RELEASE, LIVE
SERVER_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SERVER_TYPE); # WORKER, HTTP

if [[ $SERVER_TYPE == "WORKER" ]]; then
    # 安装 supervisor
    APP=$(yum info supervisor 2>/dev/null | grep Repo | awk '{ print $3 }')

    # 检查 supervisor 是否已安装
    if [[ $APP == "installed" ]]; then
        sudo supervisorctl stop all # 停止所有 supervisor 进程
    else
        sudo amazon-linux-extras enable epel
        sudo yum install -y epel-release
        sudo yum -y update
        sudo yum -y install supervisor
        sudo systemctl start supervisord
        sudo systemctl enable supervisord
    fi

    # Supervisor 配置
    sudo cp .platform/files/supervisor.ini /etc/supervisord.d/laravel.ini
    sudo supervisorctl reread
    sudo supervisorctl update

    # 重启 supervisor
    sudo supervisorctl stop all # 停止所有 supervisor 进程
fi

你可以使用 /opt/elasticbeanstalk/bin/get-config environment 命令检索你定义的环境属性。如果你想获取特定的属性,可以使用 /opt/elasticbeanstalk/bin/get-config environment -k SERVER_VER 命令。

英文:

I have implemented a solution for the problem at hand. However, I'm not completely certain if this is the best approach.

Initially, I created two environment properties for HTTP_SERVER. However, one of these will be used for HTTP_SERVER and the other for the Worker Environment. Then, from the environment settings, I set up two "Environment Properties". These properties will determine whether the current deployment is live or in a test environment, and whether it's an HTTP server or a worker.

Laravel Workers – AWS Beanstalkd 实例终止

Depending on these settings, I've created bash scripts to control the operations.

Here's a snippet from the script I prepared for prebuild:

SERVER_VER=$(/opt/elasticbeanstalk/bin/get-config environment -k SERVER_VER); # RELEASE, LIVE
SERVER_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SERVER_TYPE); # WORKER, HTTP

if [[ $SERVER_TYPE == "WORKER" ]]; then
    # Install supervisor
    APP=$(yum info supervisor 2>/dev/null | grep Repo | awk '{ print $3 }')

    # Check if supervisor is installed
    if [[ $APP == "installed" ]]; then
            sudo supervisorctl stop all # Stop all supervisor processes
    else
            sudo amazon-linux-extras enable epel
            sudo yum install -y epel-release
            sudo yum -y update
            sudo yum -y install supervisor
            sudo systemctl start supervisord
            sudo systemctl enable supervisord
    fi

    # Supervisor config
    sudo cp .platform/files/supervisor.ini /etc/supervisord.d/laravel.ini
    sudo supervisorctl reread
    sudo supervisorctl update

    # Restart supervisor
    sudo supervisorctl stop all # Stop all supervisor processes
fi

You can retrieve the Environment Properties you have defined with the /opt/elasticbeanstalk/bin/get-config environment command. If you want to get a specific one, you can use the /opt/elasticbeanstalk/bin/get-config environment -k SERVER_VER command.

huangapple
  • 本文由 发表于 2023年7月24日 17:44:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753223.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定