{ "info": { "author": "Ross Patterson", "author_email": "me@rpatterson.net", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "==================================================\niiswsgi\n==================================================\nServing Python WSGI applications natively from IIS\n==================================================\n\nThe `iiswsgi`_ module implements a FastCGI to `WSGI`_ gateway that\nis compatible with `IIS`_'s variation of the `FastCGI protocol`_. It also\nprovides `distutils`_ commands for building, distributing and installing\n`Microsoft Web Deploy`_ (MSDeploy) packages through the `Web Platform\nInstaller`_ (WebPI).\n\n.. contents::\n\n\nQuick Start\n===========\n\nQuick Start for Users\n---------------------\n\nThe ``iiswsgi`` distribution includes two sample IIS apps which can be\ninstalled through WebPI once the custom feed has been added:\n\n#. Install and Launch `Web Platform Installer`_\n\n#. Use the search box in the upper-right to search for `Web Matrix`\n\n#. Click add next to the most recent `Web Matrix` entry, then\n `Install` in the lower-right and follow the instructions\n\n#. Open the `Options` dialog by clicking the link on the lower-right\n\n#. Under `Custom Feeds`, add the URL for latest ``*.webpi.xml`` file\n from the `iiswsgi downloads`_ and click `Add feed`\n\n#. Under `Which Web Server...?`, check `IIS Express` and then click\n `OK`\n\n#. Use the search box in the upper-right to search for `pyramid`\n\n#. Click add next to `Pyramid Application` then `Install` in the\n lower-right and follow the instructions\n\nQuick Start for Distributors\n----------------------------\n\nAssuming an existing `Python`_ distribution with a `Setup Script`_ using\n`setuptools`_ and a `WSGI`_ ``*.ini`` `Paste config file`_, roughly\nthe following steps could be used to released to WebPI:\n\n#. Install `iiswsgi`_ into the Python environment used to build releases::\n\n >C:\\Python27\\Scripts\\easy_install.exe -U iiswsgi\n\n#. Copy the following to the dist root and adjust as appropriate:\n\n * ``examples/pyramid.msdeploy/Manifest.xml.in``\n * ``examples/pyramid.msdeploy/Parameters.xml``\n * ``examples/pyramid.msdeploy/iis_install.stamp.in``\n * ``examples/pyramid.msdeploy/web.config.in``\n\n#. Add custom setup to ``setup.py``::\n\n ...\n from iiswsgi import install_msdeploy\n ...\n class install_custom_msdeploy(install_msdeploy.install_msdeploy):\n def run(self):\n \"\"\"Perform custom tasks.\"\"\"\n os.environ['WEB_CONFIG_VAR'] = 'foo'\n self.pre_install()\n CUSTOM_SETUP\n self.post_install()\n ...\n setup(\n ...\n cmdclass=dict(install_msdeploy=install_custom_msdeploy),\n ...\n\n#. Build a MSDeploy package::\n\n >C:\\Python27\\python.exe setup.py bdist_msdeploy\n\n#. Add WebPI dependencies to ``setup.py``::\n\n ...\n setup(\n ...\n extras_require=dict(install_msdeploy=['virtualenv'],\n webpi_eggs=['virtualenv', 'iiswsgi']),\n ...\n\n#. Add WebPI feed metadata to ``setup.py``:\n\n See ``examples/pyramid.msdeploy/setup.py`` for an example. \n\n#. Install the `Web Platform Installer`_:\n\n#. `Install fciv.exe`_ to generate SHA1 hashes:\n\n Must be placed on the ``%PATH%``. The recommended place would be\n ``%ProgramFiles%\\Microsoft\\Web Platform Installer`` because it's\n placed on the path when WebPI is installed.\n\n#. Build a local `WebPI feed`_::\n\n >C:\\Python27\\python.exe setup.py bdist_webpi -u \"{msdeploy_package_url}\" -m .\n\n#. Test locally:\n\n #. Launch the Web Platform Installer\n #. Click on the `options` link to the bottom right,\n #. Enter the feed URL below and click `Add Feed`:\n ``file:///C:/Users/%USERNAME%/Documents/GitHub/%DIST_NAME%/dist/%DIST_NAME%-%VERSION%-py2.7-win32.webpi.xml``\n #. Click `OK` and wait for WebPI to parse the feed\n #. Search for your dist and install\n #. Watch WebPI launch Web Matrix and open the site in a browser\n\n#. Upload/Release::\n\n >C:\\Python27\\python.exe setup.py bdist_msdeploy bdist_webpi -m . upload\n\nIf everything is working correctly, both a MSDeploy zip package and\nthe WebPI feed should be uploaded to `PyPI`_. Then you can instruct\nusers to add the feed to WebPI and they can install your package.\n\n\nHow it Works\n============\n\nReleasing a WSGI app on IIS involves several steps and moving pieces.\nSee the `Web Deploy Package Contents`_ and `IIS WSGI Tools`_ sections\nfor more technical details. Here is an overview of the process and\nthe technologies involved.\n\nA Python Distribution\n---------------------\n\nThis is a pre-requisite and is not at all specific to IIS, MSDeploy or\nWebPI, only Python. This is just a directory with a ``setup.py``\n`Setup Script`_ that defines the distribution and it's metadata and\nvery little is done differently from the standard Python `distutils`_\nand `setuptools`_ ways of doing things. IOW, wherever possible,\n`iiswsgi` tries to re-use ``setup.py`` metadata and where it needs new\nmetadata it uses `setuptools`_ `entry points`_ to add `setup kwargs`_.\n\nCustom Set Up\n-------------\n\nIf the app requires extra set up beyond just setting up a\n`virtualenv`_ and installing dependencies, this can also be\nimplemented in ``setup.py`` by subclassing the ``install_msdeploy``\n`Install MSDeploy`_ command. See the `Quick Start`_ and the `Install\nMSDeploy`_ command for more details.\n\nThe MSDeploy Package\n--------------------\n\nMicrosoft's Web Deploy Tool is what WebPI uses to install an IIS app\nand expects a `MSDeploy package`_, simple zip file with some metadata\nin it. There some `special files`_ and three ``iiswsgi`` `distutils`_\ncommands that help in defining and building a MSDeploy package. The\ncommands can also be run indiviually or run all at once by running\njust the last step which will run the others first. Running them\nindividually is useful to debug packaging problems.\n\n #. `Build MSDeploy Package`_ ``build_msdeploy`` command\n #. `Install MSDeploy`_ ``install_msdeploy`` command\n #. `Test MSDeploy`_ ``test_msdeploy`` command\n #. `Build MSDeploy Distribution`_ ``bdist_msdeploy`` command\n\nOn completion of the last command a MSDeploy zip file will be in the\n``dist`` directory just like any other dist command, such as\n``sdist``. You can also upload the package using the ``upload``\ncommand.\n\nLogging output or managing verbosity for building the package is no\ndifferent than for any other disutils/setup.py uses, output is on the\nconsole and can be redirected if you wan to capture it. See\n``>C:\\Python27\\python.exe setup.py --help`` for more details.\n\nThe WebPI Feed\n--------------\n\nThe Web Platform installer can be given additional feeds in it's\noptions dialog. This feed can define things that can be installed\nalong with their metadata including dependencies. The `bdist_webpi`_\ncommand can build this feed as another dist file, and can thus also be\nreleased using the ``upload`` command.\n\nTo test locally, use the ``bdist_webpi -u \"{msdeploy_package_url}\"``\noption to put ``file:///...`` download URLs for the MSDeploy packages\nin the feed. Then use the ``file:///...`` URL for the feed\nitself in WebPI's options dialog that is printed to the console when\nthe ``bdist_webpi`` command is run.\n\nWebPI logs information while processing the feed in the\n``%LOCALAPPDATA%\\Microsoft/Web Platform Installer/logs/webpi``\ndiretory. When debugging feed issues just look at the most recently\nmodified ``webpi#.txt`` file in that directory.\n\nMSDeploy Package Installation\n-----------------------------\n\nOnce the feed is included in WebPI, the entries can be searched for\nand installed. After installation, but before WebPI reports\ncompletion, any `runCommand` providers in the `MSDeploy Manifest`_ are\nrun which is when `iiswsgi_install.exe`_ script is invoked to find the\ninstalled app and to run distutils setup commands, `install_msdeploy`_\nand `test_msdeploy`_ by default, in that distribution. Most apps will\nwant to use the ``iiswsgi_install.exe -e`` option to setup a\nvirtualenv before running setup commands. See `MSDeploy Manifest`_\nand `install_msdeploy`_ for more details and considerations.\n\nWhile installing, WebPI and MSDeploy log output into\n``%LOCALAPPDATA%\\Microsoft/Web Platform Installer/logs/install``.\nWhen debugging installation issues just look at the ``App Title.txt``\nfile in the most recently modified date-stamped direstory within that\ndirectory. Verbosity can be controlled by adding the\n``iiswsgi_install.exe -v`` option in your `Manifest.xml`_\n`` appcmd.exe set config -section:system.webServer/fastCgi /+\"[fullPath='%SystemDrive%\\Python27\\python.exe',arguments='-u %SystemDrive%\\Python27\\Scripts\\iiswsgi-script.py -c %HOMEDRIVE%%HOMEPATH%\\Documents\\My Web Sites\\FooApp\\test.ini',maxInstances='%NUMBER_OF_PROCESSORS%',monitorChangesTo='C:\\Users\\Administrator\\Documents\\My Web Sites\\FooApp\\test.ini']\" /commit:apphost\n\nSee the `IIS FastCGI Reference`_ for\nmore details on how to configure IIS for FastCGI. Note that you\ncannot use environment variable in the `monitorChangesTo` argument,\nIIS will return an opaque 500 error.\n\nThis is also where to `Custom Set Up`_ by subclassing the\n``install_msdeploy`` `Install MSDeploy`_ command in the ``setup.py``\n`Setup Script`_ and using the distutils `cmdclass`_ kwarg to\n``setup()``. See `Quick Start`_ for a small example or\n``examples\\pyramid.msdeploy\\setup.py`` for a working example.\n\nTest MSDeploy\n-------------\n\nThe ``test_msdeploy`` distutils command uses `paster request`_ with a\n`PasteDeploy INI configuration file`_ to simulate sending a request to\nthe app. If it fails, the command fails, making this useful to run\nduring `MSDeploy Package Installation`_ to ensure the user sees an\nerror in WebPI if the app isn't working even though the rest of the\ninstall succeeded. See ``>C:\\Python27\\python.exe setup.py\ntest_msdeploy --help`` for more details.\n\n\nBuild MSDeploy Distribution\n---------------------------\n\nThe ``bdist_msdeploy`` distutils command assembles an actual MSDeploy\npackage: It starts by running the ``build_msdeploy`` `Build MSDeploy\nPackage`_ command. Then it runs the ``install_msdeploy`` `Install\nMSDeploy`_ command in case your package needs any of the results of\nthe installation process and to test the installation process.\nFinally, it creates a `MSDeploy package`_ zip file with the contents\ncontolled by the same tools that `distutils`_ provides for ``sdist``\ndistributions, including ``MANIFEST.in``.\n\nMSDeploy Install Bootstrap\n--------------------------\n\nThe ``iiswsgi_install.exe`` script bootstraps the MSDeploy package\ninstall process optionally setting up a virtualenv first. It finds\nthe correct ``APPL_PHYSICAL_PATH``, changes to that directory and\ninvokes the `Setup Script`_ with arguments.\n\nThis console script attempts to workaround the fact that WebPI and\nMSDeploy don't provide any context to the app being installed.\nSpecifically, when using the `runCommand`_ MSDeploy provider in the\n`Manifest.xml`_, the process started by ``runCommand`` has no way to\nknow which app it's being invoked for on install: not the current\nworking directory, not in an argument, nor in any environment\nvariable.\n\nAs such this script has to search for the app before calling it's\n`Setup Script`_. It uses `appcmd.exe`_ to look in virtual directories\nwhose site matches the app name and which contain a stamp file still\nin place. See ``>Scripts\\iiswsgi_install.exe --help`` for more\ndetails.\n\nBuild WebPI Feed Distribution\n-----------------------------\n\nThe ``bdist_webpi`` distutils command assembles a WebPI feed from one\nor more MSDeploy packages with dependencies. The MSDeploy packages to\ninclude are defined by passing paths to distrubutions with\n``setup.py`` files whose MSDeploy dist zip files have previously been\nbuilt in the ``--msdeploy-bdists`` command option separated by\n`shlex.split`_. The download URLs for the MSDeploy zip files is\ndetermined by expanding the ``msdeploy_url_template`` ``setup()``\nkwarg with `Python string.format()`_.\n\n\nThe global feed metadata is taken from the distribution the command is\nbeing run for. Entries are added to the feed for the distributions\nlited in the ``--msdeploy-bdists`` command option and the\n``webpi_eggs`` depdencies in `extras_require`_. The WebPI dependencies\nand related products are taken from the lists given in the\n``install_msdeploy`` and ``install_webpi`` ``setup()`` kwargs\nrespectivels. The metadata for those entries is taken from the\ncorresponding distributions. The following are additional ``setup()``\nkwargs that are used in the feed if defined for a given distrubution:\n\n * title\n * author_url\n * license_url\n * display_url\n * help_url\n * published\n * icon_url\n * screenshot_url\n * discovery_file\n \nClean WebPI Caches\n------------------\n\nThe ``clean_webpi`` distutils command clears the `WebPI caches`_ for\none or more MSDeploy package downloads and the feed itself. The\nMSDeploy packages to be cleared from the cache are taken from the same\n``--msdeploy-bdists`` command option.\n\n\nDebugging\n=========\n\nOne of the more important goals of `iiswsgi`_ is to bring some greater\ntransparency and introspection to the process of integrating with\nIIS. It's a very common experience for developers in the\nnon-Window/UNIX world that developing and even deploying on Windows is\nmuch more fragile and opaque than on any other OS. Here's some of\nwhat `iiswsgi` does to try and address that.\n\nGraceful Degredation on non-Windows\n Fist and foremost, `iiswsgi` tries to degrade gracefully when run\n on non-windows platforms. Specifically, when some executable,\n environment variable, or other Windows specific piece of the\n environment is missing, the `iiswsgi` operation will not raise an\n exception but only log an error. This allows developing and, to a\n limited extent, testing MSDeploy packages on *NIX platforms. A\n side-effect of this is that some errors may be missed when there\n is a lot of console output from one of the `distutils`_ commands\n when running *on Windows*, so check your output carefully.\n\nLogging\n Finding information about what went wrong when some part of the\n process fails can be a lot more difficult on Windows than it is on\n other platforms. See the sections of `How it Works`_ for where to\n look for log files for each part of the process.\n\n\nKnown Issues\n============\n\nFCGI Process not launching under IIS\n The sample app will deploy just fine to IISExpress/Web Matrix, but\n when switched over to full IIS, it reports that the FCGI process\n exited prematurely. Even after instrumenting the very top of the\n script with writes to a file followed by ``flush()`` and\n ``fsync()`` the file still has nothing in it. So it seems like\n IIS is never actually launching the processs. If anyone can test\n this and give some insight, it would be greatly appreciated.\n\nCan't access ``APPL_PHYSICAL_PATH`` in ``runCommand`` provider\n The current method of searching for the is far too fragile and it would\n be vastly preferable if MSDeploy or WebPI set the\n APPL_PHYSICAL_PATH environment variable for ``runCommand``.\n Anyone with a MS support contract, please submit a request about\n this.\n\n```` doesn't take effect in ``web.config``\n It should be possible to `register a FCGI application in the\n web.config`_ file but that doesn't work. Hence\n ``install_msdeploy`` works around this by reading the\n ``web.config`` and using `AppCmd.exe`_ to do the actually FCGI app\n installation. It would be much better if ``web.config`` worked as\n it should. Anyone with a MS support contract, please submit a\n request about this.\n\n``System.IO.FileNotFoundException: Could not find file '\\\\?\\C:\\...``\n I've run into this error on Windows 7 on two different machines\n and multiple installs, one OEM and one vanilla Windows 7 Extreme.\n When this happens, it seems to happen when the \"Web Platform\n Installer\" has been run, then exited, and then run again without\n rebooting the machine in between. To workaround this, you may\n have to reboot the machine. See the stack overflow question `MS\n WebPI package runCommand not working in Manifest.xml`_ for more\n information. As such, it's not advisable to exit and re-launch\n WebPI. As such, the best way to get feed changes to take effect\n in WebPI may be to:\n\n #. Click on the `options` link in the bottom right of WebPI\n #. Click the `X` next to your feed to remove it\n #. Click `OK` and wait for WebPI to finish updating the remaining feeds\n #. Run `iiswsgi_webpi.exe`\n #. Click on the `options` link again in WebPI\n #. Enter the feed URL and click `Add Feed` to restore the feed\n #. Click `OK` and wait for WebPI again\n\n Now your feed changes should be reflected in WebPI.\n\n``System.IO.FileNotFoundException: Could not load file or assembly``\n This error happens when using WebPI to install on full IIS, IOW\n when not using IIS Express and Web Matrix. It can be worked\n around by installing the \"Web Deploy Tool\" in WebPI. The\n `bdist_webpi`_ command works around this by adding it as a\n dependency for all MSDeploy packages. Here's the error from the\n logs::\n\n DownloadManager Error: 0 : System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Deployment, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.\n File name: 'Microsoft.Web.Deployment, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\n at Microsoft.Web.PlatformInstaller.MSDeployProxy.GetDeclaredParameters()\n at Microsoft.Web.PlatformInstaller.MSDeployPackage.get_DeclaredParameters()\n at Microsoft.Web.PlatformInstaller.UI.AppSitePage.GetApplicationName(MSDeployPackage package, String& appName)\n at Microsoft.Web.PlatformInstaller.UI.AppSitePage.InitializeComponent()\n\n``retrieving the com class factory for remote component CLSID 2b72133b-3f5b-4602-8952-803546CE3344 error 80040154``\n This error happens when using WebPI to install on full IIS, IOW\n when not using IIS Express and Web Matrix. It can be worked\n around by installing the \"IIS Management Console\" in WebPI\n dependency\n\nWebPI Errors May be Burried\n On occasion, WebPI may burry error messages behind the WebPI\n window. So if WebPI has been hung for a long time, try using\n ``Alt-TAB`` to see if there's an error window hidden behind the\n WebPI window.\n\nWebPI getting cached feeds and MSDeploy packages\n Despite the `clean_webpi`_ helper and manually clearing all the\n caches under ``%LOCALAPPDATA%\\Microsoft/Web Platform Installer``,\n there have been several times when WebPI has still gotten stale\n content causing validation errors against the SHA1 in the feed and\n other problems. When this happens, a workaround may be to\n download the stale WebPI resources in IE.\n\n\n.. _`special files`: `Web Deploy Package Contents`_\n.. _`bdist_webpi`: `Build WebPI Feed Distribution`_\n.. _`clean_webpi`: `Clean WebPI Caches`_\n.. _`iiswsgi_install.exe`: `MSDeploy Install Bootstrap`_\n.. _`install_msdeploy`: `Install MSDeploy`_\n.. _`test_msdeploy`: `Test MSDeploy`_\n.. _`egg:iiswsgi#iis`: `iiswsgi FCGI Gateway`_\n.. _`build_msdeploy`: `Build MSDeploy Package`_\n.. _`web.config.in`: `IIS Web Config`_\n\n.. _`iiswsgi downloads`: https://github.com/rpatterson/iiswsgi/downloads\n\n.. _`Python`: http://python.org\n.. _`os.environ`: http://docs.python.org/2/library/os.html#os.environ\n.. _`shlex.split`: http://docs.python.org/2/library/shlex.html#shlex.split\n.. _`distutils`: http://docs.python.org/distutils/\n.. _`setup.cfg`: http://docs.python.org/distutils/configfile.html\n.. _`cmdclass`: http://docs.python.org/distutils/extending.html#integrating-new-commands\n.. _`Python string.format()`: http://docs.python.org/2/library/string.html#formatstrings\n.. _`PyPI`: http://pypi.python.org/pypi\n.. _`setuptools`: http://packages.python.org/distribute\n.. _`entry points`: http://packages.python.org/distribute/setuptools.html#entry-points\n.. _`setup kwargs`: http://packages.python.org/distribute/setuptools.html#adding-setup-arguments\n.. _`extras_require`: http://packages.python.org/distribute/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies\n.. _`MANIFEST.in`: http://docs.python.org/distutils/sourcedist.html#the-manifest-in-template\n.. _`WSGI`: http://wsgi.readthedocs.org/en/latest/\n.. _`Paste config file`: http://pythonpaste.org/deploy/#config-format\n.. _`PasteDeploy INI configuration file`: http://pythonpaste.org/deploy/index.html?highlight=loadapp#introduction\n.. _`PasteScript`: http://pythonpaste.org/script/#paster-serve\n.. _`paster`: `PasteScript`_\n.. _`paster serve`: `PasteScript`_\n.. _`paster request`: http://pythonpaste.org/modules/request.html\n.. _`app_factory entry point`: http://pythonpaste.org/deploy/#paste-app-factory\n.. _`paste.server_runner`: http://pythonpaste.org/deploy/#paste-server-runner\n.. _`paste.server_factory`: http://pythonpaste.org/deploy/#paste-server-factory\n.. _`flup's WSGI to FCGI gateway`: http://trac.saddi.com/flup/wiki/FlupServers\n.. _`virtualenv`: http://www.virtualenv.org\n\n.. _`IIS`: http://www.iis.net\n.. _`Microsoft Web Deploy`: http://www.iis.net/downloads/microsoft/web-deploy\n.. _`Web Platform Installer`: http://www.microsoft.com/web/downloads/platform.aspx\n.. _`WebPI feed`: http://technet.microsoft.com/en-us/library/ee424348(v=ws.10).aspx\n.. _`WebPI caches`: http://www.iis.net/learn/troubleshoot/web-platform-installer-issues/troubleshooting-problems-with-microsoft-web-platform-installer\n.. _`Install fciv.exe`: http://support.microsoft.com/kb/841290\n.. _`Web Deploy manifest`: http://www.iis.net/learn/develop/windows-web-application-gallery/reference-for-the-web-application-package\n.. _`Manifest.xml`: `Web Deploy manifest`_\n.. _`Parameters.xml`: `Web Deploy manifest`_\n.. _`MSDeploy package`: `Web Deploy manifest`_\n.. _`runCommand`: http://technet.microsoft.com/en-us/library/ee619740(v=ws.10).aspx\n.. _`runcommand option attributes`: `runCommand`_\n.. _`IIS site configuration file`: http://technet.microsoft.com/en-us/library/cc754617(v=ws.10).aspx\n.. _`web.config`: `IIS site configuration file`_\n.. _`fastCgi`: http://www.iis.net/configreference/system.webserver/fastcgi\n.. _`