Install Airsonic on FreeBSD

๐Ÿ• 4 minutes

๐Ÿ“… 2022-01-30

What is Airsonic?

Itโ€™s a free, web-based media streamer that provides ubiquitous access to our music. Airsonic was developed for huge 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.


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

$: pkg install wget openjdk11 ffmpeg

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

$: mkdir /var/airsonic/

$: mkdir /usr/local/airsonic

$: cd /usr/local/airsonic

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

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

Note: We can find the latest version here. Meanwhile, 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.

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

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

$: /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.

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

# $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 "" 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


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



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:=""}
: ${airsonic_port:="8080"}
: ${airsonic_ssl:="NO"}
: ${airsonic_context_path:="/"}
: ${airsonic_init_memory:="1024"}
: ${airsonic_max_memory:="2048"}
: ${airsonic_chdir:="/usr/local/airsonic"}

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}"


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() {
sleep 1

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

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

run_rc_command "$1"

We then have to make the script executable.

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

We will now activate and start Airsonic.

$: service airsonic enable
$: service airsonic start

NGINX configuration

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

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

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

    # Proxy to the Airsonic server
    location / {
        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.

$: nano /etc/rc.conf =>	music.(domain)

Then we restarted the NGINX.

$: service nginx restart

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

Airsonic screenshot