-
-
Save tkrempser/2a4bf6aeb2ec51a6c4370fedc3153d3d to your computer and use it in GitHub Desktop.
How to configure Celery using Elastic Beanstalk with Amazon Linux 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In .ebextensions/01_celery.config | |
files: | |
"/etc/systemd/system/celery.service": | |
mode: "000644" | |
owner: celery | |
group: celery | |
content: | | |
[Unit] | |
Description=Celery Service | |
After=network.target | |
[Service] | |
# I saw some other tutorials suggesting using Type=simple, but that didn't work for me. Type=forking works | |
# as long as you're using an instance with at least 2.0 Gigs of RAM, but on a t2.micro instance it was running out | |
# of memory and crashing. | |
Type=forking | |
Restart=on-failure | |
RestartSec=10 | |
User=celery | |
Group=celery | |
# You can have multiple EnvironmentFile= variables declared if you have files with variables. | |
# The celery docs on daemonizing celery with systemd put their environment variables in a file called | |
# /etc/conf.d/celery, but I'm choosing to instead set the celery variables as environment variables so that | |
# celery can also access the necessary variables for interacting with Django. | |
EnvironmentFile=/opt/elasticbeanstalk/deployment/env | |
WorkingDirectory=/var/app/current | |
ExecStart=/bin/sh -c '${CELERY_BIN} multi start worker \ | |
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \ | |
--logfile=${CELERYD_LOG_FILE} --loglevel=INFO --time-limit=300 --concurrency=2' | |
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait worker \ | |
--pidfile=${CELERYD_PID_FILE}' | |
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart worker \ | |
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \ | |
--logfile=${CELERYD_LOG_FILE} --loglevel=INFO --time-limit=300 --concurrency=2' | |
[Install] | |
WantedBy=multi-user.target | |
"/etc/tmpfiles.d/celery.conf": | |
mode: "000755" | |
owner: celery | |
group: celery | |
content: | | |
d /var/run/celery 0755 celery celery - | |
d /var/log/celery 0755 celery celery - | |
container_commands: | |
01_create_celery_log_file_directories: | |
command: mkdir -p /var/log/celery /var/run/celery | |
02_give_celery_user_ownership_of_directories: | |
command: chown -R celery:celery /var/log/celery /var/run/celery | |
03_change_mode_of_celery_directories: | |
command: chmod -R 755 /var/log/celery /var/run/celery | |
04_reload_settings: | |
command: systemctl daemon-reload | |
# In .platform/hooks/postdeploy/01_start_celery.sh | |
#!/bin/bash | |
(cd /var/app/current; systemctl stop celery) | |
(cd /var/app/current; systemctl start celery) | |
(cd /var/app/current; systemctl enable celery.service) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment