Setting up mercurial with HTTP authentication - Windows

This page describes a complete set of steps for installing hg as a windows service, along with nginx for HTTP proxy authentication. As it is, it is most appropriate for intranet configurations but by adding HTTPS to the mixture, the world is your sea food...

Wish list:

1. Download necessary files

2. Configuration

<service>
    <id>nginx</id>
    <name>nginx</name>
    <description>nginx</description>
    <executable>c:\nginx\nginx.exe</executable>
    <logpath>c:\nginx\servicelogs</logpath>
    <logmode>roll</logmode>
    <depend>Mercurial</depend>
    <startargument>-p c:\nginx</startargument>
    <stopargument>-p c:\nginx -s stop</stopargument>
</service>

    server {
        listen       5000;
        server_name  mis-srv;
        access_log  logs/mis-srv.access.log;
        error_log  logs/mis-srv.error.log;
        location / {
            auth_basic           "Mercurial restricted";
            auth_basic_user_file passwd;
            proxy_pass           http://localhost:5500;
        }
    }

test:testpass

<service>
    <id>Mercurial</id>
    <name>Mercurial</name>
    <description>Mercurial</description>
    <executable>cmd.exe</executable>
    <logpath>c:\nginx\hg\servicelogs</logpath>
    <logmode>roll</logmode>
    <depend></depend>
    <startargument>/c "c:\nginx\hg\hg-run start"</startargument>
    <stopargument>/c "c:\nginx\hg\hg-run stop"</stopargument>
</service>

Because winsw has a limitation where a single executable is assumed to start and stop the service, we need to use an intermediate .bat file to simulate this behaviour.

    @echo off
    if "%1"=="start" (goto :start)
:stop
    taskkill /F /IM hg.exe /T
    goto :end
:start
    "c:\Program Files\Mercurial\hg.exe" serve --address localhost --port 5500 --web-conf c:\nginx\hg\hgweb.conf
:end

[web]
push_ssl = false
allow_push = *

[paths]
test = c:\nginx\hg\repository\test

c:\nginx> nginx-service install
c:\nginx> hg-service install

And that's all!