In this guide:
As of right now, this server handles processing of handbrake scripts.
This guide assumes the following:
- This guide uses python 3.6.5, windows server 2016 and IIS 10
- Make sure you have virturalenv installed.
git clone https://github.com/dgaiero/firelight-utilities.git
cd server
python -m venv script_server
script_server/Scripts/activate
- All work should be done in the virtural environment.- pip install -r requirements.txt
The script server uses celery to make asynchronous calls alowing commands to be run in the background and the webpage to be closed. This also deals with timeout issues. To setup the distributed task queue handler, you must install celery and RabbitMq.
To install celery, run pip install celery=3.1.24
. Please note, celery > v4 does not support windows. Once celery is installed, you must also install RabbitMq. Rabbit Mq handles message brokering. To install RabbitMq, visit https://www.rabbitmq.com/. RabbitMq has a dependicy of Erlang, available from: https://www.erlang.org/.
IIS must be configured to run a wsgi application.
First, pip install wfastcgi
. This allows the cgi application to be handled by IIS. Wfastcgi is maintained by Microsoft.
After wfastcgi
is installed, make sure to run wfastcgi-enable
.
Follow the below steps to configure a new IIS site.
- In IIS, under the server, select FastCGI Settings
- Right click on the setting that was created from the
wfastcgi-enable
command. SelectEdit
- Click on
Environmental Variables
. - Make sure there are two enviromental variables:
-
Name Value PYTHONPATH Location to server directory (the one with server.py
)WSGI_HANDLER app.app
-
- Right click on the setting that was created from the
- Make a new site, none of the settings matter.
- Click on
Handler Mappings
in the new site settings.- Click
Add Module Mapping
.-
Settings Value Request Path * Module FastCgiModule Executable (Location to Python in venv)|(Location to wsgi in venv)
Example:C:\Admin_Utilities\adminScripts\firelight-utilities\server\script_server\Scripts\python.exe|C:\Admin_Utilities\adminScripts\firelight-utilities\server\script_server\Lib\site-packages\wfastcgi.py
Name Doesn't matter
-
- Click
- Click on
Application Settings
in the new site settings.-
Settings Value PYTHONPATH Location to server directory (the one with server.py
)WSGI_HANDLER app.app
WSGI_RESTART_FILE_REGEX .*((\.py)|(\.config))$
-
- Click on
- Make sure whatever account is being used to authenticate the website has
RWX
access to all directories necessary (server directory, all directories specified in handbrake_utilsettings.ini
, etc.). Also, make sure theDOMAIN\IIS_ISURS
and.\ISUR
has the same access.
A Sample web.config
file is shown below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="PYTHONPATH" value="C:\Admin_Utilities\adminScripts\firelight-utilities\server" />
<add key="WSGI_HANDLER" value="server.app" />
<add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpErrors errorMode="Custom" />
<handlers>
<add name="Script Server Python FastCgi Handler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Admin_Utilities\adminScripts\firelight-utilities\server\script_server\Scripts\python.exe|C:\Admin_Utilities\adminScripts\firelight-utilities\server\script_server\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
</handlers>
</system.webServer>
</configuration>
- Celery needs to be started in dameon mode. The
service_worker.bat
activates thevirturalenv
and then startscelery
to listen to incomming requests. You may install this however you wish, but one method is to use task scheduler to automatically start the task at startup.