VLC Headless WEB Interface

Hello. im new on this forum. My name is Mirko and im from Argentina.
Y installed DietPi (i`m very satisfied whit this OS performance on my raspberry Pi B+ model) whit no video interface (headless). I acces it, by ssh.

I can start and stop vlc web server via terminal commands.
uname -a returns:
dietpi@xxx:~$ uname -a
Linux DietPiServer 4.14.49+ #1120 Wed Jun 13 16:51:11 BST 2018 armv6l GNU/Linux

All is perfect until I disconnect the ssh terminal. The service stop inmediately.
I need a service that start on boot and remains active.

Searching with my friend google, i found systemd process to create custom services. I`m trying to learn this method, because rc.local in this version is deprecated (or not recommenden at least).
I created the following files:

/etc/vlc/start.sh

(script to run VLC as non root user(VLC requirement), with the desired host, port and password, this last mandatory).

#!/bin/sh
echo "Starting WEB Interface for VLC...."
sudo -u dietpi vlc -I http --http-password 123

May be I will use cvlc (command line without interface )
This file have execution privileges.

/etc/systemd/system/vlc.service

(Systemd service file) with 755 and X privileges.


[Unit]
Description=VLC WEB Interface Service
After=network.target

[Service]
Type=forking
ExecStart=/etc/vlc/start.sh
Restart=on-abort

[Install]
WantedBy=multi-user.target

Running de .sh script directly returns:

dietpi@xxx:/etc/systemd/system$ sudo /etc/vlc/start.sh
Starting WEB Interface for VLC....
VLC media player 2.2.6 Umbrella (revision 2.2.6-0-g1aae78981c)
[00616e68] pulse audio output error: PulseAudio server connection failure: Connection refused
[00636c48] core interface error: no suitable interface module
[0057a918] core libvlc error: interface "globalhotkeys,none" initialization failed
[00636cb0] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[00636cb0] core interface error: no suitable interface module
[0057a918] core libvlc error: interface "dbus,none" initialization failed
[00636cb0] [http] lua interface: Lua HTTP interface

The WEB Interface is up, and I can explore my dietpi User_data folder with some mp3, ogg, etc songs. Sounds very good with de jack output (remember, no HDMI output).

The terminal is locked until I press Ctrl+C. At this point the Interface gets down.

Now, when I execute:

sudo systemd start vlc.service

the Web Interface is Up again… but the service locks the terminal for around one minute and after this time, I got this message:

dietpi@xxx:/etc/systemd/system$ sudo systemctl start vlc.service 
Job for vlc.service failed because a timeout was exceeded.
See "systemctl status vlc.service" and "journalctl -xe" for details.

Asking for a service status ends in this:

dietpi@xxx:/etc/systemd/system$ sudo systemctl status vlc.service 
● vlc.service - VLC WEB Interface Service
   Loaded: loaded (/etc/systemd/system/vlc.service; disabled; vendor preset: enabled)
   Active: failed (Result: timeout) since Mon 2018-06-18 21:40:35 -03; 1min 34s ago
  Process: 2980 ExecStart=/etc/vlc/start.sh (code=killed, signal=TERM)
   CGroup: /system.slice/vlc.service

jun 18 21:39:06 xxx start.sh[2980]: [00e15918] core libvlc error: interface "globalhotkeys,none" initia
lization failed
jun 18 21:39:06 xxx start.sh[2980]: [00ed1cb0] dbus interface error: Failed to connect to the D-Bus ses
sion daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
jun 18 21:39:06 xxx start.sh[2980]: [00ed1cb0] core interface error: no suitable interface module
jun 18 21:39:06 xxx start.sh[2980]: [00e15918] core libvlc error: interface "dbus,none" initialization 
failed
jun 18 21:39:06 xxx start.sh[2980]: [00ed1cb0] [http] lua interface: Lua HTTP interface
jun 18 21:40:35 xxx systemd[1]: vlc.service: Start operation timed out. Terminating.
jun 18 21:40:35 xxx systemd[1]: [color=#FF0080]Failed to start VLC WEB Interface Service.[/color]
jun 18 21:40:35 xxx systemd[1]: vlc.service: Unit entered failed state.
jun 18 21:40:35 xxx systemd[1]: vlc.service: Failed with result 'timeout'.
jun 18 21:40:36 xxx sudo[2981]: pam_unix(sudo:session): session closed for user dietpi
dietpi@xxx :/etc/systemd/system$

I know that I`m doing something in the wrong way. Can Someone guide me to fix this problem? May be, whit some help on this issue, I can will put all together and build a pretty tutorial.

Thankyou in advance.

Mirko

Ok, No answer, but here is my solution after deep browsing.

This link was my reference.

https://wiki.archlinux.org/index.php/VLC_media_player

My new and unique files is:


sudo nano /etc/systemd/system/vlc-web.service

The content of this file is:

[Unit]
Description=VLC WEB-Interface Service MIRKO
After=network.target

[Service]
Type=forking
User=vlcd

ExecStart=/usr/bin/vlc --daemon --syslog -I http --http-port 8181 --http-password 123
Restart=on-abort

[Install]
WantedBy=multi-user.target

The most important line of this service, is

–daemon

thats enables VLC to run as a service into the background.

And the command for creating the vlcd user (remember that VLC deny root`s user) is:

useradd -c "VLC daemon" -d / -G audio -M -p \! -r -s /usr/bin/nologin -u 75 -U vlcd

Then, when the service is created, you can test this, if the service is running correctly.

Reloading all services so the modifications takes effect:

sudo systemctl daemon-reload

Starting the vlc-web.service:

sudo systemctl start vlc-web.service

Could be into simplest way either:

sudo systemctl start vlc-web

I supose that vlcd is the abbreviation to VLC-daemon user name.

To know if this service is running or not (some kind of error could be reported if something went wrong) the command is:

 sudo systemctl status vlc-web.service

Having the following return:

dietpi@xxx:~$ sudo systemctl status vlc-web.service
● > vlc-web.service - VLC WEB-Interface Service MIRKO
Loaded: loaded (/etc/systemd/system/vlc-web.service; enabled; vendor preset: enabled)
Active: > active (running) > since Thu 2018-06-21 19:26:09 -03; 49min ago
Main PID: 351 (vlc)
CGroup: /system.slice/vlc-web.service
└─351 /usr/bin/vlc --daemon --syslog -I http --http-port 8181 --http-password 123

jun 21 20:14:39 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 17
jun 21 20:14:39 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 4096
jun 21 20:14:49 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 17
jun 21 20:14:49 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 4096
jun 21 20:14:59 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 17
jun 21 20:14:59 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 4096
jun 21 20:15:09 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 17
jun 21 20:15:09 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 4096
jun 21 20:15:19 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 17
jun 21 20:15:19 DietPiServer vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 4096
dietpi@DietPiServer:~$

The indicator that all is going well is

Active: > active (running)

that indicates that all is going as expected. You can search into the web for other status, if something doesn`t work.

And finally, to activate the service in boot time, all you need is the following:

sudo systemctl enable vlc-web

After a:

sudo reboot

You can acces your VLC Web Interface from any web browser, or from the VLC Remote Control App in Android devices, and supose from other Os too. The website ask for an user and a password. Let the user blank, and complete the password field with the same written into the service (‘123’ in my example).

And again, you can check for the service status, ensuring that the service is up and running.

sudo systemctl status vlc-web

For those that noticed this:

jun 21 20:33:19 xxx vlc[351]: ts error: libdvbpsi error (PSI decoder): TS duplicate (received 0
, expected 1) for PID 4096

and so on, they are known issues into VLC. This is for VLC <3.0 versions. Theorically, into the newer versions, the problem was solved…
Today, i don`t know how to update to the newest version of VLC, if someone knows the procedure and repos for the Raspberry Pi B+ (or other arm for dietPi) and can post it, i will be very happy and gratefull.

I hope that topic will be usefull for anybody, and spect that more people make things like this to improve SietPi comunity (and other very light distros too).

Regards

Mirko