← Back
Editing: ajp.cpython-311.pyc
� #H\aT � �� � d Z dZdZddlZddlZddlmZmZ ddlm Z dgZ G d� dee � � Zed k rAd � Z ddlmZ ej e � � Z ee ddej � � � � � � dS dS )a� ajp - an AJP 1.3/WSGI gateway. For more information about AJP and AJP connectors for your web server, see <http://jakarta.apache.org/tomcat/connectors-doc/>. For more information about the Web Server Gateway Interface, see <http://www.python.org/peps/pep-0333.html>. Example usage: #!/usr/bin/env python import sys from myapplication import app # Assume app is your WSGI application object from ajp import WSGIServer ret = WSGIServer(app).run() sys.exit(ret and 42 or 0) See the documentation for WSGIServer for more information. About the bit of logic at the end: Upon receiving SIGHUP, the python script will exit with status code 42. This can be used by a wrapper script to determine if the python script should be re-run. When a SIGINT or SIGTERM is received, the script exits with status code 0, possibly indicating a normal exit. Example wrapper script: #!/bin/sh STATUS=42 while test $STATUS -eq 42; do python "$@" that_script_above.py STATUS=$? done Example workers.properties (for mod_jk): worker.list=foo worker.foo.port=8009 worker.foo.host=localhost worker.foo.type=ajp13 Example httpd.conf (for mod_jk): JkWorkersFile /path/to/workers.properties JkMount /* foo Note that if you mount your ajp application anywhere but the root ("/"), you SHOULD specifiy scriptName to the WSGIServer constructor. This will ensure that SCRIPT_NAME/PATH_INFO are correctly deduced. zAllan Saddi <allan@saddi.com>z $Revision$� N)� BaseAJPServer� Connection)�ThreadedServer� WSGIServerc �: � e Zd ZdZddddddej dfd�Zd� ZdS ) r a� AJP1.3/WSGI server. Runs your WSGI application as a persistant program that understands AJP1.3. Opens up a TCP socket, binds it, and then waits for forwarded requests from your webserver. Why AJP? Two good reasons are that AJP provides load-balancing and fail-over support. Personally, I just wanted something new to implement. :) Of course you will need an AJP1.3 connector for your webserver (e.g. mod_jk) - see <http://jakarta.apache.org/tomcat/connectors-doc/>. � NTF)� localhost�I c � � t j | ||||||||| �� � dD ] }|| v r| |= � t j | ft | fd�| �� dS )a� scriptName is the initial portion of the URL path that "belongs" to your application. It is used to determine PATH_INFO (which doesn't seem to be passed in). An empty scriptName means your application is mounted at the root of your virtual host. environ, which must be a dictionary, can contain any additional environment variables you want to pass to your application. bindAddress is the address to bind to, which must be a tuple of length 2. The first element is a string, which is the host name or IPv4 address of a local interface. The 2nd element is the port number. allowedServers must be None or a list of strings representing the IPv4 addresses of servers allowed to connect. None means accept connections from anywhere. loggingLevel sets the logging level of the module-level logger. )� scriptName�environ� multithreaded�multiprocess�bindAddress�allowedServers�loggingLevel�debug)�jobClass�jobArgsN)r �__init__r r )�self�applicationr r r r r r r r �kw�keys �1/usr/lib/python3/dist-packages/flup/server/ajp.pyr zWSGIServer.__init__g s� � �0 ��t�[�*4�'.�-:�,8�+6�.<�,8�%*� ,� ,� ,� ,� +� � �C��b�y�y��s�G����� &�z�D�7� &� &�"$� &� &� &� &� &� c � � | j � d| j j � � | � � � }nE# t j $ r3}| j � dt |� � � � Y d}~dS d}~ww xY wt j | |� � }| � |� � | j � d| j j | j rdpd� � |S )z� Main loop. Call this after instantiating WSGIServer. SIGHUP, SIGINT, SIGQUIT, SIGTERM cause it to cleanup and return. (If a SIGHUP is caught, this method returns True. Returns False otherwise.) z%s starting upz#Failed to bind socket (%s), exitingNFz%s shutting down%sz (reload requested)r )�logger�info� __class__�__name__�_setupSocket�socket�error�strr �run�_cleanupSocket�_hupReceived)r �sock�e�rets r r&