supervisor 和 mysql 开机启动问题

2020-04-22 09:13:31 +08:00
 OnlyO
我用 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 启动,并设置了优先级还是同样的问题.
请问大家遇到这种问题吗?如何解决的?
3682 次点击
所在节点    Python
25 条回复
ClericPy
2020-04-22 09:38:38 +08:00
好久不用 supervisor 了, 现在用着 systemd 直接一个 After=XXX 就做到串行启动了

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

```
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
2020-04-22 10:33:07 +08:00
@sonice 设置了优先级,优先级只能保证启动顺序不能保证完全启动 https://stackoverflow.com/questions/17443692/python-supervisord-program-dependency
sonice
2020-04-22 10:49:20 +08:00
@OnlyO #7 还真是,查了一下貌似官方还没有针对这个问题给出合适的解决方案。
https://github.com/Supervisor/supervisor/issues/122
awanabe
2020-04-22 11:00:06 +08:00
uwsgi 和 celery 启动的时候去掉依赖 mysql...
xpresslink
2020-04-22 11:13:31 +08:00
mysql 服务起动过程相对较慢
可以弄个 sh 脚本来起动 uwsgi 和 celery 启动,脚本前面先 sleep 30 秒
把这个脚本加到 rc.local
keakon
2020-04-22 11:25:11 +08:00
把 supervisor 改成在 mysql 后启动
deljuven
2020-04-22 11:33:10 +08:00
单机编排软件 docker-compose 欢迎你……
ctOS1H
2020-04-22 11:36:09 +08:00
可以试试编排
AllenBigBear
2020-04-22 11:44:04 +08:00
performance_schema=ON 这个开了,把这个关了就好
AllenBigBear
2020-04-22 11:46:05 +08:00
忘记贴个链接了,直接自己碰到的,写了个记录。。你看看一样不?
https://www.jianshu.com/p/3ab146fd5153
wangyzj
2020-04-22 12:04:29 +08:00
docker-compose
superrichman
2020-04-22 12:10:07 +08:00
裸奔的话,supervisor 换成 pm2 管理。
用 docker 就写个 compose 文件。
ieric
2020-04-22 13:25:26 +08:00
celery 支持 uwsgi 吗?
ieric
2020-04-22 13:26:44 +08:00
celery 支持 uwsig 吗?
love
2020-04-22 15:34:43 +08:00
我以前也用这个,后来就换成 systemd 了,更简单更稳定

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/664857

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX