Install Airsonic on FreeBSD

In this tutorial I'll explain how to install Airsonic on FreeBSD.


What is Airsonic?

It's a free, web-based media streamer that provides ubiquitous access to our music. Airsonic was developed for very large music collections. Although it's optimized for MP3 streaming, it works for any audio or video format that can be streamed over HTTP, such as. B. AAC and OGG. Using transcoder plug-ins, Airsonic supports direct conversion and streaming of virtually all audio formats including WMA, FLAC, APE, Musepack, WavPack and Shorten.

Installation

We first install wget, openjdk11 and ffmpeg with the following command:

root: pkg install wget openjdk11 ffmpeg

Next, we create the required directories with the next commands and change to the directory /usr/local/airsonic:

root: mkdir /var/airsonic/

root: mkdir /usr/local/airsonic

root: cd /usr/local/airsonic

Now we can download Airsonic from their GitHub site with wget.

root:  wget https://github.com/airsonic/airsonic/releases/download/v10.6.2/airsonic.war

Note: We can find the latest version here. In the meantime, there is also a fork called Airsonic Advanced, which is a more modern implementation of Airsonic. More information can be found here.

Then we have to set a system link so that Airsonic can find the ffmpeg transcoder.

root: ln -s /usr/local/bin/ffmpeg /var/airsonic/transcode/ffmpeg

We can now start Airsonic on a test basis via the command line.

root: /usr/local/bin/java -jar /usr/local/airsonic/airsonic.war

Create an FreeBSD rc script

Next, we want to create a rc.d script for Airsonic.

root: nano /etc/rc.d/airsonic =>

#!/bin/sh
#
# $FreeBSD: airsonic $
#
# PROVIDE: airsonic REQUIRE: LOGIN KEYWORD: shutdown
#
# Configuration settings for airsonic in /etc/rc.conf:
#
# airsonic_enable (bool):
# Set to "NO" by default. Set it to "YES" to enable airsonic.
#
# airsonic_home (str):
# Set to "/var/airsonic" by default.
#
# airsonic_host (str):
# Set to "0.0.0.0" by default. Specify which IP address to listen to.
#
# airsonic_port (int):
# Set to "4040" by default. Specify which port to listen on for HTTP(S).
#
# airsonic_context_path (str):
# Set to "/" by default. Specify the last part of the airsonic URL, typically "/" or "/airsonic".
#
# airsonic_init_memory (int):
# Set to "192" by default. Specify the memory initial size (Java heap size) in megabytes.
#
# airsonic_max_memory (int):
# Set to "384" by default. Specify the memory limit (Java heap size) in megabytes.
#

. /etc/rc.subr

export LANG=en_EN.UTF-8

name=airsonic

desc="Airsonic is a free, web-based media streamer, providing ubiquitous access to your music"

rcvar=${name}_enable

pidfile="/var/run/${name}.pid"

load_rc_config "${name}"

: ${airsonic_enable:="NO"}
: ${airsonic_user:="root"} #: ${airsonic_user:="media"}
: ${airsonic_group:="wheel"} #: ${airsonic_group:="media"}
: ${airsonic_home:="/var/airsonic"}
: ${airsonic_address:="0.0.0.0"}
: ${airsonic_port:="8080"}
: ${airsonic_ssl:="NO"}
: ${airsonic_context_path:="/"}
: ${airsonic_init_memory:="1024"}
: ${airsonic_max_memory:="2048"}
: ${airsonic_chdir:="/usr/local/airsonic"}

start_cmd=airsonic_start
stop_cmd=airsonic_stop
restart_cmd=airsonic_restart
status_cmd=airsonic_status
start_precmd="export LC_CTYPE='en_US.UTF-8'"

# -Dairsonic.defaultMusicFolder=${airsonic_home}/artists \
# -Dairsonic.defaultUploadFolder=${airsonic_home}/incoming \
# -Dairsonic.defaultPodcastFolder=${airsonic_home}/podcasts \
# -Dairsonic.defaultPlaylistImportFolder=${airsonic_home}/playlists/import \
# -Dairsonic.defaultPlaylistExportFolder=${airsonic_home}/playlists/export \
# -Dairsonic.defaultPlaylistBackupFolder=${airsonic_home}/playlists/backup \

command="/usr/sbin/daemon -p ${pidfile} -f -u ${airsonic_user}"

procname="/usr/local/bin/java"

command_args="-Dairsonic.home=${airsonic_home} -Dserver.address=${airsonic_address} -Dserver.port=${airsonic_port} -Dserver.context-path=${airsonic_context_path} -Xms${airsonic_init_memory}m -Xmx${airsonic_max_memory}m -Djava.awt.headless=true -jar ${airsonic_chdir}/airsonic.war"

command_args1="-Dairsonic.home=${airsonic_home} -Dserver.port=${airsonic_port} -jar ${airsonic_chdir}/airsonic.war"

airsonic_start() {
echo "Starting Airsonic"
echo "${command} ${procname} ${command_args}"
cd ${airsonic_chdir}
${command} ${procname} ${command_args}
}

airsonic_stop() {
echo "Stopping Airsonic"
kill `cat ${pidfile}`
rm ${pidfile}
}

airsonic_restart() {
airsonic_stop
sleep 1
airsonic_start
}

airsonic_status() {
if airsonic_check; then
echo "Airsonic running"
return 1
else
echo "Airsonic not running"
return 0
fi
}


airsonic_check() {
if [ -f ${pidfile} ]; then
return 0
else
return 1
fi
}

run_rc_command "$1"

We then have to make the script executable.

root: chmod +x /etc/rc.d/airsonic

We will now activate and start Airsonic.

root: service airsonic enable
root: service airsonic start

NGINX configuration

We use NGINX as the reverse proxy server. We now create the following file under /usr /local/etc/nginx/vhosts:

root: nano /usr/local/etc/nginx/vhosts/airsonic.conf =>

server {
    listen 80;
    server_name music.<<domain>>;

    # Proxy to the Airsonic server
    location / {
        proxy_pass                          http://127.0.0.1:8080;
        proxy_http_version                 1.1;
        proxy_cache_bypass                 $http_upgrade;

        # Proxy headers
        proxy_set_header Upgrade           $http_upgrade;
        proxy_set_header Connection        "upgrade";
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host  $host;
        proxy_set_header X-Forwarded-Port  $server_port;

        # Proxy timeouts
        proxy_connect_timeout              60s;
        proxy_send_timeout                 60s;
        proxy_read_timeout                 60s;
    }
}

In our /etc/hosts we add the following line.

root: nano /etc/rc.conf =>

127.0.0.1   music.(domain)

Then we restarted the NGINX.

root: service nginx restart

If we now call up the address http://music.<>, we now see the Airsonic login screen.

Airsonic Screen

Airsonic clients

We can now use the web interface on our PC, but there are also nice clients that we can use that I would like to introduce to you.

stmp

stmp is a console-based client for Airsonic. We can install the whole thing as follows:

root: pkg install stmp

Then we create the configuration file.

mkdir ~/.config/stmp

 nano stmp.toml =>

[auth]
username = 'admin'
password = '(password)'

[server]
host = 'https://music.(domain)'
stmp screen
ShortcutFunctionality
1Folder view
2Queue view
enterPlay song (clears the current queue)
d / deleteRemoves the currently selected song from the queue
DRemoves all songs from the queue
aAdd an album or song to the queue
pPlay or pause
- / =Decrease volume / increase volume

Sublime Music

Sublime Music is a native GTK client with numerous functions for Subsonic-compatible servers.

Python 3.8 is required for Sublime Music.

First, we need to install python38 and py38-pip.

root: pkg install python38 py38-pip

Then we can install Sublime Music with pip.

pip-3.8 install sublime-music
sublime music screen