jellyfin-plugin-preventsleep
jellyfin-plugin-preventsleep copied to clipboard
Ubuntu/Linux version?
Any chance you can make a version for Ubuntu/Linux ? thanks I am looking into the session activity but cannot figure out how to access http://192.168.1.101:8920/Sessions when i type in url i get nothing
I could look into it, but can't make any promises - I don't have a desktop or laptop with Linux set up at the moment. If you have some basic programming experience, you're also welcome to contribute! The part that is most different to Windows would be the API calls that tell the system not to go to sleep, so any knowledge on that would also help.
I'm going off a small program I wrote seven years ago and I haven't ran Linux on the desktop in a very long time so take this with a grain of salt:
You ask something called logind (which, IIRC, replaced UPower as the program to ask) over D-Bus, an IPC mechanism, to inhibit sleep. If granted permission, you get transferred a file descriptor over D-Bus, which you close when you want the lock to be released. (Apparently, the currently-supported .NET library for D-Bus communication is https://github.com/tmds/Tmds.DBus)
As that systemd page notes, "Taking inhibitor locks is a privileged operation." If you were to ask for an inhibition, you would probably (again, I don't run Linux) get the PolicyKit agent asking you to enter the password of a privileged user. You would need to write a PolKit rule to allow inhibition requests originating from Jellyfin to go through without prompting the active user. Of course, that's not needed if someone's running Jellyfin as root, but I sincerely hope nobody is doing that.
(Desktop applications will usually ask a session manager daemon provided by their desktop environment of choice [e.g. GNOME] to inhibit sleep - this avoids the need for a password and writing Polkit rules for every application - but I don't think that's a feasible approach, most people are running Jellyfin as a daemon, not connected to a particular user's desktop session.)
I created a python script that does the job for Linux systems You need a jellyfin api token, create in the Dashboard Create a systemd timer to run the script once an hour will prevent the system from entering sleep/suspend mode
This looks like one approach to at least partially tackle the problem, and looks like @qwerty12 's afterthought. Thanks!
- I assume that this only works for some desktop environments, so gnome or kde must be running for this script to work?
- Can you comment on @qwerty12 's objection that the script must be connected to a user session? I don't have enough Linux Desktop expertise to judge that.
Definitely a hack. but works for me, thought some others could use as well. This is for ppl who use their computer/laptop for other things and run a jellyfin server... Yes the script only works for user logged into PC/Laptop. I found this googling last year to prevent screen saver when running wine games. One more thing the systemd timers/service units must be setup as --user configs There are numerous ways to to disable power-management even with no DE, but this seems the simplest way. A bit beyond my skill set learning the dbus comms at a system level. Just wanted to share for some future googler... Cheers!
I haven't quite tried your script yet as I am just testing all my software/alternatives before I swap from Windows to Linux. Having looked around and pretty much only found your script, I wonder if you really need the token.
Is it not possible just to look at the most recent jellyfin log file (or last 2 in case of split) in /var/log/jellyfin/ and find something like the "EnablePlaybackRemuxing" or "Sending ForceKeepAlive message to 1 inactive WebSockets".
Obviously it would need a little more programming to find the message in the log, look at the time of the message and check if it is within the time frame (e.g. 90s or 10mins etc.). But, I was thinking that if you can take something from the log file, I am guessing then it would not have to have a user logged in (or a token) and could run as a service/cronjob the same as the jellyfin server. It should then "wiggly" the mouse on the logon screen I guess. I am also not sure if it would work on a headless display e.g. the wiggling the mouse bit though.
Anyone tried this or wish to try it?
The solutions you suggest may very well work for you, but they are too setup-dependent to be used in a general solution (in my opinion). Detecting idle time based on the log depends on the logging settings of the user, and depending on mouse wiggling may depend on lots of factors (Jellyfin may run on a server without any GUI at all).
Nevertheless, feel free to comment if your approach works out!
Thanks @txhammer68 for your code.
I am on Linux Mint 22 wilma but could not find a package that would give me the qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity query. I kept being told that "ScreenSaver.SimulateUserActivity " was not available, or something like that.
So I installed "xdotool" and happily modified your script and it worked. I even set up system multi-user timers after a bit of a read.
However, I have the same problem as you in that when the computer boots (e.g. power outage) you get the logon screen (lightdm/slick greeter) which I have not been able to get xdotool to move the mouse on. I have tried tons of stuff but no joy. Also on Mint, the greeter screen does not have a suspend option, so unless you logon or setup autologin your pc/server will just sit powered on until you get home from holiday after the power outage.
I have an old Windows 10 server running Jellyfin and need to install Linux (thanks MS!!), so this has become a little challenge for me. I have spent the good part of two weeks searching the web, trying different stuff out and cribbing together different bits of code.
I am not the best of programmers (I'm sure someone will look at my code and go ....what), but I have come up with a little "application" (couple of scripts) that run as a root cron job. The one checks for the session and the other checks when to suspend the pc/server.
I have took on @jonschz comment of not "too setup-dependant" and have used pretty much only the Unix command set I think (e.g. not reliant on gnome/cinnamon/lightdm or GUI etc.). Not sure how well my suspend script will work on a headless device though, so it would be nice if someone could test it once uploaded.
I just need to do a little more testing and some documentation and then work out how to upload onto github and hopefully people will be happy to test.
Touch wood it will be sometime this week.
Happy Easter!!
Well, here we go with my Linux version of preventsleep
Could someone check that my first github is configured correctly and people can see and download this, and let me know please.
@jonschz I hope you don't mind, but I have pointed windows users to your github page. If it is an issue let me know and I will remove it.
@txhammer68 This may help with the logon screen issue you have using mouse movements. The logon screen will now suspend also, so you don't have to have a user logged in.
Jellyfin-Inhibit-Sleep (for Linux)
Please feel free to test, add code (e.g. ssh/vnc detection), I have puts lots of comments in the code, configured logging and testing (on/off). I will try to look at ssh and vnc when I get my server built. Feel free to raise issues if needed, I may not be able to fix them but I will have a go and try to help, other users may try to help too.
I hope people find this useful.
Thank you for uploading! I wasn't able to test it since I don't have a Linux desktop set up at the moment. Linking this repo is completely fine with me (it is a public repo after all).
I've just found this as well which is an alternative to my code if you want some choice. If I had found this first it may have saved me a couple of weeks of coding and testing. I have not tested the below, but thought I would add it here for information.
https://github.com/bulletmark/sleep-inhibitor