x

Basic Linux user and PostgreSQL setup commands

27 Aug 2022 / Oscar F

Linux commands

User

Add new user

sudo adduser devuser

Sudo privileges

Add sudo privileges

adduser devuser sudo

Remove sudo privileges from user

sudo deluser devuser sudo

Change password on user[1]

sudo passwd devuser

Delete user [2]

userdel -r devuser

if error

sudo killall -u devuser

or

userdel -f devuser

PostgreSQL commands

Setup

Create database

sudo su - postgres
createdb devdb

Create database user

sudo su - postgres
createuser -P devuser

or [3]

sudo su - postgres
psql
CREATE USER devuser WITH PASSWORD 'devpassword';
\q

Grant privileges to database user

sudo su - postgres
psql
GRANT ALL PRIVILEGES ON DATABASE devdb TO devuser;
\q

Backup

sudo su - postgres
pg_dump --no-owner -x devdb > backup.psql
exit

Restore backup

sudo su - devuser
psql devdb < backup.psql

Lemon mead recipe

18 Jun 2022 / Oscar F

Mead with lemon recipe inspired by recipes from HBL.

Required equipment:

  • 4.5-5 l Demijohn
  • 4.5-5 l stockpot
  • Hydrometer
  • Thermometer
  • Bung
  • Airlock

Good to have equipment:

  • Siphon
  • Funnel
  • Spoons

I used yeast M05 from mangrovejacks.com and vwp sterilizer.

Ingredients:

  • 1 Lemon
  • 1,3 kg Honey
  • 3,5 l Water
  • 10 g Yeast

Instructions:

Wash the demijohn.

Fill the demijohn with water and sterilizer.

Wait 30 minutes.

Wash the stockpot.

Pour the sterilized water from the demijohn in the stockpot.

Wash two spoons, a funnel, a thermometer, a bung and an airlock.

Put the equipment in the stockpot with the sterilized water.

Wait 10 minutes and rinse the equipment thoroughly and put them in a dish rack.

Slice the lemon in some slices and remove the yellow and white peel.

Dissolve the honey with 3,5 l new fresh spring water in the stockpot. If nessesary heat the water to a max ~32°C to dissolve the honey completely.

Pour the honey water mix in to the demijohn.

Add the lemon pieces to the demijohn.

Pour the yeast in the demijohn and put on the bung with airlock.

Let it ferment for at least 4 weeks.

Transfer into bottles. Drink, enjoy and scold in the company of good friends!

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