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 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.
Installation
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 them 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 a FreeBSD RC script
Next, we want to create an rc.d script for Airsonic.
$: 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.
$: 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_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.
$: nano /etc/rc.conf =>
127.0.0.1 music.(domain)
Then we restarted the NGINX.
$: service nginx restart
If we now call up the address http://music.(domain), we see the Airsonic login screen.