@@ -376,8 +376,9 @@ There are multiple web interfaces to choose from:
3763762. `cgi-bin for limited-access hosting`_
3773773. `stand-alone web server`_
3783784. `Zope product - ZRoundup`_
379- 5. `WSGI handler`_ (to be written ` Apache HTTP Server with mod_wsgi`_)
379+ 5. `Apache HTTP Server with mod_wsgi`_
3803806. `Apache HTTP Server with mod_python`_ (deprecated)
381+ 7. `WSGI Variations`_
381382
382383You may need to give the web server user permission to access the tracker home
383384- see the `UNIX environment steps`_ for information. You may also need to
@@ -508,11 +509,157 @@ that interfaces to your new tracker.
508509Apache HTTP Server with mod_wsgi
509510~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
510511
511- This needs to be developed by somebody. See:
512- https://issues.roundup-tracker.org/issue2550566 to see if there has
513- been something developed.
514-
515- See the main web site for `mod_wsgi`_.
512+ This is a work in progress thanks to Garth Jensen.
513+
514+ See the main web site for `mod_wsgi`_ whcih include directions for
515+ using mod_wsgi-express which is easier if you are not used to apache
516+ configuration. Also there is the
517+ `main mod_wsgi <https://modwsgi.readthedocs.io/en/develop/>`_ for more
518+ detailed directions.
519+
520+ Background
521+ ^^^^^^^^^^
522+
523+ These notes were developed on a Microsoft Azure VM running Ubuntu
524+ 18.04 LTS. The instructions below assume:
525+
526+ - python and roundup are already installed
527+ - roundup is running in the system python instance (e.g. no virtual
528+ environment)
529+ - the tracker ``mytracker`` is installed in the ``trackers`` folder of
530+ home directory of a user called ``admin``. Thus, the absolute path to
531+ the tracker home directory is ``/home/admin/trackers/mytracker``.
532+ - the server has a static public IP address of 11.11.11.101
533+
534+ Install mod-wsgi
535+ ^^^^^^^^^^^^^^^^
536+
537+ You can install/build it using the python package manager pip, or
538+ install using the OS package manager (apt).
539+
540+ Pip install of mod_wsgi
541+ '''''''''''''''''''''''
542+
543+ This is the tested method, and offers an easier path to get started,
544+ but it does mean that you will need to keep up to date with any
545+ security or other issues. If you use the packages supplied by your OS
546+ vendor, you may get more timely updates and notifications.
547+
548+ The mod_wsgi docs talk about two installation methods: (1) the
549+ so-called CMMI method or (2) with pip. The pip method also provides an
550+ admin script called ``mod_wsgi-express`` that can start up a
551+ standalone instance of Apache directly from the command line with an
552+ auto generated configuration. These instructions follow the pip
553+ method.
554+
555+
556+ 1. The `mod_wsgi`_ PyPi page lists prerequisites for various types of
557+ systems. For Ubuntu, they are apache2 and apache2-dev. To see
558+ installed apache packages, you can use ``dpkg -l | grep apache``.
559+ If apache2 or apache2-dev are not installed, they install them with:
560+ - ``sudo apt update``
561+ - ``sudo apt install apache2 apache2-dev``
562+ 2. If ``pip`` is not already installed, install it with
563+ ``sudo apt install python-pip``
564+
565+ If you are using python 3, use ``sudo apt-install python3-pip`` and
566+ change references to pip in the directions to pip3.
567+ 3. ``sudo pip install mod_wsgi``. In my case, I got warnings about
568+ the user not owning directories, but it said it completed
569+ "successfully."
570+ 4. For testing, open port 8000 for TCP on the server. For an Azure VM,
571+ this is done with Azure Portal under ``Networking`` > ``Add inbound port``
572+ rule.
573+ 5. Test with ``mod_wsgi-express start-server``. This should serve
574+ up content on localhost port 8000. You can then direct a browser on
575+ the server itself to http://localhost:8000/ or on another machine at
576+ the server's domain name or ip address followed by colon then 8000
577+ (e.g. http://11.11.11.101:8000/). If successful, you should see a
578+ Malt Whiskey image.
579+
580+ Package manager install of mod_wsgi
581+ '''''''''''''''''''''''''''''''''''
582+
583+ On debian (which should work for Ubuntu), install apache2 with
584+ libapache2-mod-wsgi:
585+
586+ - ``sudo apt update``
587+ - ``sudo apt install apache2 libapache2-mod-wsgi``
588+
589+ this is the less tested method for installing mod_wsgi and may not
590+ install mod_wsgi-express, which is used below. However there is an
591+ example apache config included as part of `WSGI Variations`_ that can
592+ be used to hand craft an apache config.
593+
594+ You should make sure that the version you install is 3.5 or newer due
595+ to security issues in older releases.
596+
597+ Configure web interface via wsgi_handler
598+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
599+
600+ 1. In the tracker's home directory create a ``wsgi.py`` file with the
601+ following content (substituting ``/home/admin/trackers/mytracker``
602+ with the absolute path for your tracker's home directory):
603+
604+ .. code:: python
605+
606+ from roundup.cgi.wsgi_handler import RequestDispatcher
607+ tracker_home = '/home/admin/trackers/mytracker'
608+ application = RequestDispatcher(tracker_home)
609+
610+ To run the tracker on Port 8000 as a foreground process
611+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
612+
613+ 1. Change the ``tracker.web`` url in ``config.ini`` to port 8000 at the
614+ server domain name or ip address (e.g. http://11.11.11.101:8000/).
615+ 2. Open port 8000 for TCP on the server if you didn't already do so.
616+ 3. ``cd`` to your tracker home directory, then run
617+ ``mod_wsgi-express start-server wsgi.py``.
618+ 4. Test by directing a browser on another machine to the url you set
619+ ``tracker.web`` to in ``config.ini``.
620+
621+ Run tracker as background daemon
622+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
623+
624+ To run the tracker on Port 80 or as a background process, you'll need
625+ to configure a UNIX group with appropriate privileges as described in
626+ `UNIX environment steps`_. These steps are summarized here:
627+
628+ 1. To add a group named "mytrackergrp" run: ``sudo groupadd mytrackergrp``.
629+ 2. Add the owner of the tracker home (admin in this example) run:
630+ ``sudo usermod -a -G mytrackergrp admin``
631+ 3. Add user that runs Apache (the default on Ubuntu is www-data) run:
632+ ``sudo usermod -a -G mytrackergrp www-data``
633+ 4. Add user mail service runs as (e.g. daemon) run:
634+ ``sudo usermod -a -G mytrackergrp daemon``
635+ 5. Change group of the database in the tracker folder run:
636+ ``sudo chgrp -R mytrackergrp ~/trackers/mytracker``.
637+ 6. Make sure group can write to the database, and any new files created
638+ in the database will be owned by the group run:
639+ ``sudo chmod -R g+sw ~/trackers/mytracker/db``
640+
641+ To run mod_wsgi on PORT 80
642+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
643+
644+ 1. Change the ``tracker.web`` url in ``config.ini`` to the server url
645+ with no port designator. E.g. http://11.11.11.101.
646+ 2. Open port 80 on the server for TCP traffic if it isn't open already.
647+ 3. Stop the system instance of Apache to make sure it isn't holding on
648+ to port 80 run: ``sudo service apache2 stop``.
649+
650+ To run as a foreground process
651+ ''''''''''''''''''''''''''''''
652+
653+ 1. From the tracker home directory, run
654+ ``sudo mod_wsgi-express start-server wsgi.py --port 80 --user admin --group mytrackergrp``
655+
656+ To run as a background process
657+ ''''''''''''''''''''''''''''''
658+
659+ 1. From the tracker home directory, bash
660+ ``sudo mod_wsgi-express setup-server wsgi.py --port=80 --user admin --group mytrackergrp --server-root=/etc/mod_wsgi-express-80``
661+ 2. Then, run ``sudo /etc/mod_wsgi-express-80/apachectl start``
662+ 3. To stop, run ``sudo /etc/mod_wsgi-express-80/apachectl stop``
516663
517664Apache HTTP Server with mod_python
518665~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -647,25 +794,107 @@ The URL for accessing these trackers then become:
647794Note that in order to use https connections you must set up Apache for secure
648795serving with SSL.
649796
650- WSGI Handler
651- ~~~~~~~~~~~~
797+ WSGI Variations
798+ ~~~~~~~~~~~~~~~
652799
653- The WSGI handler is quite simple. The following sample code shows how
654- to use it::
800+ This method from Thomas Arendsen Hein goes into a bit more detail and
801+ is designed to allow you to run multiple roundup trackers each under
802+ their own user.
655803
656- from wsgiref.simple_server import make_server
804+ The tracker instances are read-only to the tracker user and located
805+ under /srv/roundup/. The (writable) data files are stored in the home
806+ directory of the user running the tracker.
657807
658- # obtain the WSGI request dispatcher
659- from roundup.cgi.wsgi_handler import RequestDispatcher
660- tracker_home = 'demo'
661- app = RequestDispatcher(tracker_home)
808+ To install roundup, download and unpack a distribution tarball and run
809+ the following as user "roundup"::
810+
811+ python setup.py build_doc
812+ python setup.py sdist --manifest-only
813+ python setup.py install --home="/home/roundup/install" --force
814+
815+ Create a user roundup-foo, group roundup-foo to run the tracker. Add
816+ the following apache config to
817+ /etc/apache2/sites-available/roundup-foo (under debian/Ubunutu, modify
818+ as needed):
819+
820+ .. code:: xml
821+
822+ 823+ ErrorLog /var/log/apache2/error.log
824+
825+ LogLevel notice
826+
827+ DocumentRoot /var/www/
828+
829+ <VirtualHost *:80>
830+ CustomLog /var/log/apache2/access.log vhost_combined
831+
832+ # allow access to roundup docs
833+ Alias /doc/ /home/roundup/install/share/doc/roundup/html/
834+
835+ # make apache serve static assets like css rather than
836+ # having roundup serve the files
837+ Alias /foo/@@file/ /srv/roundup/foo/html/
838+
839+ # make /foo into /foo/
840+ RedirectMatch permanent ^/(foo)$ /$1/
841+
842+ # start a wsgi daemon process running as user roundup-foo
843+ # in group roundup-foo. This also changes directory to
844+ # ~roundup-foo before it starts roundup.wsgi.
845+ WSGIDaemonProcess roundup-foo display-name=roundup-foo user=roundup-foo group=roundup-foo threads=25
846+
847+ # make tracker available at /foo and tie it into the
848+ # wsgi script below.
849+ WSGIScriptAlias /foo /srv/roundup/foo/roundup.wsgi
850+ <Location /foo>
851+ WSGIProcessGroup roundup-foo
852+ </Location>
853+ </VirtualHost>
854+
855+ The directory ~roundup-foo should have:
856+
857+ * a ``db`` subdirectory where messages and files will be stored
858+ * a symbolic link called ``instance`` to /srv/roundup/foo which has
859+ been initialized using ``roundup-admin``.
860+
861+ The `Apache HTTP Server with mod_wsgi`_ section above has a simple
862+ WSGI handler. This is a enhanced version to be put into
863+ ``/srv/roundup/foo/roundup.wsgi``.
864+
865+ .. code:: python
866+
867+ import sys, os
868+ sys.stdout = sys.stderr
869+
870+ enabled = True
871+
872+ if enabled:
873+ # Add the directory with the roundup installation
874+ # subdirectory to the python path.
875+ sys.path.insert(0, '/home/roundup/install/lib/python')
662876
663- httpd = make_server('', 8917, app)
664- httpd.serve_forever()
877+ # obtain the WSGI request dispatcher
878+ from roundup.cgi.wsgi_handler import RequestDispatcher
879+
880+ tracker_home = os.path.join(os.getcwd(), 'instance')
881+ application = RequestDispatcher(tracker_home)
882+ else:
883+ def application(environ, start_response):
884+ status = '503 Service Unavailable'
885+ output = 'service is down for maintenance'
886+ response_headers = [('Content-type', 'text/plain'),
887+ ('Content-Length', str(len(output)))]
888+ start_response(status, response_headers)
889+ return [output]
665890
666- To test the above you should create a demo tracker with ``python demo.py``.
667- Edit the ``config.ini`` to change the web URL to "http://localhost:8917/".
891+ This handler allows you to temporarily disable the tracker by setting
892+ "enabled = False", apache will automatically detect the changed
893+ roundup.wsgi file and reload it.
668894
895+ One last change is needed. In the tracker's config.ini change the db
896+ parameter in the [main] section to be /home/roundup-foo/db. This will
897+ put the files and messages in the db directory for the user.
669898
670899Configure an Email Interface
671900----------------------------
0 commit comments