INTERACT FORUM

Please login or register.

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

Author Topic: Systemd services to autostart JRiver and a VNC server  (Read 4607 times)

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5174
  • "Linux Merit Badge" Recipient
Systemd services to autostart JRiver and a VNC server
« on: July 23, 2017, 08:45:46 am »

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/mediacenter23 /MediaServer
     Restart=always
     RestartSec=10
     KillSignal=SIGHUP
     TimeoutStopSec=45

  [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

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2239
Re: Systemd services to autostart JRiver and a VNC server
« Reply #1 on: July 24, 2017, 04:01:18 pm »

Nice.

You're doing a great job to add another merit badge to your collection.

Will keep this in mind when I the opportunity to tinker presents.
Logged
MC31, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

tombert

  • Galactic Citizen
  • ****
  • Posts: 449
Re: Systemd services to autostart JRiver and a VNC server
« Reply #2 on: September 14, 2017, 04:36:05 pm »

I would like to note for others that display-manager.service is a link to lightdm.service (at least in Ubuntu 16):

Code: [Select]
lrwxrwxrwx  1 root root   35 Sep  7 22:03 display-manager.service -> /lib/systemd/system/lightdm.service
At least on my system mediacenter23 did not start reliable (sometimes yes, more-often no):
Replacing the line:
Code: [Select]
After=display-manager.servicewith:
Code: [Select]
After=lightdm.serviceseems to work better.

Also I would recommend to replace:
Code: [Select]
Restart=alwayswith:
Code: [Select]
Restart=on-failureThis way one can shutdown MC without it being restarted automatically.

Logged

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5174
  • "Linux Merit Badge" Recipient
Re: Systemd services to autostart JRiver and a VNC server
« Reply #3 on: September 14, 2017, 04:50:57 pm »

I would like to note for others that display-manager.service is a link to lightdm.service (at least in Ubuntu 16):

Code: [Select]
lrwxrwxrwx  1 root root   35 Sep  7 22:03 display-manager.service -> /lib/systemd/system/lightdm.service
At least on my system mediacenter23 did not start reliable (sometimes yes, more-often no):
Replacing the line:
Code: [Select]
After=display-manager.servicewith:
Code: [Select]
After=lightdm.serviceseems to work better.

display-manager.service is always linked to the display manager for the distro.  On ubuntu it's lightdm, on debian its gdm (by default), on fedora gdm, etc.  So display-manager.service is guaranteed to point to the right place, and is the correct general purpose answer.  As a symlink it's interchangeable with the thing linked to, so it's would be very unusual if you're actually seeing different results with "after=lightdm.service," but if you are there is something peculiar about your install.

Additionally the always auto-restart should be bringing MC up shortly if it doesn't succeed in loading the first time (unless you changed it to "on failure" as you described, because systemd doesn't always do a good job of distinguishing failure-based shutdowns)

Quote
Also I would recommend to replace:
Code: [Select]
Restart=alwayswith:
Code: [Select]
Restart=on-failureThis way one can shutdown MC without it being restarted automatically.

I initially tried that, but my experience was that some of MC's failure modes do not successfully hook "on-failure", so I'd get crashes where MC would never respawn.  I was using this primarily on headless systems, so "always" was a safer choice.  If you want to stop MC on a system with the "always" option, there's always "systemctl stop jriver.service"
Logged

Awesome Donkey

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 7371
  • The color of Spring...
Re: Systemd services to autostart JRiver and a VNC server
« Reply #4 on: September 14, 2017, 04:57:25 pm »

Ubuntu 17.10 is switching to gdm from lightdm.
Logged
I don't work for JRiver... I help keep the forums safe from Viagra and other sources of sketchy pharmaceuticals.

Windows 11 2023 Update (23H2) 64-bit + Ubuntu 24.04 LTS Noble Numbat 64-bit | Windows 11 2023 Update (23H2) 64-bit (Intel N305 Fanless NUC 16GB RAM/256GB NVMe SSD)
JRiver Media Center 32 (Windows + Linux) | Topping D50s DAC | Edifier R2000DB Bookshelf Speakers

tombert

  • Galactic Citizen
  • ****
  • Posts: 449
Re: Systemd services to autostart JRiver and a VNC server
« Reply #5 on: September 14, 2017, 05:33:22 pm »

Additionally the always auto-restart should be bringing MC up shortly if it doesn't succeed in loading the first time (unless you changed it to "on failure" as you described, because systemd doesn't always do a good job of distinguishing failure-based shutdowns)

