setting up central mercurial server in ubuntu

来源:互联网 发布:自助授权系统源码 编辑:程序博客网 时间:2024/06/06 12:40

ref:  http://phpfour.com/blog/2011/05/setting-up-central-mercurial-server-in-ubuntu/



It’s been a while since we’ve been thinking about moving to Mercurial from Subversion at our company. We were convinced about the benefits of DVCS and chose Mercurial over Git. However, due to pressure at work and some procrastination, the move was delayed a couple times. Finally, today we had the move and the team is already up to speed with it.

Although it’s quite simple to install it in a central server, the different articles on the web had me confused with too many options or with a different distro than Ubuntu. So, here is a dead simple list of things to do for installing Mercurial centrally for your dev team.


1. Log onto your server using SSH

ssh admin@rbs-server.com

2. Install mercurial from repository:

sudo apt-get update
sudo apt-get install mercurial

3. We need to have a directory to store our Mercurial configuration and repository files, so let’s create one and change it’s owner to the apache user so that apache can access them:

cd /var/
sudo mkdir hg
sudo mkdir hg/repos
sudo chown -R www-data:www-data hg/repos

4. We’ll be creating a configuration that will allow us to host multiple repositories in this server. And we’ll be using CGI to serve the files through Apache:

cd /var/hg
sudo cp /usr/share/doc/mercurial/examples/hgweb.cgi .
sudo chmod a+x hgweb.cgi

5. We need to show the location of the config file to the CGI script, so open the file hgweb.cgi with nano or vim to update the line with “config = …” with the following and save it.

config = "/var/hg/hgweb.config"

6. Now let’s create the file /var/hg/hgweb.config and write the location of the repositories:

sudo nano hgweb.config

Enter the following content and save the file:

[collections]
/var/hg/repos = /var/hg/repos

7. As a final step, we’ll need to update the Apache configuration so that it executes the CGI when requested with a /hg prefix:

cd /etc/apache2/sites-available
sudo nano default

At the end of the defaul virtual host configuration and just before the </VirtualHost> tag, add the following and save it:

ScriptAlias /hg "/var/hg/hgweb.cgi"

AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /var/hg/hgusers
Require valid-user

8. In order to take effect of the above change, we’ll need to restart apache:

sudo apache2ctl restart

9. Now you should be able to visit the server’s /hg location like http://rbs-server.com/hg from browser. However, you’ll be greeted with a username/password prompt as we’ve enabled that in our apache configuration above. So, lets add some user for our use.

cd /var/hg
htpasswd -mc hgusers admin

It will ask for the password of the user admin twice and after you enter that, it will be stored in the file hgusers. You can add more users in the similar fashion, just ignore the c parameter as it was used to create the file first time:

htpasswd -m hgusers abid
htpasswd -m hgusers saeed
...

10. Now visit the /hg path in your browser and you’ll see the empty list of repositories after you authenticate.

11. By default Mercurial only allows pushing changes through SSL, but in our case it was not necessary. Also, we wanted to give all our developers the push access to the repositories. For that, let’s update the system-wide mercurial configuration file /etc/mercurial/hgrc by adding the following lines at the end of the file and saving it:

[web]
allow_push = *
push_ssl = false

12. Now that all is set, let’s setup a test repository so that we can clone it in our development machine:

cd /var/hg/repos
mkdir test
cd test
hg init

This repository can now be accessed through http://rbs-server.com/hg/test and can be cloned in a development machine with the following command (mercurial must be installed already):

cd /var/www
hg clone http://rbs-server.com/hg/test

Hope this will make someone’s life easy. Enjoy the beauty of Mercurial!


原创粉丝点击