cjmurph / PmsService

Plex Media Server service wrapper for windows
MIT License
504 stars 57 forks source link

PMS Service Blocking WSL, Plex Post Processing #73

Open arrmo opened 1 year ago

arrmo commented 1 year ago

OK, this one is going to sound screwy, but I re-checked it today 😆.

I have been pulling my hair out for about a week, as my Plex Post Processing script (post DVR recording) would not properly call WSL (to run my script). Tried all sorts of things, and thing funny as it is, I did a Plex Server update - and that "hung" PmsService (other thread there). I stopped it, temporarily ran PMS manually ... and all of a sudden my post processing was working again! So I did this in a more controlled fashion ... and it turns out, running PMS via the PmsService is the underlying cause. If I run PMS "manually" (the application), then my WSL script is fine. But if PMS is started and controlled by PmsService, my script fails, with the following error when trying to call WSL,

T h e   f i l e   c a n n o t   b e   a c c e s s e d   b y   t h e   s y s t e m . 

Make any sense?

Thanks!

ukdtom commented 1 year ago

Unsure, but maybe wsl needs a GUI?

arrmo commented 1 year ago

Not thinking WSL does (though I may be wrong!), but perhaps PMS is not running "the same"? I did check the processes ... it seems to be running as the same user, and still 64 bit, but no tray icon (for PMS). Hmm.

cjmurph commented 1 year ago

Does your script try to access files on a mapped drive?

arrmo commented 1 year ago

I run a batch file (no mapped drives), that calls a script in WSL - that WSL script does call mapped drives. You suspect something? 😉

Thanks!

cjmurph commented 1 year ago

Yep, that'll be it. When running as a service, in session 0, drive mappings are not available. Change the path to a UNC path and it should be ok so long as the user the service is running as has the proper permissions to access the files.

arrmo commented 1 year ago

OK, oddly enough - it even breaks if I just try to run wsl --version. Would this be expected? Meaning ... it breaks even just trying to load the mounts in /etc/fstab? Not using them, just mounting.

Thanks!

cjmurph commented 1 year ago

What are the mounts? I'm no wsl expert, but it's important to remember that all this is happening in session 0 with no user session available (hence, no mapped drives)

arrmo commented 1 year ago

Yes, that makes sense - just want to make sure we're talking the same thing ... LOL. I have no (Windows) mapped drives in use, rather only mounts inside WSL.

Hmmm ... so I then tried a second distribution, with no mounts inside WSL - same issue, even just for wsl --version. OK, that's odd. I admit, I'm not sure what session 0 means quite yet ... LOL.

cjmurph commented 1 year ago

Ok, services in windows run in session 0, which is not a user session. There is no explorer instance, so no task bar etc. Many applications require things like the taskbar, mapped drives etc so can't run in session 0. Perhaps wsl falls into this category.

arrmo commented 1 year ago

I think you hit the nail on the head - thanks! Found this, https://github.com/microsoft/WSL/issues/9451

Hmmm. Not sure how to get around it though. Dang it!

arrmo commented 1 year ago

Digging, but ... is there no way to spawn / launch a shell in another session? I can see from Task Manager, that when I manually run PMS, it is in Session ID 2.

Thanks!

ukdtom commented 1 year ago

https://stackoverflow.com/questions/56628843/runas-password-in-batchfile

arrmo commented 1 year ago

Thanks! Will do some digging in PsExec. Seems to let me set / change Session ID, just need to figure out how to set the value correctly 😆. And not sure if I need to change user or not.

Appreciate it!

cjmurph commented 1 year ago

@arrmo can I ask, what is it you're actually trying to do with this action? Maybe there is another way to achieve this without using wsl.

arrmo commented 1 year ago

@arrmo can I ask, what is it you're actually trying to do with this action? Maybe there is another way to achieve this without using wsl.

Sure, NP! And yes, open to suggestions - for sure.

I'm trying to run my (Plex) Post Processing script - transcode from incoming high bit rate MPEG2VIDEO (from my cable company), to lower bit rate HEVC => save storage space ... don't need to save video at ~ 18-20 Mbps on my HDD 😆. Plex allows me to do this - it (automatically) calls a Post Processing script before adding the newly recorded item to the library. So just trying to (re) use the script I have running on Linux - and it does work in WSL, no issues at all.

Clear as mud?

arrmo commented 1 year ago

PsExec works! I just have to force / set the session id, so for example ... -i 2. It won't run in the console session though - thinking that may be an issue, as after reboot I won't be logged in. Hmmm. OK, have to noodle on that one a bit yet 😆

cjmurph commented 1 year ago

I suppose you just need to be careful to ensure you kill everything, not sure what the implications of kicking off multiple user sessions, at some point you might reach a performance problem. Surely you can do this in windows natively.

arrmo commented 1 year ago

Ya, trying to find a better way around this 😞. Still digging!

arrmo commented 1 year ago

I suppose you just need to be careful to ensure you kill everything, not sure what the implications of kicking off multiple user sessions, at some point you might reach a performance problem. Surely you can do this in windows natively.

Arrgh. You would think so. Not having any luck though, even with PsExec. Like noted above, need to spawn a bat (and then bash) script, from Session ID 0. Dang it!