{X} This page is proposed for deletion. See our wiki cleanup plan for more information.

{i} This page does not meet our wiki style guidelines. Please help improve this page by cleaning up its formatting.

Mercurial has a built-in light-weight web server which can be used for browsing a repository with a web browser or for allowing remote machines to pull from you. To use it, simply run:

$ hg serve

And then point your web browser at http://localhost:8000/.

The built-in web server is missing some features found in other web servers, including access control, authentication, SSL, etc. These are especially useful if you want to be able to securely push to a web-based repository. Thus, if you want to make a more permanent server, you should probably use a CGI-based server.

Following are detailed options for using hg's HTTP server:

bash-2.05$ hg --version
Mercurial Distributed SCM (version 1.2.1)

Copyright (C) 2005-2009 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bash-2.05$ hg help serve
hg serve [OPTION]...

export the repository via HTTP

    Start a local HTTP repository browser and pull server.

    By default, the server logs accesses to stdout and errors to
    stderr. Use the "-A" and "-E" options to log to files.

options:

 -A --accesslog       name of access log file to write to
 -d --daemon          run server in background
    --daemon-pipefds  used internally by daemon mode
 -E --errorlog        name of error log file to write to
 -p --port            port to listen on (default: 8000)
 -a --address         address to listen on (default: all interfaces)
    --prefix          prefix path to serve from (default: server root)
 -n --name            name to show in web pages (default: working dir)
    --webdir-conf     name of the webdir config file (serve more than one repo)
    --pid-file        name of file to write process ID to
    --stdio           for remote clients
 -t --templates       web templates to use
    --style           template style to use
 -6 --ipv6            use IPv6 in addition to IPv4
    --certificate     SSL certificate file

use "hg -v help serve" to show global options
bash-2.05$

An init script to start and stop mercurial's built in http server.

bash-2.05$ cat  hg.init
#!/sbin/sh
#
# Startup script for mercurial server.
#
# Change following ines
APP_BIN=/usr/bin/hg
SRC=/export/src
SRCNAME=" package source"
# Path to PID file of running mercurial process.
PID_FILE=/var/adm/hg.pid


state=$1

case "$state" in
'start')
    echo "Mecurial Server service starting."
   (cd ${SRC} ;${APP_BIN} serve --name "${SRCNAME}"  -d  -p 8001 --pid-file ${PID_FILE})
  ;;

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

*)
  echo "$0 {start|stop}"
  exit 1
  ;;
esac
bash-2.05$


CategoryCommand CategoryWeb

Chinese Fran├žais

hgserve (last edited 2012-10-25 19:49:02 by mpm)