Sunday, January 30, 2011

Running Mercurial hg serve on Linux, allowing push

In a previous post I showed how to run "hg serve" on Windows.  I then tried the same approach on Linux, and things did not quite work the same.

After much tinkering, here is my recipe for running on Linux.

1) Create a directory called /var/hg

2) Create a file called /var/hg/hg.conf with the following content -- this peculiar directive states  all subdirectories of /var/hg/repos are treated as repositories and can be accessed directly using the subdirectory name (e.g. /var/hg/repos/myrepo is accessed as myrepo).

/var/hg/repos = /var/hg/repos

3) Create a directory called /var/hg/repos -- this is where you will create the repositories

4)  Create a repository as follows (repeat for any repository you want to create).
cd /var/hg/repos
mkdir myrepo
cd myrepo
hg init

5) Edit /etc/mercurial/hgrc and add the following lines to allow pushing

push_ssl = false
allow_push = *

6) Create a file /etc/init.d/hg.init and make it executable (chmod a+x) with the following contents

# Startup script for mercurial server.
# Change following ines
SRCNAME=" package source"
# Path to PID file of running mercurial process.


case "$state" in
    echo "Mecurial Server service starting."
   (cd ${SRC} ;${APP_BIN} serve -d --webdir-conf ${SRC}/hg.conf -p 8000 --pid-file ${PID_FILE})

  if [ -f "${PID_FILE}" ]; then
    PID=`cat "${PID_FILE}"`
    if [ "${PID}" -gt 1 ]; then
      kill -TERM ${PID}
      echo "Stopping the Mercurial service PID=${PID}."
      echo Bad PID for Mercurial -- \"${PID}\"
    echo No PID file recorded for mercurial

  echo "$0 {start|stop}"
  exit 1

7) You can now start the server (the -p 8000 parameter in the script makes it listen on port 8000)
/etc/init.d/hg.init start

1 comment:

YouthOfUnity said...

Excellent, This is what i have been looking for and i got hg repos up and running in no time at all. One of the RARE occurance to have such accurate and working instructions.
Thanks, this was a life saver