Funkwhale

Updated 2 August 2019

Installing and configuring Funkwhale

Introduction

Funkwhale - это проект, разрабатываемый сообществом, который позволяет вам слушать и обмениваться музыкой в децентрализованной, открытой сети.

Подготовка LXC контейнера

Мы рекомендуем выполнить установку Pixelfed в отдельном контейнере, настроив его согласно инструкции.

Installing and configuring PostgreSQL

Install and configure PostgreSQL according to the manual. Вместо базы данных dbtest из примера создайте базу funkwhale, а вместо пользователя test создайте funkwhale.

От пользователя postgres добавьте для базы расширение:

psql -U postgres funkwhale -c 'CREATE EXTENSION "unaccent";'

Installing system packages

Установите вспомогательное программное обеспечение:

emerge -a dev-db/redis app-arch/unzip media-video/ffmpeg media-libs/libjpeg-turbo dev-libs/libpqxx net-nds/openldap sys-devel/gettext

Launching Redis

Запустите Redis и добавьте его в автозагрузку:

/etc/init.d/redis start

rc-update add redis

Adding a system user

Add a user named funkwhale:

mkdir -p /var/calculate/www

useradd -r -s /usr/sbin/nologin -d /var/calculate/www/funkwhale -m funkwhale

Log in as funkwhale:

su - -s /bin/bash funkwhale

Create the necessary directories:

mkdir -p config api data/static data/media data/music front

Загрузка исходного кода Funkwhale

Скачайте и распакуйте последний релиз API:

curl -L -o "api-0.19.1.zip" "https://dev.funkwhale.audio/funkwhale/funkwhale/-/jobs/artifacts/0.19.1/download?job=build_api"

unzip "api-0.19.1.zip" -d extracted

