zoukankan      html  css  js  c++  java
  • Celery-系统守护进程

    1. 使用systemd控制Celery

    用法: systemctl {start|stop|restart|status} celery.service

    配置文件: /etc/celery/celery.conf

    celery服务文件: /etc/systemd/system/celery.service

    celery beat服务文件: /etc/systemd/system/celerybeat.service

    服务文件: /etc/systemd/system/celery.service

    [Unit]
    Description=Celery Service
    After=network.target
    
    [Service]
    Type=forking
    User=celery
    Group=celery
    EnvironmentFile=/etc/celery/celery.conf
    WorkingDirectory=/app/celery
    ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} 
      -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} 
      --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
    ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} 
      --pidfile=${CELERYD_PID_FILE}'
    ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} 
      -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} 
      --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
    
    [Install]
    WantedBy=multi-user.target

    应用的配置文件: /etc/celery/celery.conf

    # Name of nodes to start
    # here we have a single node
    CELERYD_NODES="w1"
    # or we could have three nodes:
    #CELERYD_NODES="w1 w2 w3"
    # or we could have three nodes:
    #CELERYD_NODES="w1 w2 w3"
    # or we could have three nodes:
    #CELERYD_NODES="w1 w2 w3"
    
    # Absolute or relative path to the 'celery' command:
    CELERY_BIN="/usr/local/python3.6.5/bin/celery"
    
    # App instance to use
    # comment out this line if you don't use an app
    CELERY_APP="tasks"
    # or fully qualified:
    #CELERY_APP="proj.tasks:app"
    
    # How to call manage.py
    CELERYD_MULTI="multi"
    
    # Extra command-line arguments to the worker
    CELERYD_OPTS="--time-limit=300 --concurrency=8"
    
    # - %n will be replaced with the first part of the nodename.
    # - %I will be replaced with the current child process index
    #   and is important when using the prefork pool to avoid race conditions.
    CELERYD_PID_FILE="/var/run/celery/%n.pid"
    CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
    CELERYD_LOG_LEVEL="INFO"
    
    # you may wish to add these options for Celery Beat
    CELERYBEAT_PID_FILE="/var/run/celery/beat.pid"
    CELERYBEAT_LOG_FILE="/var/log/celery/beat.log"

    Celery Beat服务文件:celerybeat.service 

    这是Celery Beat的示例systemd文件:

     /etc/systemd/system/celerybeat.service

    [Unit]
    Description=Celery Beat Service
    After=network.target
    
    [Service]
    Type=simple
    User=celery
    Group=celery
    EnvironmentFile=/etc/celery/celery.conf
    WorkingDirectory=/opt/celery
    ExecStart=/bin/sh -c '${CELERY_BIN} beat  
      -A ${CELERY_APP} --pidfile=${CELERYBEAT_PID_FILE} 
      --logfile=${CELERYBEAT_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}'
    
    [Install]
    WantedBy=multi-user.target
  • 相关阅读:
    静态资源放置于独立域名之下
    一个程序学习String类的所有常用方法
    Myeclipse的workspace配置文件浅谈
    使用myeclipse自带的tomcat发布web功能怎么访问
    Java陷阱之assert关键字
    Java集合Map接口与Map.Entry学习
    Java中List和ArrayList的区别
    手动命名名字空间打包以及调用
    命令行java -classpath 的使用
    maven 环境变量设置和Java maven工具配置 on windows 7
  • 原文地址:https://www.cnblogs.com/zydev/p/11732239.html
Copyright © 2011-2022 走看看