celery-systemd-service-unit

Description

Systemd service unit for Celery workers.

Variables

Name Type Default Description

celery_bin

n/a --

n/a Required

celery_entrypoint

n/a --

n/a Required

env_files

list []

Additional systemd environment files, usefule for app-specific configuration.

Format is:

CONFIG_KEY_1=config_value_1
CONFIG_KEY_2=config_value_2

user

string celery

The user to run celery.

Code

doc:
  short_help: Systemd service unit for Celery workers.

args:
  user:
    doc:
      short_help: The user to run celery.
    type: string
    required: false
    default: celery

  env_files:
    doc:
      short_help: Additional systemd environment configuration files.
      help: |
        Additional systemd environment files, usefule for app-specific configuration.

        Format is:

            CONFIG_KEY_1=config_value_1
            CONFIG_KEY_2=config_value_2

    type: list
    schema:
      type: string
    required: false
    empty: true
    default: []
frecklets:
- systemd-service-unit:
    name: celery
    enabled: true
    started: true
    unit_description: Celery worker daemons.
    unit_after:
    - network.target
    install_wanted_by:
    - multi-user.target
    service_type: forking
    service_environment_file: '{{:: env_files ::}}'
    service_environment:
      CELERYD_NODES: w1
      CELERY_BIN: '{{:: celery_bin ::}}'
      CELERY_APP: '{{:: celery_entrypoint ::}}'
      CELERYD_MULTI: multi
      CELERYD_OPTS: --time-limit=300 --concurrency=8
      CELERYD_PID_FILE: /run/celery/%n.pid
      CELERYD_LOG_FILE: /var/log/celery/%n%I.log
      CELERYD_LOG_LEVEL: INFO
      CELERYBEAT_PID_FILE: /run/celery/beat.pid
      CELERYBEAT_LOG_FILE: /var/log/celery/beat.log
    service_exec_start: /bin/sh -c '${CELERY_BIN} ${CELERYD_MULTI} start ${CELERYD_NODES}
      -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE}
      --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
    service_exec_stop: /bin/sh -c '${CELERY_BIN} ${CELERYD_MULTI} stopwait ${CELERYD_NODES}
      --pidfile=${CELERYD_PID_FILE}'
    service_exec_reload: /bin/sh -c '${CELERY_BIN} ${CELERYD_MULTI} restart ${CELERYD_NODES}
      -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE}
      --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
    service_exec_start_pre:
    - +/bin/mkdir /run/celery
    - '+/bin/chown -R {{:: user ::}} /run/celery'
    - +/bin/mkdir -p /var/log/celery
    - '+/bin/chown -R {{:: user ::}} /var/log/celery'
    service_exec_stop_post:
    - +/bin/rm -rf /run/celery
- init-service-restarted:     # can't make it work otherwise
    name: celery
frecklecute --community celery-systemd-service-unit --help

Usage: frecklecute celery-systemd-service-unit [OPTIONS]

  Systemd service unit for Celery workers.

Options:
  --celery-bin CELERY_BIN         n/a  [required]
  --celery-entrypoint CELERY_ENTRYPOINT
                                  n/a  [required]
  --env-files ENV_FILES           Additional systemd environment configuration
                                  files.
  --user USER                     The user to run celery.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.celery_systemd_service_unit.CelerySystemdServiceUnit
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class CelerySystemdServiceUnit(AutoPycklet):
    """Systemd service unit for Celery workers.

       Args:
         celery_bin: n/a
         celery_entrypoint: n/a
         env_files: Additional systemd environment configuration files.
         user: The user to run celery.

    """

    FRECKLET_ID = "celery-systemd-service-unit"

    celery_bin: str = None
    celery_entrypoint: str = None
    env_files: List = None
    user: str = None


    def __post_init__(self):
        super(CelerySystemdServiceUnit, self).__init__(var_names=["celery_bin", "celery_entrypoint", "env_files", "user"])


frecklet_class = CelerySystemdServiceUnit
# -*- coding: utf-8 -*-


#
# module path: pycklets.celery_systemd_service_unit.CelerySystemdServiceUnit
#


from pyckles import AutoPycklet

class CelerySystemdServiceUnit(AutoPycklet):
    """Systemd service unit for Celery workers.

       Args:
         celery_bin: n/a
         celery_entrypoint: n/a
         env_files: Additional systemd environment configuration files.
         user: The user to run celery.

    """

    FRECKLET_ID = "celery-systemd-service-unit"

    def __init__(self, celery_bin=None, celery_entrypoint=None, env_files=None, user="celery"):

        super(CelerySystemdServiceUnit, self).__init__(var_names=["celery_bin", "celery_entrypoint", "env_files", "user"])
        self._celery_bin = celery_bin
        self._celery_entrypoint = celery_entrypoint
        self._env_files = env_files
        self._user = user

    @property
    def celery_bin(self):
        return self._celery_bin

    @celery_bin.setter
    def celery_bin(self, celery_bin):
        self._celery_bin = celery_bin

    @property
    def celery_entrypoint(self):
        return self._celery_entrypoint

    @celery_entrypoint.setter
    def celery_entrypoint(self, celery_entrypoint):
        self._celery_entrypoint = celery_entrypoint

    @property
    def env_files(self):
        return self._env_files

    @env_files.setter
    def env_files(self, env_files):
        self._env_files = env_files

    @property
    def user(self):
        return self._user

    @user.setter
    def user(self, user):
        self._user = user



frecklet_class = CelerySystemdServiceUnit