Install Serviio on Raspberry Pi using DietPi.

A disclaimer, this is not all my own work, so many thanks to all those who contributed their time and knowledge for the benefit of us all.

This process has been tested using Serviio 2.3 and DietPi 8.11 on an Rpi 3B+.



Getting Started

I am a windows user, specifically Windows 11, and this guide has been written from that standpoint. I am sure that other OS users will be able to extrapolate to suit your own preferred environment - but please don't ask me about things not in this guide.

What you need on Windows.

  • WinSCP- a free SFTP, SCP and FTP client for Windows,
  • Putty- a free implementation of SSH and Telnet for Windows with an xterm terminal emulator,
  • Advanced IP Scanner- a reliable and free network scanner to analyse LAN,
  • a spare wired ethernet connection to your LAN ( where appropriate! ).
  • Balena Etcher- a tool for writing images to USB sticks or SD/CF cards, available for Windows, Mac and Linux.
  • NotePad++(or similar) - Notepad++ is a free (as in "free speech" and also as in "free beer") source code editor and Notepad replacement that supports several languages. I have also set this up to be the default editor in WinSCP.


Source files you need to download.

DietPi- http://www.dietpi.com/#download.

Serviio- http://www.serviio.org - this will be downloaded during the set-up procedure described below.



Set-up DietPi

See : https://dietpi.com/docs/install/

Using dietpi-software install Samba. and Nano

I advise that you change the default SSH tool from OpenBear to OPENSSH.

Using dietpi-drive-manager attach the drive containing your music, this I have called audio.

Configure Samba

Using Putty Edit /etc/samba/smb.conf using :

$ nano /etc/samba/smb.conf

... and under [printers] add :

[audio] comment = Audio Library for Serviio path = /mnt/audio browseable = yes create mask = 0775 directory mask = 0775 valid users = root read only = no writeable = yes max connections = 1

At the command prompt, issue the following command :

$ sudo smbpasswd -a root

You will be prompted to enter and verify a new password for the user. Next issue the command :

$ sudo smbpasswd -e root

and the user will be enabled for Samba shares.



Install Serviio

Introduction

Serviio is media server written in java. It is available in two versions: the free one (unfortunately free as in beer), and the “pro” version, which comes with some additional features like remote access.

Installing dependencies

Serviio is written in java, therefore we must install the java development kit to be able to use it. Serviio expects version 8, but the earliest that is currently available in the Dietpi repositories is 11, this will require a later tweak.

$ sudo apt install --no-install-recommends openjdk-11-jdk ffmpeg x264

Grab and install Serviio

At the time of writing Serviio 2.3 was the latest version. I this has been superseeded you will need to modify the scripts below to reflect the current version number.

Now that we have installed all the needed packages, we must grab the Serviio tarball: since we are working on a headless machine, we will used wget to accomplish the task. Therefore, we run :

$ wget http://download.serviio.org/releases/serviio-2.3-linux.tar.gz

After the download is finished, we can proceed to the actual Serviio installation. We are going to extract the content of the tarball inside the /opt directory: obviously you can choose another one, but /opt is conventionally used to host self-contained third party applications. Let’s proceed :

$ sudo tar -xvzf serviio-2.3-linux.tar.gz -C /opt

The -C option (short for --directory) instructs tar to change directory to the given one, before performing the operations.

Create the systemd service for Serviio

Now that Serviio is installed, you can observe that two scripts exists inside the /opt/serviio-2.3/bin directory: serviio.sh and serviio-console.sh. The first one launches the server while the second the interface to control it.

Because we had to use version 11 of the jdk, we now need to tweak serviio.sh to take account of the change of version 8 to 11.

$ nano /opt/serviio-2.3/bin/serviio.sh

... and modify :

# Check if we are using Java9 JAVA_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}') case "$JAVA_VERSION" in \1.8*) JAVA9_OPTS="" ;; *) JAVA9_OPTS="--add-modules jdk.unsupported" ;; esac

... to

# Check if we are using Java9 or greater... JAVA_VERSION=$("$JAVA" -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;') [ "$JAVA_VERSION" -gt 18 ] && JAVA9_OPTS="--add-modules jdk.unsupported" || JAVA9_OPTS=""

In theory this should allow later jdk versions to be used BUT I have not tested this.

At this point, we have all that we need to create the systemd service to launch serviio when the system boots. To accomplish this task, we must write a small service file. As you surely know, systemd is the new linux init system, now adopted by all the major distributions. It has been the source of many discussions in the open source community, but it has undoubtedly become the standard. To create the service, create a file called serviio.service :

$ nano Serviio.service

... and add the text below :

[Unit] Description=Serviio media Server After=syslog.target network.target [Service] User=serviio ExecStart=/opt/serviio-2.2.1/bin/serviio.sh ExecStop=/opt/serviio-2.2.1/bin/serviio.sh -stop [Install] WantedBy=multi-user.target

Describing the syntax of a systemd service file it’s not the purpose of this tutorial, but please notice the line containing the User=serviio instruction. What we want to obtain with it, is to specify that the daemon must run with the serviio user privileges and not as root, for security reasons. The serviio user doesn’t exist yet, so let’s create it and give it the ownership of the /opt/serviio-2.3 directory and all the files in it:

$ sudo useradd -r -U -s /sbin/nologin serviio && chown -R serviio:serviio /opt/serviio-2.3

You are probably familiar with the useradd command, but for the sake of clarity, let’s specify what the provided options are for. The -r option specifies that we want to create a system account. System accounts have no aging information and a uid with a value< 1000; for such accounts no home directory is created. The -U option will instruct the program to create also a group with the same name as the user, and automatically add the user to said group. Finally with -s, we specified the shell for the user. In this case we used sbin nologin which is a fake shell. We used it for security reasons: this way the user, the service is running as, will never be able to use an actual shell to run commands.< p>

There we are: we have created the serviio user and written our service file. Now we must copy it into the usr systemd system directory :< p>

$ sudo cp serviio.service /etc/systemd/system

To enable the service we now run :

$ sudo systemctl enable serviio.service

Now, reboot the system: if all goes well, the serviio service will be already active when the boot process is completed. You can verify its status by running :

$ systemctl status serviio.service

Systemd will inform you about the status of the daemon, for example :

serviio.service - Serviio media Server Loaded: loaded (/etc/systemd/system/serviio.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2017-09-28 21:29:18 CEST; 31s ago Main PID: 420 (java) CGroup: /system.slice/serviio.service └─420 java -Xmx512M -Xms20M -XX:+UseG1GC -XX:GCTimeRatio=1 -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -Djava.net.preferIPv4Stack=true [...]

As you can see the service is active and running, so all went as expected. If something goes wrong and there are problem launching the service, you can use the logs provided by the same command to resolve the issues.

If you are running a firewall on your machine you must also open ports 8895/tcp, 1900/udp, 23423/tcp and 23424/tcp. The last two ports are needed respectively to control the console and to access the mediabrowser.



Control Serviio

To control Serviio, we have few options. Since we are running on a headless machine, we can’t access the graphical console, but we can access the web interface, by navigating to http://yourmachineip:23423/console/ from another machine in the same lan or use third party applications such as the android app “ServiiDroid”.

A complete list of possible options are available here: http://serviio.org/apps. If you are running the “pro” version of serviio you will also be able to explore your catalog by using the integrated mediabrowser accessible at http://yourmachineip:23424/mediabrowser/.