gpt4 book ai didi

docker - 重新启动运行supervisord程序的docker会保留pid文件并在重新启动时导致错误

转载 作者:行者123 更新时间:2023-12-02 02:26:20 26 4
gpt4 key购买 nike

我有一个通过supervisord运行django celery worker的docker,程序设置非常简单

[program:celery_priority]
command=python manage.py celery worker -E -Q priority --concurrency=2 --loglevel=ERROR
directory=/var/lib/app
stdout_events_enabled = true
stderr_events_enabled = true
stopwaitsecs = 600

[program:celery_medium]
command=python manage.py celery worker -E -Q medium --concurrency=2 --loglevel=ERROR
directory=/var/lib/app
stdout_events_enabled = true
stderr_events_enabled = true
stopwaitsecs = 600

[program:celerycam]
command=python manage.py celerycam
directory=/var/lib/app
stdout_events_enabled = true
stderr_events_enabled = true
stopwaitsecs = 600

我们的部署周期使用Fig来管理docker,这是我们的fig.yml文件对于worker的样子

worker:
build: .docker/worker
command: normal
volumes_from:
- appdata
hostname: workerprod
domainname: project.internal
links:
- redis
- rabbit
- appdata
- mail

我们面临的问题是,当我们尝试使用 fig restart worker 时,supervisord 程序会失败,因为它发现 pid 存在冲突,并出现以下错误

[130.211.XX.XX] out: worker_1     | celery_medium stderr | [2015-02-13 13:40:54,271: WARNING/MainProcess] ERROR: Pidfile (/tmp/med_celery.pid) already exists.
[130.211.XX.XX] out: worker_1 | Seems we're already running? (pid: 17)
[130.211.XX.XX] out: worker_1 | celery_priority stderr | [2015-02-13 13:40:54,272: WARNING/MainProcess] ERROR: Pidfile (/tmp/priority_celery.pid) already exists.
[130.211.XX.XX] out: worker_1 | Seems we're already running? (pid: 16)
[130.211.XX.XX] out: worker_1 | 2015-02-13 18:40:54,359 INFO exited: celery_medium (exit status 0; expected)
[130.211.XX.XX] out: worker_1 | 2015-02-13 18:40:54,359 INFO exited: celery_priority (exit status 0; expected)
[130.211.XX.XX] out: worker_1 | 2015-02-13 18:40:55,360 INFO success: celerycam entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

但是,当我们使用 fig -d upworker 时,它可以工作,因为显然使用 up Fig 尝试重新创建容器而不是使用现有容器。但这会导致所有链接服务也重新创建,从而丢失 RabbitMQ 数据和 Redis 缓存。

有没有办法使用简单的fig restart worker来重新启动docker并确保重新启动时清除pid?请指教

最佳答案

创建一个 ENTRYPOINT 脚本,在运行 CMD 之前清理所有状态数据。例如

FROM someotherimage
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

entrypoint.sh中:

#!/bin/sh
rm -f /tmp/*.pid
exec "$@"

ENTRYPOINT 脚本将在每次容器启动时运行,并确保在运行容器命令之前清除 /tmp 中的所有 pid 文件。

关于docker - 重新启动运行supervisord程序的docker会保留pid文件并在重新启动时导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28506722/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com