More > JRiver Media Center 22 for Linux

Systemd services to autostart JRiver and a VNC server

(1/2) > >>

mwillems:
So I've been working on automating more of my JRiver config (more to come on this in the next version of the pi isntall guide), but in the meanwhile I thought I'd put some useful config files here for everyone's reference

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: ---  [Unit]
     Description=JRiver
     After=display-manager.service

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

  [Install]
     WantedBy=graphical.target

--- End code ---

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: ---[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

--- End code ---

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: ---x11vnc -storepasswd your_password ~/.vnc/passwd

--- End code ---

Once you've got the services in place you can set them to start on boot by typing

--- Code: ---sudo systemctl enable jriver.service

--- End code ---
and/or

--- Code: ---sudo systemctl enable x11vnc.service

--- End code ---

As noted above, at some point I'm going to overhaul the pi startup instructions to incorporate these (and to add more scripting to automate it), but I thought these might be of general interest in the meanwhile.

mk9pa:
Excellent guide.  I was just looking for this tonight, and you posted it 2 days ago.  Good timing.


I implemented your directions on my RPi3 setup and it works perfectly.

bob:
It would be nice to have it handle shutdown as well if that's possible.

If you send MC a HUP signal it will initiate a clean shutdown which includes notifying all DLNA devices that it's going down as well as unsubscribing from events and closing all open files. You need to wait until MC finishes it's shutdown before continuing. This can take up to 30 seconds on a network with a ton of DLNA devices.

In init on the Id I just wait until the mediacenter22 process ends.

mk9pa:
Hi Bob / MWillems,


I added the following two lines to the [Service] stanza of MWillem's jriver.service file and it seems to have done the trick:



--- Code: ---  KillMode=process
  KillSignal=SIGHUP
--- End code ---

The full jriver.service file is now:


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


[Service]
  Type=simple
  Environment=DISPLAY=:0
  User=pi
  ExecStart=/usr/bin/mediacenter22 /MediaServer
  Restart=always
  RestartSec=10
  KillMode=process
  KillSignal=SIGHUP


[Install]
  WantedBy=graphical.target
--- End code ---


Looking at /var/log/daemon.log after I type service jriver stop, I see:

--- Code: ---Jan 30 13:46:48 audiopi systemd[1]: Stopping JRiver...
Jan 30 13:46:48 audiopi mediacenter22[9644]: Received a hangup, exiting!
Jan 30 13:46:55 audiopi systemd[1]: Stopped JRiver.
--- End code ---

bob:

--- Quote from: mk9pa on January 30, 2017, 03:54:31 pm ---Hi Bob / MWillems,


I added the following two lines to the [Service] stanza of MWillem's jriver.service file and it seems to have done the trick:



--- Code: ---  KillMode=process
  KillSignal=SIGHUP
--- End code ---

The full jriver.service file is now:


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


[Service]
  Type=simple
  Environment=DISPLAY=:0
  User=pi
  ExecStart=/usr/bin/mediacenter22 /MediaServer
  Restart=always
  RestartSec=10
  KillMode=process
  KillSignal=SIGHUP


[Install]
  WantedBy=graphical.target
--- End code ---


Looking at /var/log/daemon.log after I type service jriver stop, I see:

--- Code: ---Jan 30 13:46:48 audiopi systemd[1]: Stopping JRiver...
Jan 30 13:46:48 audiopi mediacenter22[9644]: Received a hangup, exiting!
Jan 30 13:46:55 audiopi systemd[1]: Stopped JRiver.
--- End code ---

--- End quote ---

That looks good and hopefully it waits until MC ends if it's executed during the system shutdown and reboot processes.

Navigation

[0] Message Index

[#] Next page

Go to full version