Mercurial

This example install mercurial as a web service.

Install

apt install mercurial uwsgi-core uwsgi-plugins-all

UWSGI

Test

Application

foobar.py

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]

Server

uwsgi --plugins http,python3 --http :9090 --wsgi-file foobar.py

Client

$ telnet 127.0.0.1 9090
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
HEAD / HTTP/1.0

HTTP/1.0 200 OK
Content-Type: text/html

Hello World

Run it

CGI

/var/www/cgi-bin/hgweb.wsgi

config = b"/var/www/repos/WWW.EXAMPLE.COM/hgweb.config"
import os
os.environ["HGENCODING"] = "UTF-8"
import cgitb; cgitb.enable()
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb
application = hgweb(config)
CONF

/var/www/repos/WWW.EXAMPLE.COM/hgweb.config

[collections]
/var/www/repos/WWW.EXAMPLE.COM = /var/www/repos/WWW.EXAMPLE.COM

[web]
staticurl = /static/
allow_archive = gz
RUN

http

#! /bin/bash

#LOG
exec 2>&1
ulimit -l unlimited
ulimit -i unlimited
ulimit -q unlimited
ulimit -n 8192
ulimit -aH

#RUN
export TZ="UTC"
exec /bin/uwsgi --die-on-term --plugins http,python3 --http :9090 --master --processes 4 --threads 2 --uid=www-data --gid=www-data --wsgi-file /var/www/cgi-bin/hgweb.wsgi

UWSGI

#! /bin/bash

#LOG
exec 2>&1
ulimit -l unlimited
ulimit -i unlimited
ulimit -q unlimited
ulimit -n 8192
ulimit -aH

#RUN
export TZ="UTC"
mkdir -p /run/uwsgi
chown -R www-data:www-data /run/uwsgi
exec /bin/uwsgi --die-on-term --plugins python3 --uwsgi-socket /run/uwsgi/hgweb.sock --master --processes 4 --threads 2 --uid=www-data --gid=www-data --wsgi-file /var/www/cgi-bin/hgweb.wsgi

NGINX

...
        location / {
                uwsgi_pass unix:/run/uwsgi/hgweb.sock;
                include uwsgi_params;

                limit_except GET HEAD {
                        auth_basic "Login";
                        auth_basic_user_file /var/www/private/htpasswd;
                }
        }

        location /static/ {
                alias /usr/lib/python3/dist-packages/mercurial/templates/static/;
                expires 30d;
        }
...

Resources

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies