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

  显示原文与译文双语对照的内容
0 0

我有一个 Docker,通过supervisord运行 Django celery 工作,程序设置非常简单


[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

部署周期使用图来管理 dockers,这是我们的fig.yml 文件在工作环境中的样子


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

我们所面临的问题是,当我们尝试使用 fig restart worker 时,supervisord程序会失败,因为它发现了以下错误。


[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 up worker 是的,因为很明显,up 图像试图重新创建容器,而不是使用现有的。 但是这会导致所有链接服务重新创建,从而丢失RabbitMQ数据和Redis缓存。

是否可以使用简单 fig restart worker 重新启动 Docker,并确保在重新启动时清除 pid? 请告知

时间: 原作者:

0 0

创建一个 ENTRYPOINT 脚本,在运行 CMD 之前清除任何状态数据。 E.g.


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

entrypoint.sh 中:


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

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

原作者:
...