dongpao1873 2016-10-23 00:20
浏览 142
已采纳

如何在不停机的情况下自动部署在后台运行的PHP脚本的新版本?

I have a AMQP consumer (a RabbitMQ consumer) written in PHP always active running in the background. This script is run in multiple nodes and 12 times per node: 12 unix background processes running:

php -f consumer.php &.

If a new version of the code must be deployed, at the moment I always have to kill ALL these processes manually and launch them again one by one, in each node.

  1. Is there a way to automate the deployment of background scripts? I.e. put it in a deployment pipeline and then having them reloaded, similarly to using https://deployer.org.
  2. Is there a way to avoid downtime?
  3. Any way ReactPHP would help in this case?
  • 写回答

1条回答 默认 最新

  • duancong7573 2016-10-23 00:44
    关注

    Found the answer in the Laravel docs (the solution works for any always running background process, not just PHP and Laravel). Supervisor!

    Configuring Supervisor

    Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a laravel-worker.conf file that starts and monitors a queue:work process:

    Starting Supervisor

    Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

    sudo supervisorctl reread

    sudo supervisorctl update

    sudo supervisorctl start laravel-worker:*

    It will even help me starting as many processes I want with a single configuration file and single command. Again, from the Laravel docs:

    [program:laravel-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3
    autostart=true
    autorestart=true
    user=forge
    numprocs=8
    redirect_stderr=true
    stdout_logfile=/home/forge/app.com/worker.log
    

    By calling sudo supervisorctl start laravel-worker:*, 8 background processes will run, which also restart in case of error.

    If I just want to restart with a new released version, I call the restart command directly:

    supervisorctl restart laravel-worker:*

    I'll just integrate this as a Deployer task in my CI/CD pipeline.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 网页游戏在本地页面修改游戏结果
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数