Quick start: install larigira on Debian buster

Note: this guide is a bit outdated. However, larigira works well on Debian trixie. Most things are similar to what you are reading here, but if you follow this guide for a modern debian, please take it with a grain of salt.

This guides have this assumptions or conventions:
  • you have a Debian buster installation - actually 99% of this should work in any distro with recent-enough python3 and systemd - if you don’t like systemd, you are free to use any other service manager; larigira integrates nicely with systemd, but has no requirement at all on it.

  • you have a non-root main user, which we’ll call radio

  • all commands are meant to be run as root. Use sudo -i if you don’t have root password

Install

Get larigira

Let’s start!:

apt-get install python3 python3-dev build-essential virtualenv mpd mpc libxml2-dev libxslt1-dev zlib1g-dev
virtualenv -p /usr/bin/python3 /opt/larigira/
/opt/larigira/bin/pip3 install larigira
touch /etc/default/larigira
mkdir -p /home/radio/.mpd/ /etc/larigira/ /var/log/larigira/
chown radio. /home/radio/.mpd/
chown radio:adm /var/log/larigira/
touch /etc/systemd/system/larigira.service

Edit /etc/systemd/system/larigira.service and put this content:

[Unit]
Description=Radio Automation
After=mpd.service

[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=/etc/default/larigira
User=radio
ExecStart=/opt/larigira/bin/larigira
Restart=always

[Install]
WantedBy=multi-user.target

Configure mpd

Now let’s edit /etc/mpd.conf:

music_directory              "/home/radio/Music/"
playlist_directory           "/home/radio/.mpd/playlists"
db_file                      "/home/radio/.mpd/tag_cache"
log_file                     "syslog"
pid_file                     "/home/radio/.mpd/pid"
state_file                   "/home/radio/.mpd/state"
sticker_file                   "/home/radio/.mpd/sticker.sql"
user                         "radio"
bind_to_address              "/home/radio/.mpd/socket"
bind_to_address                      "127.0.0.1"
port                         "6600"
log_level                    "default"
replaygain                   "track"
replaygain_limit             "yes"
volume_normalization         "yes"
max_connections "30"

Configure larigira

Now let’s edit larigira settings, editing the file /etc/default/larigira:

MPD_HOST=/home/radio/.mpd/socket
LARIGIRA_DEBUG=false
LARIGIRA_LOG_CONFIG=/etc/larigira/logging.ini

LARIGIRA_EVENT_FILTERS='["percentwait"]'
LARIGIRA_EF_MAXWAIT_PERC=400
LARIGIRA_MPD_ENFORCE_ALWAYS_PLAYING=1
LARIGIRA_SECRET_KEY="changeme with a random, secret string of any length"

Let’s include logging configuration, editing /etc/larigira/logging.ini:

[loggers]
keys=root

[formatters]
keys=brief,ext,debug

[handlers]
keys=syslog,own,owndebug,ownerr

[logger_root]
handlers=syslog,own,owndebug,ownerr
level=DEBUG

[handler_syslog]
class=handlers.SysLogHandler
level=INFO
args=('/dev/log', handlers.SysLogHandler.LOG_USER)
formatter=brief

[handler_own]
class=handlers.WatchedFileHandler
level=INFO
args=('/var/log/larigira/larigira.log',)
formatter=ext
[handler_owndebug]
class=handlers.WatchedFileHandler
level=DEBUG
args=('/var/log/larigira/larigira.debug',)
formatter=debug
[handler_ownerr]
class=handlers.WatchedFileHandler
level=ERROR
args=('/var/log/larigira/larigira.err',)
formatter=ext

[formatter_ext]
format=%(asctime)s|%(levelname)s[%(name)s] %(message)s

[formatter_debug]
format=%(asctime)s|%(levelname)s[%(name)s:%(lineno)d] %(message)s

[formatter_brief]
format=%(levelname)s:%(message)s

For hygiene’s sake, let’s configure rotation for this log, editing /etc/logrotate.d/larigira:

/var/log/larigira/*.err
/var/log/larigira/*.log {
        daily
        missingok
        rotate 14
        compress
        notifempty
        copytruncate
        create 600
}

/var/log/larigira/*.debug {
        daily
        rotate 2
        missingok
        compress
        notifempty
        copytruncate
        create 600
}

Go live!

Restart everything:

systemctl daemon-reload
systemctl restart mpd
systemctl restart larigira
systemctl enable larigira
systemctl enable mpd

Everything should work now!

Add music

For larigira to be able to fill the playlist, you need to give mpd some music. Put your music in mpd’s music_directory, ie /home/radio/Music/. Then, run mpc update. With this, larigira will be able to fill the playlist with some music.

By default, it takes music randomly from mpd’s music_directory, which is a sane default, but you’ll be able to change it when you’re expert enough!