PlexConnect as Windows Service

EDIT: Full instructions for PlexConnect as a windows service can now be found on this wiki page.

 

Hey Guys,

 

For those that haven't seen this yet, It works really well! nice work to those involved :rolleyes:

 

If you grab the latest git and install pywin32 you can run PlexConnect as a service on windows

startup.

 

i'm just using the Task Scheduler to grab the latest git and then start the service (i assume this is the best way?)

 

start-plexconnect.bat

C:
cd \plexconnect
git pull
python PlexConnect_Winservice.py start

Cheers Rob.

While testing, I still see issues like ATVSettings.cfg not being saved at shutdown...

Not sure, why that happens (or not...).

Ahh I see, perhaps when it saves incrementally that won’t be such an issue.


Would you need to stop the service manually on a shutdown/reboot to save settings otherwise?

Well, that's the thing. With manual stop/start the file is updated correctly. I don't know what Windows does differently, when the service is stopped caused by a shutdown...

The goal is, to NOT have the need to do it manually.

How do you uninstall the service?

Hey Roidy,

There is a batch file included on the git for install/start/stop/uninstall

(support/win/uninstall.bat) is the one you are after....

@echo off
set InstallerPath=%~dp0
set PlexConnectPath=%InstallerPath%..\..\
python %PlexConnectPath%PlexConnect_WinService.py remove
echo PlexConnect-Service removed

 

Ok, I'm not using the batch files and I assumed it would be:- 

python PlexConnect_Winservice.py uninstall

That'll teach me to read the file notes :D
 

this does not work on win 8.1…


edit: after removing the beginning ‘python’ on all 4 bat files, it works fine…

weird how python wasnt recognized, even though its installed…


fyi…creating a shortcut to PlexConnect.py & placing this in startup folder/run minimized, also works…

this is how i was starting plexconnect until now…thanks for that :slight_smile:

Python is found by either the file type (.py) or the first line within PlexConnect.py (#!/usr/bin/env python).

Do you know, why it won't work on your machine? What happens when typing "python" in a cmd window?

He probably doesn’t have python added to his path Environment Variables, but does have the .py file association.

Microsoft Windows [Version 6.3.9600]

© 2013 Microsoft Corporation. All rights reserved.


C:\WINDOWS\system32>python

‘python’ is not recognized as an internal or external command,

operable program or batch file.


C:\WINDOWS\system32>


if i remove ‘python’ it works…i dont need python in front of the command below…


%PlexConnectPath%PlexConnect_WinService.py install

Open any windows explorer and right click on “Computer” in the left hand side of explorer. Select “Properties” from the menu. This will bring up the system information windows, on the left hand side press “Advanced system settings”. This should launch a windows with the “Advanced” tab already selected, at the bottom press the “Enviroment Variables” button. At the bottom of the next windows is a scroll list called “System Variables”, scroll down the list to find the entry called “Path”, click to highlight it, press “Edit”. DO NOT DELETE THE CONTENT OF “Variable Value” instead add the following to the end:-

;c:\Python27;

Replacing the above path with where ever you installed python. “OK” out of all the dialogs and reboot your computer. Try running python again from a command prompt.

Or just edit python out of all the batch files :slight_smile:

Question - the filetype settings (i.e. which executable to launch for a given file) are user dependent, right?

When does the "service" start running, with windows starting up (that's how it should work...) - or later, when logging in?

-> I think the filetype dependency wouldn't fly in that case...

The PATH to python however should be a system-wide setting.

I might be wrong, only "play" with windows, when I really have to - mostly during day job hours, those long ones. :-)

Well, that's the thing. With manual stop/start the file is updated correctly. I don't know what Windows does differently, when the service is stopped caused by a shutdown...

The goal is, to NOT have the need to do it manually.

We had a recent bugfix in this area:
fix broken shutdown - missed return value from run()

Can anybody verify that this helps the Service shutdown as well?

I made a small change the the installation script below - address' the python not found issue...  

@echo off

set InstallerPath=%~dp0
set PlexConnectPath=%InstallerPath%…
if “%PROCESSOR_ARCHITECTURE%”==“AMD64” goto x64
Set PythonPath=C:\Program Files\Python27
goto install
:x64
Set PythonPath=C:\Program Files (x86)\Python27
goto install

:install
“%PythonPath%python” “%PlexConnectPath%PlexConnect_WinService.py” install
cls
echo PlexConnect-Service installed!
pause

Hope this helps people out...

Baa you are welcome to include this in future updates if you like.

Also if you want to detect if running on a Windows DC that has DNS running and want to disable DNS service so that PlexConnect runs correctly....

@echo off
cls
sc query "DNS" | find "RUNNING" >1
if "%ERRORLEVEL%"=="0" (
    sc stop DNS
	sc config DNS start=disabled
	echo DNS is now stopped and disabled!
) else (
    echo DNS is not running.
) 

this one needs elevated privileges to run correctly.

>>PythonPath

How high is the risk the your two directories won't fit the bill? My opinion: very high. I don't think that we should set environment variables that we have no background in defining...

Good that you already fixed the IF-else-stucture. :-)

>>DNS

I don't think other will be happy with that. In the end you cancel out their main DNS, leaving them somewhat alone, even killing the chance that a reboot might fix things.

This stuff doesn't seem to work in my win7 environment:

set InstallerPath=%~dp0
set PlexConnectPath=%InstallerPath%..\..\
C:\Program Files (x86)\PlexConnect\support\Win>stop.bat
python: can't open file 'C:\Program': [Errno 2] No such file or directory

edit I think the path should be enclosed in quotes; then it works

python "%PlexConnectPath%PlexConnect_WinService.py" stop

>>PythonPath
How high is the risk the your two directories won't fit the bill? My opinion: very high. I don't think that we should set environment variables that we have no background in defining...
Good that you already fixed the IF-else-stucture. :-)

>>DNS
I don't think other will be happy with that. In the end you cancel out their main DNS, leaving them somewhat alone, even killing the chance that a reboot might fix things.


Fair enough. Just trying to offer some further help for other that may have had the same problem as me...

And of course in regards to the DNS changes - you don't have to run it or you can modify it to not disable the DNS.

I will shut up now.


Sent from my iPad using Tapatalk

>>I will shut up now.

Oh no, wrong decision. :-)

You can have your free speech, I didn't want to shoot down your creativity and/or opinion.

I just think, those issues I wrote about need at least some thoughts/discussion...

>>I think the path should be enclosed in quotes; then it works

Ok, I will change that on github. Always the same, stumbling over this "late to the game" change of handling SPACEs in path/file names.