如何在supervisor-linux中为被监督的进程添加一个延迟[英] How to add a delay to supervised process in supervisor - linux

本文是小编为大家收集整理的关于如何在supervisor-linux中为被监督的进程添加一个延迟的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我添加了一个使用Python的Cassandra库的瓶服务器,但是它在此错误中退出:
Bottle FATAL Exited too quickly (process log may have details)
日志显示了这一点:
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1765, in _reconnect_internal raise NoHostAvailable("Unable to connect to any servers", errors)

,所以我尝试了使用suspisorctl启动瓶手动运行它,然后没有任何问题.结论=瓶装服务的开始太快(在需要的Cassandra监督服务之前):需要延迟!

推荐答案

对sleep hack不太满意,我创建了一个启动脚本并从那里启动supervisorctl start processname.

[program:startup]
command=/startup.sh
startsecs = 0
autostart = true
autorestart = false
startretries = 1
priority=1

[program:myapp]
command=/home/website/venv/bin/gunicorn /home/website/myapp/app.py
autostart=false
autorestart=true
process_name=myapp

startup.sh

#!/bin/bash
sleep 5
supervisorctrl start myapp

以这种方式,主管将启动启动脚本一次,这将在5秒钟后开始MyApp,请注意autostart=false和autorestart=true myapp.

其他推荐答案

这就是我使用的:

[program:uwsgi]
command=bash -c 'sleep 5 && uwsgi /etc/uwsgi.ini'

其他推荐答案

我也有一个类似的问题,在每个重新启动时,使用SubstisorCtl开始64个Python RQ-Worker流程正在提高CPU和RAM警报.我所做的是以下内容:

command=/bin/bash -c "sleep %(process_num)02d && virtualenv/bin/python3 manage.py rqworker --name %(program_name)s_my-rq-worker_%(process_num)02d default low"

基本上,在运行python命令之前,我睡了n秒,其中n是过程编号,这基本上意味着我每秒都会启动一个RQ-worker进程.

本文地址:https://www.itbaoku.cn/post/2328058.html

问题描述

I added a bottle server that uses python's cassandra library, but it exits with this error:
Bottle FATAL Exited too quickly (process log may have details)
log shows this:
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1765, in _reconnect_internal raise NoHostAvailable("Unable to connect to any servers", errors)

So I tried to run it manually using supervisorctl start Bottle ,and then it started with no issue. The conclusion= Bottle service starts too fast (before the needed cassandra supervised service does): a delay is needed!

推荐答案

Not happy enough with the sleep hack I created a startup script and launched supervisorctl start processname from there.

[program:startup]
command=/startup.sh
startsecs = 0
autostart = true
autorestart = false
startretries = 1
priority=1

[program:myapp]
command=/home/website/venv/bin/gunicorn /home/website/myapp/app.py
autostart=false
autorestart=true
process_name=myapp

startup.sh

#!/bin/bash
sleep 5
supervisorctrl start myapp

This way supervisor will fire the startup script once and this will start myapp after 5 seconds, mind the autostart=false and autorestart=true on myapp.

其他推荐答案

This is what I use:

[program:uwsgi]
command=bash -c 'sleep 5 && uwsgi /etc/uwsgi.ini'

其他推荐答案

I had a similar issue where, starting 64 python rq-worker processes using supervisorctl was raising CPU and RAM alert at every restart. What I did was the following:

command=/bin/bash -c "sleep %(process_num)02d && virtualenv/bin/python3 manage.py rqworker --name %(program_name)s_my-rq-worker_%(process_num)02d default low"

Basically, before running the python command, I sleep for N second, where N is the process number, which basically means I supervisor will start one rq-worker process every second.