mv extracted/api/* api/

rm -rf extracted

Скачайте и распакуйте последний релиз фронтэнда:

curl -L -o "front-0.19.1.zip" "https://dev.funkwhale.audio/funkwhale/funkwhale/-/jobs/artifacts/0.19.1/download?job=build_front"

unzip "front-0.19.1.zip" -d extracted

mv extracted/front .

rm -rf extracted

Установка Python зависимости

Create a virtual environment:

python3 -m venv virtualenv

source virtualenv/bin/activate

Установите Python зависимости:

pip install wheel

pip install -r api/requirements.txt

Configuring Funkwhale

Скачайте файл настроек и выставите права:

curl -L -o ~/config/.env "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/master/deploy/env.prod.sample"

chmod 600 ~/config/.env

Create a private key for Django:

openssl rand -base64 45
ev5pFTw2gV4TEOeAmCwDZB87qGeFgvsHxUJt5A7c4SNfgP1HEZMxM5hz/mw+

Выполните настройку конфигурационного файла для хоста music.example.org:

~/config/.env
# Replace this by the definitive, public domain you will use for
# your instance
FUNKWHALE_HOSTNAME=music.example.org
FUNKWHALE_PROTOCOL=https
...
EMAIL_CONFIG=smtp://mail.example.org:25
# The email address to use to send system emails.
DEFAULT_FROM_EMAIL=support@example.org
...
# API/Django configuration

# Database configuration
# Examples:
#  DATABASE_URL=postgresql://<user>:<password>@<host>:<port>/<database>
#  DATABASE_URL=postgresql://funkwhale:passw0rd@localhost:5432/funkwhale_database
# Use the next one if you followed Debian installation guide
DATABASE_URL=postgresql://funkwhale:secret@localhost:5432/funkwhale

# Cache configuration
# Examples:
#  CACHE_URL=redis://<host>:<port>/<database>
#  CACHE_URL=redis://localhost:6379/0c
#  With a password:
#  CACHE_URL=redis://:password@localhost:6379/0
#  (the extra semicolon is important)
# Use the next one if you followed Debian installation guide
#
CACHE_URL=redis://127.0.0.1:6379/0

# Where media files (such as album covers or audio tracks) should be stored
# on your system?
# (Ensure this directory actually exists)
MEDIA_ROOT=/var/calculate/www/funkwhale/data/media

# Where static files (such as API css or icons) should be compiled
# on your system?
# (Ensure this directory actually exists)
STATIC_ROOT=/var/calculate/www/funkwhale/data/static

# Generate one using `openssl rand -base64 45`, for example
DJANGO_SECRET_KEY=ev5pFTw2gV4TEOeAmCwDZB87qGeFgvsHxUJt5A7c4SNfgP1HEZMxM5hz/mw+

# In-place import settings
# You can safely leave those settings uncommented if you don't plan to use
# in place imports.
# Typical docker setup:
#   MUSIC_DIRECTORY_PATH=/music  # docker-only
#   MUSIC_DIRECTORY_SERVE_PATH=/srv/funkwhale/data/music
# Typical non-docker setup:
#   MUSIC_DIRECTORY_PATH=/srv/funkwhale/data/music
#   # MUSIC_DIRECTORY_SERVE_PATH= # stays commented, not needed

MUSIC_DIRECTORY_PATH=/var/calculate/www/funkwhale/data/music
MUSIC_DIRECTORY_SERVE_PATH=/var/calculate/www/funkwhale/data/music
...
FUNKWHALE_FRONTEND_PATH=/var/calculate/www/funkwhale/front/dist

Выполните инициализацию базы данных:

python api/manage.py migrate

Update the static files:

python api/manage.py collectstatic

Create the superuser:

python api/manage.py createsuperuser
Username: user
Email address: user@example.org
Password: 
Password (again): 
Superuser created successfully.

Quit as funkwhale:

exit

Получение сертификата Let's Encrypt

Получите сертификат домена music.example.org для Nginx согласно руководству.

Installing and configuring Nginx

Установите и настройте веб-сервер Nginx в качестве обратного прокси согласно руководству.

Получите шаблон настройек Funkwhale для Nginx:

export FUNKWHALE_VERSION="0.19.1"

curl -L -o /etc/nginx/funkwhale_proxy.conf "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/0.19.1/deploy/funkwhale_proxy.conf"

curl -L -o /etc/nginx/sites-enabled/funkwhale.template "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/0.19.1/deploy/nginx.template"

Use the template to configure Nginx:

set -a && source /var/calculate/www/funkwhale/config/.env && set +a

envsubst "`env | awk -F = '{printf \" $%s\", $$1}'`" \
< /etc/nginx/sites-enabled/funkwhale.template \
> /etc/nginx/sites-enabled/funkwhale.conf

Starting Funkwhale

Создайте сценарии OpenRC для управления сервисами.

Сценарий запуска Funkwhale server:

/etc/init.d/funkwhale-server
#!/sbin/openrc-run
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

name="Funkwhale application server"
description="Funkwhale application server"
command_user=funkwhale
command=/var/calculate/www/funkwhale/virtualenv/bin/daphne
FUNKWHALE_API_IP=127.0.0.1
FUNKWHALE_API_PORT=5000
command_args="-b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application --proxy-headers"
directory=/var/calculate/www/funkwhale/api
pidfile="/run/funkwhale-server.pid"
command_background=true
output_log=/var/log/funkwhale-server.log
error_log=/var/log/funkwhale-server.log

depend() {
        use net postgresql redis
}

start_pre() {
        checkpath -f -o funkwhale -m 0600 /var/log/funkwhale-server.log
}

Сценарий запуска Funkwhale celery worker:

/etc/init.d/funkwhale-worker
#!/sbin/openrc-run
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

name="Funkwhale celery worker"
description="Funkwhale celery worker"
command_user=funkwhale
command=/var/calculate/www/funkwhale/virtualenv/bin/celery
command_args="-A funkwhale_api.taskapp worker -l INFO"
directory=/var/calculate/www/funkwhale/api
pidfile="/run/funkwhale-worker.pid"
command_background=true
output_log=/var/log/funkwhale-worker.log
error_log=/var/log/funkwhale-worker.log

depend() {
        use net postgresql redis
}

start_pre() {
        checkpath -f -o funkwhale -m 0600 /var/log/funkwhale-worker.log
}

Сценарий запуска Funkwhale beat:

/etc/init.d/funkwhale-beat
#!/sbin/openrc-run
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

name="Funkwhale celery beat process"
description="Funkwhale celery beat process"
command_user=funkwhale
command=/var/calculate/www/funkwhale/virtualenv/bin/celery
command_args="-A funkwhale_api.taskapp beat -l INFO"
directory=/var/calculate/www/funkwhale/api
pidfile="/run/funkwhale-beat.pid"
command_background=true
output_log=/var/log/funkwhale-beat.log
error_log=/var/log/funkwhale-beat.log

depend() {
        use net postgresql redis
}

start_pre() {
        checkpath -f -o funkwhale -m 0600 /var/log/funkwhale-beat.log
}

Установите права на запуск сервисов Funkwhale:

chmod 0755 /etc/init.d/funkwhale-*

Launch Funkwhale services:

/etc/init.d/funkwhale-beat start

/etc/init.d/funkwhale-server start

/etc/init.d/funkwhale-worker start

Add the Funkwhale services to autostart:

rc-update add funkwhale-beat

rc-update add funkwhale-server

rc-update add funkwhale-worker