推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
OnlyO
V2EX  ›  Python

supervisor 和 mysql 开机启动问题

  •  
  •   OnlyO · Apr 22, 2020 · 5169 views
    This topic created in 2388 days ago, the information mentioned may be changed or developed.
    我用 supervisor 控制 celery 和 uwsgi 的开机启动.
    但是每次启动时 uwsig 和 celery 都会报错 MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)").
    这是因为 mysqld 在开机时还没有启动,但是我将 mysql 也用 supervisor 启动,并设置了优先级还是同样的问题.
    请问大家遇到这种问题吗?如何解决的?
    25 replies  •  2020-04-22 21:06:39 +08:00
    ClericPy
    ClericPy
    Apr 22, 2020
    1
    好久不用 supervisor 了, 现在用着 systemd 直接一个 After=XXX 就做到串行启动了

    如果非要 supervisor, 以前我是写了个 while 循环不断 sleep 检查是否可连接, 后来受不了才改 systemd 的... 随手搜了下说用 Event 什么的, 以前没试过不确定怎么样
    OnlyO
    OnlyO
    OP
    Apr 22, 2020
    2
    @ClericPy 我也去试试 md
    keepeye
    keepeye
    Apr 22, 2020
    3
    systemd 好用
    lniwn
    lniwn
    Apr 22, 2020
    4
    我用的 circusd,可以使用 hooks,官方有例子: https://circus.readthedocs.io/en/latest/for-devs/writing-hooks/#hooks
    Vegetable
    Vegetable
    Apr 22, 2020
    5
    我感觉 supervisor 应该也有 depend 这种配置,但是接触的太少不了解。
    我也建议直接采用 systemd
    sonice
    sonice
    Apr 22, 2020
    6
    启动不是有优先级吗?

    ```
    The relative priority of the program in the start and shutdown ordering. Lower priorities indicate programs that start first and shut down last at startup and when aggregate commands are used in various clients (e.g. “start all”/”stop all”). Higher priorities indicate programs that start last and shut down first.

    ```
    OnlyO
    OnlyO
    OP
    Apr 22, 2020
    7
    @sonice 设置了优先级,优先级只能保证启动顺序不能保证完全启动 https://stackoverflow.com/questions/17443692/python-supervisord-program-dependency
    sonice
    sonice
    Apr 22, 2020
    8
    @OnlyO #7 还真是,查了一下貌似官方还没有针对这个问题给出合适的解决方案。
    https://github.com/Supervisor/supervisor/issues/122
    awanabe
    awanabe
    Apr 22, 2020
    9
    uwsgi 和 celery 启动的时候去掉依赖 mysql...
    xpresslink
    xpresslink
    Apr 22, 2020
    10
    mysql 服务起动过程相对较慢
    可以弄个 sh 脚本来起动 uwsgi 和 celery 启动,脚本前面先 sleep 30 秒
    把这个脚本加到 rc.local
    keakon
    keakon
    Apr 22, 2020
    11
    把 supervisor 改成在 mysql 后启动
    deljuven
    deljuven
    Apr 22, 2020
    12
    单机编排软件 docker-compose 欢迎你……
    ctOS1H
    ctOS1H
    Apr 22, 2020
    13
    可以试试编排
    AllenBigBear
    AllenBigBear
    Apr 22, 2020
    14
    performance_schema=ON 这个开了,把这个关了就好
    AllenBigBear
    AllenBigBear
    Apr 22, 2020
    15
    忘记贴个链接了,直接自己碰到的,写了个记录。。你看看一样不?
    https://www.jianshu.com/p/3ab146fd5153
    wangyzj
    wangyzj
    Apr 22, 2020
    16
    docker-compose
    superrichman
    superrichman
    Apr 22, 2020 via iPhone
    17
    裸奔的话,supervisor 换成 pm2 管理。
    用 docker 就写个 compose 文件。
    ieric
    ieric
    Apr 22, 2020 via iPhone
    18
    celery 支持 uwsgi 吗?
    ieric
    ieric
    Apr 22, 2020 via iPhone
    19
    celery 支持 uwsig 吗?
    love
    love
    Apr 22, 2020 via Android
    20
    我以前也用这个,后来就换成 systemd 了,更简单更稳定
    Variazioni
    Variazioni
    Apr 22, 2020
    21
    supervisor 顺序启动这块是个坑。。
    只能设置优先级。但是 supervisor 不能检测你的程序有没有完全启动。。
    所以并没有什么卵用。。
    我现在的方案是用关闭配置文件里的自启动。用脚本启动。。supervisorctl start xxx 。然后各 x 秒,启动下一个。。
    vZexc0m
    vZexc0m
    Apr 22, 2020
    22
    可以把 supervisor 的 autostart=true 和 utorestart=true 打开,然后在 celery 和 uwsgi 启动时判断能否连接 MySQL,不能连接则抛出异常停止进程,然后 supervisor 会自动重启 celery 和 uwsgi 。
    OnlyO
    OnlyO
    OP
    Apr 22, 2020
    23
    @vZexc0m 你这思路很清奇,我用 systemd 了.
    Kobayashi
    Kobayashi
    Apr 22, 2020 via Android
    24
    supervisor 控制 MySQL 启动,这什么骚操作
    knightdf
    knightdf
    Apr 22, 2020
    25
    mysql 在 supervisor 之前启动不就好了?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4999 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 87ms · UTC 07:01 · PVG 15:01 · LAX 23:01 · JFK 02:01
    ♥ Do have faith in what you're doing.