INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Systemd Services for JRiver (To Facilitate Running Headless on Linux)  (Read 5963 times)

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5162
  • "Linux Merit Badge" Recipient

Here's a systemd service that will automatically start jriver on boot as your user (after the display manager loads), and if JRiver should crash, restarts it within 10 seconds.  This will work best on systems with autologin, but because of the restarting feature, should work fine even if it has to wait for you to login.  You want to put your username in the "user" spot, and put the following text in a file at /etc/systemd/system/jriver.service:
Code: [Select]
  [Unit]
     Description=JRiver
     After=display-manager.service

  [Service]
     Type=simple
     Environment=DISPLAY=:0
     User=your_user_here
     ExecStart=/usr/bin/mediacenter24 /MediaServer
     Restart=always
     RestartSec=10
     KillSignal=SIGHUP
     TimeoutStopSec=45

  [Install]
     WantedBy=graphical.target

If you have already setup the optional thread prioritization to prioritize CPU time for audio playback (as described here: https://yabb.jriver.com/interact/index.php/topic,115349.msg797319.html#msg797319), use the following service file instead:
Code: [Select]
  [Unit]
     Description=JRiver
     After=display-manager.service

  [Service]
     Type=simple
     Environment=DISPLAY=:0
     User=your_user_here
     ExecStart=/usr/bin/mediacenter24 /MediaServer
     Restart=always
     RestartSec=10
     KillSignal=SIGHUP
     TimeoutStopSec=45
     LimitRTPRIO=100

  [Install]
     WantedBy=graphical.target

Some technical notes:  this presumes you're running on your actual display, not a virtual display generated by a VNC client.  If you are using such a virtual display, substitute the display variable in the Environment section, and change the "After" line to refer to the name of the systemd service you're using to start your vnc server, but note that VNC virtual displays may not work correctly anymore with MC since 22.0.36. 

In that vein, here's a service to start x11vnc to allow remote access to your actual display on boot.  It similarly will restart if it crashes.  You want to put your username in place of both of the "your_user_here" placeholders below, create a file at /etc/systemd/system/x11vnc.service, and put the following text there:

Code: [Select]
[Unit]
     Description=x11vnc
     After=display-manager.service

  [Service]
     Type=forking
     Environment=DISPLAY=:0
     User=your_user_here
     ExecStart=/usr/bin/x11vnc -rfbauth /home/your_user_here/.vnc/passwd -display :0 -geometry 1920x1080 -auth guess -forever -bg
     Restart=always
     RestartSec=10

  [Install]
     WantedBy=graphical.target

Technical notes: this presumes that you've already setup a VNC password.  If you want to run without a password remove the -rfbauth flag and the path following it.  If you want to set a password run the following command replacing "your_password" with your password:

Code: [Select]
x11vnc -storepasswd your_password ~/.vnc/passwd

Once you've got the services in place you can set them to start on boot by typing
Code: [Select]
sudo systemctl enable jriver.service
and/or
Code: [Select]
sudo systemctl enable x11vnc.service
Logged

BradC

  • World Citizen
  • ***
  • Posts: 207

Hi

With this script to start jriver in headless mode, how do I make JRiver play a playlist from boot?

I tried adding another line with mediacenter24 /Play TREEPATH="PLaylist name"

but it opened another instance of JRiver

help is appreciated

Brad
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 71212
  • where the buffalo roam

Take a look at the options.  General > Behavior.  You may find what you need there.
Logged

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5162
  • "Linux Merit Badge" Recipient

Hi

With this script to start jriver in headless mode, how do I make JRiver play a playlist from boot?

I tried adding another line with mediacenter24 /Play TREEPATH="PLaylist name"

but it opened another instance of JRiver

help is appreciated

Brad

AFAIK the command line control switches aren't implemented on mediacenter for linux.  To make mediacenter play something you either have to point it at the literal file on the command line (which you could try if the playlist is a static playlist saved as a file), or send the request through MCWS and media network.  I've never done any direct automation that way so can't provide examples, but you can probably use curl or wget to send the MCWS command. 
Logged

BradC

  • World Citizen
  • ***
  • Posts: 207

Take a look at the options.  General > Behavior.  You may find what you need there.

Hi

The only that I see is 'resume playback using bookmarks: Automatic'

This does seem to start the playlist on reboot where it left off

Any way to shuffle the playlist on each boot?
Logged

Zhillsguy

  • Galactic Citizen
  • ****
  • Posts: 325

I'm not running headless, assuming the options are the same, you can activate Options/Startup/Start playing current playlist, and turn on shuffle under Playing Now. I don't know what the difference between Shuffle On and Shuffle Automatic is.
Logged
Ryzen 5 W11 x64 MC 29 HTPC/Server and HP G2 Mini Elitedesk W11 MC 29 (music only zone), various Android Phones and Tablets for control of both, powering two lanai surround systems, 5.1 and 4.1 respectively.

sekrit

  • Recent member
  • *
  • Posts: 33
Re: Systemd Services for JRiver (To Facilitate Running Headless on Linux)
« Reply #6 on: September 22, 2018, 04:47:18 pm »

Ubuntu has built-in "startup applications" feature.  In fact, when JRiver 24 is installed on Ubuntu18.04, it is automatically added to the startup applications list.
Logged
Devialet Phantoms (Silver) x2  << Devialet Dialog router << Gb Network << JRiver MC 24 Ubuntu 18.04 x64 [Core2duo E8400, 4Gb, SSD] << File server Windows 10 x64 [Supermicro X11SSH-LN4F, Xeon E3-1425 v5, 30 Tb 16Gb]

biblio

  • Junior Woodchuck
  • **
  • Posts: 81
Re: Systemd Services for JRiver (To Facilitate Running Headless on Linux)
« Reply #7 on: January 13, 2019, 05:23:45 pm »

For those not aware the "Startup Applications" program is a GUI for a local folder.

~/.config/autostart/

If you put .desktop files in that folder they will start when you log in.

Desktop files are either in
/usr/share/applications (system)
~/.local/share/applications (user)
Logged

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2550
Re: Systemd Services for JRiver (To Facilitate Running Headless on Linux)
« Reply #8 on: January 13, 2019, 05:57:05 pm »

Ubuntu has built-in "startup applications" feature.  In fact, when JRiver 24 is installed on Ubuntu18.04, it is automatically added to the startup applications list.

For those not aware the "Startup Applications" program is a GUI for a local folder.

~/.config/autostart/

If you put .desktop files in that folder they will start when you log in.

Desktop files are either in
/usr/share/applications (system)
~/.local/share/applications (user)

It can get complicated quickly when you are running a headless server or need to start an X or VNC server before starting MC.

A systemd service alleviates a lot of those issues.
Logged

biblio

  • Junior Woodchuck
  • **
  • Posts: 81
Re: Systemd Services for JRiver (To Facilitate Running Headless on Linux)
« Reply #9 on: January 13, 2019, 09:08:58 pm »

I agree; for the unit file there are some extras some people might want.
(This is just altered from a different program i run renamed for mediacenter)

You could wait for network and remote file systems in the unit section.
use a pid file for reloading so you don't reload over the top of yourself
use a group on top of a user if you have shared files under different permissions.

Code: [Select]
[Unit]
Description=MediaCenter24
After=display-manager.service network.target remote-fs.target nss-lookup.target
Documentation=https://yabb.jriver.com/interact/index.php/topic,115514.0/topicseen.html

[Service]
PrivateTmp=true
KillMode=mixed
Type=simple
Environment=DISPLAY=:0
User=user
Group=user
ExecStart=/usr/bin/mediacenter24 /MediaServer
PIDFile=/run/mediacenter24.pid
Restart=always
ExecReload=/bin/kill -HUP $MAINPID
ProtectSystem=yes

[Install]
WantedBy=multi-user.target

Logged
Pages: [1]   Go Up