x

How to add Celery, Celerybeat and Redis to a Django website.

09 Apr 2022 / Oscar F

Install

Redis-server

sudo apt install redis-server

Python packages

In your python environment

pip install redis celery[redis] django-celery-beat

Celery

add to settings.py

INSTALLED_APPS += [
    'django_celery_beat',
]

and

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'

to /project/webbapp/__init__.py add

from .celery import app as celery_app

__all__ = ("celery_app",)

add a celery.py to /project/webbapp/ with

import os

from celery import Celery

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webbapp.settings")

app = Celery("webbapp")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()

Development

redis-server
redis-cli ping
celery -A webapp worker -l info
celery -A webapp beat -l info -S django

Production

sudo nano /etc/redis/redis.conf

change "supervised no" to "supervised systemd"

sudo systemctl enable redis-server.service
sudo systemctl daemon-reload
sudo apt install supervisor

In /etc/supervisor/conf.d add two new files

celery.conf

[program:celery]
directory=/project/webapp
command=/project/webbapp/env/bin/celery -A webapp worker --loglevel=INFO
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600

celerybeat.conf

[program:celerybeat]
directory=/project/webapp
command=/project/webbapp/env/bin/celery -A webbapp beat -S django --loglevel=INFO
autostart=true
autorestart=true
startsecs=10

run the two commands

sudo supervisorctl start all
sudo supervisorctl status all

References:

https://docs.celeryq.dev/en/stable/getting-started/introduction.html#installation

https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/redis.html

https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html

https://docs.celeryq.dev/en/stable/userguide/daemonizing.html

https://github.com/celery/celery/blob/master/extra/supervisord/celeryd.conf

https://github.com/celery/celery/blob/master/extra/supervisord/celerybeat.conf

"Mead and chill" a metheglin mead by Oscfr

13 Mar 2022 / Oscar F

Mead and chill

Type: Metheglin, mead spiced with chili
ABV: 11 %
Flavor: Sweet, chili
My rating: 3.5 / 5

What is metheglin?

According to Wikipedia:

Metheglin: Metheglin is traditional mead with herbs or spices added. Some of the most common metheglins are ginger, tea, orange peel, nutmeg, coriander, cinnamon, cloves or vanilla. Its name indicates that many metheglins were originally employed as folk medicines. The Welsh word for mead is medd, and the word "metheglin" derives from meddyglyn, a compound of meddyg, "healing" + llyn, "liquor".

/ Wikipedia: List of mead variants

How to make metheglin?

You can find my recipe of metheglin here.

Change Gitlab password

30 Jan 2022 / Oscar F

There's two alternative ways.

Both alternatives requires terminal or ssh to the server.

Alternative 1

Tested by me on a Raspberry Pi.

gitlab-rails console production
user = User.where(id: 1).first
user.password = 'your secret'
user.password_confirmation = 'your secret'
user.save
exit

How to setup GitLab on a Raspberry Pi you can read about here.

Alternative 2

The official docs way.

gitlab-rake "gitlab:password:reset[root]"

References:

Alternative 1: https://stackoverflow.com/questions/55747402/docker-gitlab-change-forgotten-root-password

Alternative 2: https://docs.gitlab.com/ee/security/reset_user_password.html

Yubico Yubikey 5C NFC setup on Ubuntu 21.04

11 Dec 2021 / Oscar F

TL;DR Terminal commands for Yubikey 5C NFC setup on Ubuntu 21.04

sudo add-apt-repository ppa:yubico/stable && sudo apt-get update
sudo apt install yubikey-manager
sudo apt install yubikey-personalization-gui
sudo apt install libpam-yubico
sudo apt install libpam-u2f
mkdir -p ~/.config/Yubico
pamu2fcfg > ~/.config/Yubico/u2f_keys

Touch the metal contact to confirm the association.

Backup devices

Insert your backup U2F Key

pamu2fcfg -n >> ~/.config/Yubico/u2f_keys

Touch the metal contact to confirm the association.

Require for Sudo

In /etc/pam.d/sudo below “@include common-auth” add

auth       required   pam_u2f.so

Require for Login

In /etc/pam.d/gdm-password below @include common-auth

auth       required   pam_u2f.so

References:

[1]:Installing Yubico Software on Linux Visited: 10-12-2021

[2]:Ubuntu Linux Login Guide - U2F Visited: 10-12-2021

Tech do links november 2021

15 Nov 2021 / Oscar F