INTERACT FORUM
More => Old Versions => JRiver Media Center 22 for Linux => Topic started by: mwillems on January 19, 2017, 10:54:31 am
-
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:
[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
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:
[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:
x11vnc -storepasswd your_password ~/.vnc/passwd
Once you've got the services in place you can set them to start on boot by typing
sudo systemctl enable jriver.service
and/or
sudo systemctl enable x11vnc.service
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.
-
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.
-
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.
-
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:
KillMode=process
KillSignal=SIGHUP
The full jriver.service file is now:
[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
Looking at /var/log/daemon.log after I type service jriver stop, I see:
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.
-
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:
KillMode=process
KillSignal=SIGHUP
The full jriver.service file is now:
[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
Looking at /var/log/daemon.log after I type service jriver stop, I see:
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.
That looks good and hopefully it waits until MC ends if it's executed during the system shutdown and reboot processes.
-
It's hard to convince systemd to wait indefinitely, but you can specify a timeout with:
TimeoutStopSec=45
Adding that with Killsignal set to SIGHUP waits for JRiver to finish or for 45 seconds whichever comes first. I tested on a VM, with just the kill signal but no timeout, the shutdown is instantaneous; with the timeout it waits about five or six seconds, at which point a log message shows jriver closing and the shutdown finishes (a half second later).
You don't need the killmode. I'll add the extra lines to the service in the top post.
-
It's hard to convince systemd to wait indefinitely, but you can specify a timeout with:
TimeoutStopSec=45
Adding that with Killsignal set to SIGHUP waits for JRiver to finish or for 45 seconds whichever comes first. I tested on a VM, with just the kill signal but no timeout, the shutdown is instantaneous; with the timeout it waits about five or six seconds, at which point a log message shows jriver closing and the shutdown finishes (a half second later).
You don't need the killmode. I'll add the extra lines to the service in the top post.
Minor point -- the timeout shouldn't be necessary. If not provided, it defaults to DefaultTimeoutStopSec which is 90s (https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html# and https://www.freedesktop.org/software/systemd/man/systemd.service.html, and see the file /etc/systemd/system.conf on your system). The log file snippet above shows a 7 second delay between systemd issuing the signal and detecting that MC has exited, which is about what it felt like at the command line.
-
Minor point -- the timeout shouldn't be necessary. If not provided, it defaults to DefaultTimeoutStopSec which is 90s (https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html# and https://www.freedesktop.org/software/systemd/man/systemd.service.html, and see the file /etc/systemd/system.conf on your system). The log file snippet above shows a 7 second delay between systemd issuing the signal and detecting that MC has exited, which is about what it felt like at the command line.
That's what is supposed to happen, but is not actually happening on the systems I tested. It may be a bug, but without the timeout systemd just shuts on down on my testbeds. It may also be distro-specific changes to defaults (I'm testing on the debian stretch release candidate), or (as happens occasionally with systemd) there may have been undocumented changes.
In any case, if one configuration needs it others may ;D
-
@mwillems
Just FYI, the "TimeoutStopSec" entry in jriver.service in the first post is missing the "t" (TimeouStopSec).
-
Good catch! Thanks.