TIL-20210216

Centos7 에서 Celery 데몬화하여 동작시키기Permalink

  1. /etc/conf.d/celery
ELERYD_NODES="w1"
CELERY_BIN="/root/apps/notification-drawer-api/venv/bin/celery"
CELERY_APP="config"
CELERYD_MULTI="multi"
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="/root/apps/notification-drawer-api/celery-%n.pid"
CELERYD_LOG_FILE="/root/apps/notification-drawer-api/celery-%n%I.log"
CELERYD_LOG_LEVEL="INFO"

# you may wish to add these options for Celery Beat
CELERYBEAT_PID_FILE="/root/apps/notification-drawer-api/celery-beat.pid"
CELERYBEAT_LOG_FILE="/root/apps/notification-drawer-api/celery-beat.log"
  1. /etc/systemd/system/celery.service
[Unit]
Description=Celery Service
After=network.target

[Service]
Type=forking
User=root
Group=root
EnvironmentFile=/etc/conf.d/celery
WorkingDirectory=/root/apps/notification-drawer-api
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} --loglevel=${CELERYD_LOG_LEVEL}'
ExecReload=/bin/sh -c '${CELERY_BIN} -A ${CELERY_APP} multi restart ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

[Install]
WantedBy=multi-user.target
  1. /etc/systemd/system/celerybeat.service
[Unit]
Description=Celery Beat Service
After=network.target

[Service]
Type=simple
User=root
Group=root
EnvironmentFile=/etc/conf.d/celery
WorkingDirectory=/root/apps/notification-drawer-api
ExecStart=/bin/sh -c '${CELERY_BIN} -A ${CELERY_APP} beat --pidfile=${CELERYBEAT_PID_FILE} --logfile=${CELERYBEAT_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}'

[Install]
WantedBy=multi-user.target

Celery 명령어Permalink

sudo systemctl daemon-reload => 실행 스크립트를 생성하거나 수정한 다음에는 이 명령어를 통해 파일이 변경되었음을 알려줘야 함

서비스 시작 sudo systemctl start celery.service => celery 서비스를 구동 sudo systemctl start celerybeat.service => celery beat 서비스를 구동

서비스 상태 점검 sudo systemctl status celery.service => Celery 상태를 점검 sudo systemctl status celery.service => Celery beat상태를 점검

시스템을 (재) 부팅 할 때 셀러리 서비스가 자동으로 시작되도록 하려면  systemctl enable celery.service

Celery 설정파일 위치

/etc/conf.d/celery : 변수 설정파일 /etc/systemd/system/celery.service : 셀러리(비동기) /etc/systemd/system/celerybeat.service : 셀러리(crontab 주기적작업)

/var/log/message : systemctl log 보는 곳

참고사이트 https://devlog.jwgo.kr/2019/07/05/celery-daemonization/

선택적으로 셀러리 서비스에 대한 추가 종속성을 지정할 수 있습니다. 예를 들어 RabbitMQ를 브로커로 사용하는 경우 rabbitmq-server.service모두 After=및 systemd 섹션Requires= 에서 지정할 수 있습니다.[Unit] 구성의 사용자, 그룹에 CHDIR 설정을 변경 : User, Group,와 WorkingDirectory정의 /etc/systemd/system/celery.service. 작업 디렉토리 (log 및 pid 용)를 생성하기 위해 systemd-tmpfiles를 사용할 수도 있습니다.

https://docs.celeryproject.org/en/latest/userguide/daemonizing.html

2021-02-18

알게된 것

  1. Celery에서 Debug = True 일 경우 메모리 누수가 있다고 한다.

태그:

카테고리:

업데이트:

댓글남기기