Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd service to start jellyfin-mpv-shim #330

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oschwand
Copy link

@oschwand oschwand commented Mar 18, 2023

Here is a proposal for a systemd unit to manage the jellyfin-mpv-shim. I use it on a media player without keyboard access. It may be of interest for #174.

It's far from perfect:

  • it assumes an installation in ~/.local/bin, which should be the case when installed with pip{x},
  • if the Jellyfin server is not launched, it does not work because it wants to interactively create a new connection, but systemd is not noticed since the process is not killed.

I don't know how to deal properly with the first issue, but it's not really a problem.

For second one, my workaround is the following. I add a condition in order to check if my Jellyfin server is accessible

ExecCondition=bash -c "curl --fail http://jellyfin || exit 255"; echo $?

(the bashism is used to get a proper exit code for systemd). But unfortunately the URL is hard-coded...

A proper way to fix this issue would be to have a command line argument which exits the shim when the connection fails, instead of asking the user to create a new one. I will try to work on this point, but the command line processing is rather primitive for now.

@iwalton3
Copy link
Member

There is a config option to wait for a period of time before connecting. A command option to make it wait and then fail if it can't connect makes sense.

@oschwand
Copy link
Author

Indeed, connect_retry_mins is useful for this usecase.

@bgstack15
Copy link

Users can always use a systemctl edit --user jellyfin-mpv-shim.service and basically rewrite the entire ExecCondition, or perhaps you could experiment to see if the ExecCondition parses $ENVVARIABLE used like so in the .service file:

Environment=JELLYFIN_URL=http://jellyfin:8096
ExecCondition=bash -c "curl --fail ${JELLYFIN_URL} || exit 255"; echo $?

Environment is demonstrated in the man page with ExecStart, but not ExecCondition so this should be tested. And then if it works, the user can still use systemctl edit --user jellyfin-mpv-shim.service to then just add the one entry for Environment=JELLYFIN_URL=http://jellyfin:8096 and not the whole logic.

@JPVenson JPVenson added enhancement New feature or request good first issue Good for newcomers Linux Pertains only to Linux environment. labels Dec 2, 2023
@iwalton3 iwalton3 marked this pull request as draft January 21, 2024 17:48
@gudvinr
Copy link

gudvinr commented Mar 21, 2024

it assumes an installation in ~/.local/bin, which should be the case when installed with pip{x},

Not everyone uses PIP. You shouldn't assume this for unit file that could be distributed to broad audience.

Hardcoding paths is acceptable if you are both building and packaging software but for other cases just use executable name. $PATH should do the rest.

It's also worth adding

After=network-online.target

If you run jellyfin server on the same PC, it won't do anything basically, but if your server is on the network, there is no point in starting shim before network is up. ExecCondition in this case will fail too.

For exec condition, to avoid hardcoding URL something like this can be used:

cat "${XDG_CONFIG_HOME:-%h/.config}"/jellyfin-mpv-shim/cred.json | grep -o '"address": "[^"]*' | grep -o '[^"]*$'

This needs to be changed for multiple entries though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Linux Pertains only to Linux environment.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants