ObjectiveInstall Serviio media service on Raspberry Pi
- A Raspberry Pi with a working installation of Raspbian "Stretch"
- Root privileges
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
IntroductionServiio 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. In this tutorial we will cover the installation of Serviio on a Raspberry Pi running a minimal versions of Raspbian "Stretch".
Installing dependenciesServiio is written in java, therefore we must install the java development kit to be able to use it. There are two versions of the JDK in the Raspbian Stretch repositories: the open source version, released under the
OpenJDK, and the commercial, proprietary version from Oracle (the package is actually called oracle-java8-jdk). Both of them should work correctly, but in this tutorial we will use the former.
# apt-get update && apt-get install --no-install-recommends openjdk-8-jdk ffmpeg x264
Grab and install ServiioNow 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
wgetto accomplish the task. Therefore, we run:
wget http://download.serviio.org/releases/serviio-1.9-linux.tar.gzAfter the download is finished, we can proceed to the actual Serviio installation. We are going to extract the content of the tarball inside the
/optdirectory: obviously you can choose another one, but /opt is conventionally used to host self-contained third party applications. Let's proceed:
# tar -xvzf serviio-1.9-linux.tar.gz -C /optThe
-Coption (short for
--directory) instructs tar to change directory to the given one, before performing the operations.
Create the systemd service for ServiioNow that Serviio is installed, you can observe that two scripts exists inside the
serviio.shand serviio-console.sh. The first one launches the server while the second the interface to control it.
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, just fire up your favorite editor and create a file called serviio.service containing the text below:
Describing the syntax of a systemd service file it's not the purpose of this tutorial, but please notice the line containing the
[Unit] Description=Serviio media Server After=syslog.target network.target [Service] User=serviio ExecStart=/opt/serviio-1.9/bin/serviio.sh ExecStop=/opt/serviio-1.9/bin/serviio.sh -stop [Install] WantedBy=multi-user.target
User=serviioinstruction. What we want to obtain with it, is to specify that the daemon must run with the
serviiouser privileges and not as root, for security reasons. The
serviiouser doesn't exist yet, so let's create it and give it the ownership of the /opt/serviio-1.9 directory and all the files in it:
# useradd -r -U -s /sbin/nologin serviio && chown -R serviio:serviio /opt/serviio-1.9You are probably familiar with the
useraddcommand, but for the sake of clarity, let's specify what the provided options are for. The
-roption specifies that we want to create a
system account. System accounts have no aging information and a
uidwith a value < 1000; for such accounts no home directory is created. The
-Uoption 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/nologinwhich 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.
There we are: we have created the serviio user and written our service file. Now we must copy it into the
# cp serviio.service /etc/systemd/systemTo enable the service we now run:
# systemctl enable serviio.serviceNow, 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.serviceSystemd 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
23424/tcp. The last two ports are needed respectively to control the console and to access the mediabrowser
Control serviioTo 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