NGINX Unit

Mercurial§

To install and run the Mercurial source control system using Unit:

  1. Install Unit with a Python language module.

  2. Install Mercurial’s core files. Here, we install it at /path/to/app/; use a real path in your configuration.

  3. Optionally, configure a repository or choose an existing one, noting its directory path.

  4. Unit uses WSGI to run Python apps, so it requires a wrapper script to publish a Mercurial repo. Here, it’s /path/to/app/hgweb.py (note the extension); the application callable is the entry point:

    from mercurial.hgweb import hgweb
    
    # path to a repo or a hgweb config file to serve in UTF-8 (see 'hg help hgweb')
    application = hgweb("/path/to/app/repo/or/config/file".encode("utf-8"))
    

    This is a very basic script; to elaborate on it, see the Mercurial repo publishing guide.

  5. Run the following command so Unit can access the application directory:

    # chown -R unit:unit /path/to/app/
    

    Note

    The unit:unit user-group pair is available only with official packages, Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

  6. Next, prepare the Mercurial configuration for Unit (use a real value for path):

    {
        "listeners": {
            "*:80": {
                "pass": "applications/hg"
            }
        },
    
        "applications": {
            "hg": {
                "type": "python",
                "path": "/path/to/app/",
                "module": "hgweb"
            }
        }
    }
    
  7. Upload the updated configuration. Assuming the JSON above was added to config.json:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    Note

    The control socket path may vary; run unitd -h or see Startup and Shutdown for details.

    After a successful update, you can proceed to work with your Mercurial repository as usual:

    $ hg config --edit
    
    $ hg clone http://localhost/ project/
    
    $ cd project/
    
    $ touch hg_rocks.txt
    
    $ hg add
    
    $ hg commit -m 'Official: Mercurial on Unit rocks!'
    
    $ hg push
    
    Mercurial on Unit - Changeset Screen