0

I"m trying to figure out the best "architecture" so our django projects hosted on debian server could use celery and celery beat. He are my requirements:

  • Celery workers and celery beats should be able to run after server restart automatically.
  • Using standard Debian packages is preferred.
  • What doesn't have to be installed globally, should be installed in project virtualenv.
  • Linux user, who is owner of django project shouldn't need sudo permissions to deploy project

Based on these requirements I came to these conclusions:

  • It would be good to use supervisord for deamonizing workers and beat. Supervisord is in standard debian packages and installing it this way means that running of supervisord after server restart is taken care of (this is the main reason why I dont want to install it locally in virtualenv for every project)
  • Celery could be installed locally for every project in virtualenv.

Under these circumstances, when I'm deploying NEW project, next to creating new linux user, setting up apache virtualhost etc., which Im doing as a root, I would also add new config file for supervisord, which seems OK to me. Then when Im deploying new version of project using Fabric im working only under project user.

The only unresolved problem (which I found until now) of this solution is that schedule configuration for celery beat is written in django settings, but beat deamon isnt able to recognize change in the configuration until it's reloaded. However project user isn't allowed to make the reload.

My question is how should I solve this problem or what other architecture would you recommend to me? Thank you.

4

2 回答 2

1

我没有专门用 celery beat 试过这个,但我似乎记得它在另一个程序上对我有用。您可以将主管配置为在特定用户下运行该程序,然后我相信您可以使用以下命令而无需 sudo 如果它是从该用户运行的: supervisorctl [stop/start/restart] [program_name]. 请参阅此处的“用户”参数:

http://supervisord.org/configuration.html#program-x-section-settings

于 2015-02-16T23:34:19.460 回答
0

根据克里斯的回答,如何在没有 sudo 权限的情况下重新启动 supervisord 程序的解决方案:您必须编辑 supervisord.conf 以更改套接字权限(在我的情况下位于 /etc/supervisor/supervisord.conf]

[unix_http_server]
file=/var/run//supervisor.sock   ; (the path to the socket file)
chmod=0766                       ; sockef file mode (default 0700)

然后您必须确保写入配置文件的用户是将重新启动程序的用户:

[program:projectx_celerybeat]
; Set full path to celery program if using virtualenv
command=/path_to_project_root/env/bin/celery beat -A main -s /path_to_project_root/celerybeat-schedule --loglevel=INFO

; remove the -A myapp argument if you are not using an app instance

directory=/home/xxx/project_root/celery_root/
user=YOUR_USER
numprocs=1
stdout_logfile=/path_to_log/beat.log
stderr_logfile=/path_to_log/beat.log
autostart=true
autorestart=true
startsecs=10

然后由 YOUR_USER 运行的这个命令应该可以工作:

supervisorctl [stop/start/restart] [program_name]
于 2015-02-17T15:42:52.943 回答