I initially tried that, but my experience was that some of MC's failure modes do not successfully hook "on-failure", so I'd get crashes where MC would never respawn.  I was using this primarily on headless systems, so "always" was a safer choice.  If you want to stop MC on a system with the "always" option, there's always "systemctl stop jriver.service"

Ah! that's the reason why you had "always" in the restart option. I am somewhat too lazy to type "systemctl ..." stopping MC.
On the other hand it does not feel like a final solution if I assume it always starts 10 seconds later ...
Logged

tombert

  • Galactic Citizen
  • ****
  • Posts: 449
Re: Systemd services to autostart JRiver and a VNC server
« Reply #6 on: September 14, 2017, 05:35:23 pm »

... but if you are there is something peculiar about your install.
Of course it's always the fault of the others  :P
Logged

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5174
  • "Linux Merit Badge" Recipient
Re: Systemd services to autostart JRiver and a VNC server
« Reply #7 on: September 14, 2017, 06:06:52 pm »

Of course it's always the fault of the others  :P

To be clear, I'm not employed by JRiver, I'm just a user like you.   A systemd symlink to a service should be 100% identical to the service pointed to, and if it's not then something very strange is happening (at the systemd or POSIX level, not at the jriver level).
Logged

tombert

  • Galactic Citizen
  • ****
  • Posts: 449
Re: Systemd services to autostart JRiver and a VNC server
« Reply #8 on: September 14, 2017, 07:32:00 pm »

To be clear, I'm not employed by JRiver, I'm just a user like you.   A systemd symlink to a service should be 100% identical to the service pointed to, and if it's not then something very strange is happening (at the systemd or POSIX level, not at the jriver level).
Of course you'r right. I just wondered because doing a systemctl list-dependencies shows lightdm and not display-manager.
The reason why it now works better on my server could be the missing gravity of the sun here in Vienna (at time of writing) or simply because systemd is not bug free.
And, don't we know it all better ... how often have you already said ".... it should ..." regarding SW systems!?
Logged

Wybe

  • World Citizen
  • ***
  • Posts: 129
Re: Systemd services to autostart JRiver and a VNC server
« Reply #9 on: January 13, 2018, 05:36:47 pm »

I did a clean install of Debian Stretch 9.3 and it appears that jriver.service does not start anymore. Any ideas?
Logged

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5174
  • "Linux Merit Badge" Recipient
Re: Systemd services to autostart JRiver and a VNC server
« Reply #10 on: January 13, 2018, 08:14:34 pm »

I did a clean install of Debian Stretch 9.3 and it appears that jriver.service does not start anymore. Any ideas?

Did you enable it?  What does the journal tell you about jriver.service?
Logged

Wybe

  • World Citizen
  • ***
  • Posts: 129
Re: Systemd services to autostart JRiver and a VNC server
« Reply #11 on: January 14, 2018, 04:43:26 am »

Some extra info: I did the same install like before (when it worked): installed only the Debian 9 base system plus Standard system uitlities and then I installed only gnome-session and some applications like gedit, sudo, abiword, gnome-disk-utility etc.. Now at Debian 9.3, when I start jriver.service and I ask for the status, it returns with: no protocol specified and unable to open the X display device:0. I know that device:0 is correct. Some problem with permissions/authority?

Update: the output of: echo $DISPLAY = :0
Logged

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5174
  • "Linux Merit Badge" Recipient
Re: Systemd services to autostart JRiver and a VNC server
« Reply #12 on: January 14, 2018, 11:42:10 am »

What happens if you start JRiver manually using the normal command-line invocation?

How about if you try to start the service manually from inside gnome using systemctl start jriver.service?  How about systemctl restart jriver.service?

You don't mention whether or not you installed or enabled a display manager; if you did not do so, that is almost certainly the problem; how are you starting gnome-session and/or xorg?  Piecemealing a desktop environment in debian (as opposed to using tasksel or the installer) can lead to many surprises as many components are pre-configured to rely on other components that they expect to be installed; the fact that it worked once is no guarantee it will work again. 

This sounds like either a display manager issue or an xsession permissions issue, but we'll get to the bottom of it.
Logged

Wybe

  • World Citizen
  • ***
  • Posts: 129
Re: Systemd services to autostart JRiver and a VNC server
« Reply #13 on: January 14, 2018, 03:26:03 pm »

I did a clean install again and now it works. Not sure what went wrong. When the problem occured I was able to start mediacenter 23 /mediaserver from the command-line. If I'm not mistaken, gnome-session comes with gdm3. Thanks for your willingness to help. Much appreciated!
Logged
Pages: [1]   Go Up