Edgewall Software

Changes between Initial Version and Version 1 of Ubuntu-10.04.04-Mercurial


Ignore:
Timestamp:
Aug 31, 2012, 10:01:16 AM (12 years ago)
Author:
anonymous
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ubuntu-10.04.04-Mercurial

    v1 v1  
     1= Installing Trac with Mercurial on Ubuntu =
     2
     3This is a modified version of the [[Ubuntu-11.04-Subversion]] guide written for a 10.04.4/Lucid installation with Mercurial 2.3.
     4
     5The goal of this tutorial is to demostrate how to setup a Mercurial <-> Trac enviroment on Ubuntu 10.04. A MySQL database and Mercurial Python bindings are going to be used.
     6Please note that only general instructions are provided, and it's asummed that you have basic knowledge on Linux administration.
     7
     8'''Note''': for a full installation tutorial on Trac, please read TracInstall
     9
     10[[PageOutline(2-3,Installation Steps,inline)]]
     11
     12== Installing the software and its dependencies ==
     13
     14= Progress indication, to be removed =
     15
     16=== Base packages ===
     17
     18In order to get Trac and Subversion installed, you will need to get a few packages listed below. Also, make sure your system is updated.
     19
     20{{{
     21sudo apt-get install apache2 libapache2-mod-python python-setuptools python-genshi mysql-server python-mysqldb
     22}}}
     23
     24=== Subversion ===
     25
     26Installing Subversion (SVN) is pretty straight forward. Just run:
     27
     28{{{
     29sudo apt-get install subversion
     30}}}
     31
     32=== Trac ===
     33
     34There are different ways of installing Trac. But since this tutorial is focused on Ubuntu, you'll do the Ubuntu way:
     35
     36{{{
     37sudo apt-get install trac
     38}}}
     39
     40== Configuring ==
     41
     42This part is maybe the most important section on this tutorial. You'll learn how to syncronize Trac and Subversion in order to be able to see on your Trac Project website what's going on in your repository and also how to automate some tasks.
     43
     44=== Subversion ===
     45
     46==== Creating the project ====
     47
     48You may already know how to do this, but let's make a review just in case.
     49
     50Create a directory to store the SVN projects:
     51{{{
     52sudo mkdir /var/lib/svn
     53}}}
     54
     55Create a the project directory:
     56{{{
     57sudo mkdir /var/lib/svn/YourProject
     58}}}
     59
     60Use svnadmin to create a project in the previously created folder:
     61{{{
     62sudo svnadmin create /var/lib/svn/YourProject
     63}}}
     64
     65In order to perform some changes to the project, Trac needs write access to it:
     66{{{
     67sudo chown -R www-data /var/lib/svn/YourProject
     68}}}
     69
     70Start the Subversion server (or use your preferred method):
     71{{{
     72sudo svnserve -d
     73}}}
     74
     75=== Setup the MySQL database ===
     76
     77Before configuring your new Trac project, you'll need to setup the MySQL database.
     78
     79Log into MySQL database, using the root credentials you've setup during the installation:
     80{{{
     81mysql -u root -p
     82}}}
     83
     84Once logged in, create the database for Trac:
     85{{{
     86CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
     87}}}
     88
     89Now create the username which Trac is going to use to connect to the database:
     90{{{
     91GRANT ALL ON trac.* TO trac@localhost IDENTIFIED BY 'yourpassword';
     92}}}
     93
     94You can now exit the MySQL command line.
     95
     96=== Trac ===
     97
     98==== Initiate the enviroment
     99
     100Let's create a directory to contain all the Trac project (just like we did for SVN projects).
     101{{{
     102sudo mkdir /var/lib/trac
     103}}}
     104
     105Create a directory where to store the Trac project in:
     106{{{
     107sudo mkdir /var/lib/trac/YourProject
     108}}}
     109
     110As you did for Subversion, change the ownership of the project files to Apache's user www-data:
     111{{{
     112sudo chown -R www-data:www-data /var/lib/trac/YourProject
     113}}}
     114
     115Use trac-admin to create the new project:
     116{{{
     117sudo trac-admin /var/lib/trac/YourProject initenv
     118}}}
     119
     120Also you will need to fill in some information, like the project name. It will ask you for the MySQL connection string. Input the following (according to the way we did setup the MySQL database in the step 2.2).
     121{{{
     122mysql://trac:yourpassword@localhost/trac
     123}}}
     124
     125Pay attention to the question about the location of the Subversion project. Enter the path as discussed before:
     126{{{
     127/var/lib/svn/YourProject
     128}}}
     129
     130If the MySQL default engine wasn't InnoDB, you might need to convert the tables tha trac-admin has just created. Issue the following within your MySQL client:
     131{{{
     132USE trac; \
     133ALTER TABLE `attachment` ENGINE = InnoDB; \
     134ALTER TABLE `auth_cookie` ENGINE = InnoDB; \
     135ALTER TABLE `cache` ENGINE = InnoDB; \
     136ALTER TABLE `component` ENGINE = InnoDB; \
     137ALTER TABLE `enum` ENGINE = InnoDB; \
     138ALTER TABLE `milestone` ENGINE = InnoDB; \
     139ALTER TABLE `node_change` ENGINE = InnoDB; \
     140ALTER TABLE `permission` ENGINE = InnoDB; \
     141ALTER TABLE `report` ENGINE = InnoDB; \
     142ALTER TABLE `repository` ENGINE = InnoDB; \
     143ALTER TABLE `revision` ENGINE = InnoDB; \
     144ALTER TABLE `session` ENGINE = InnoDB; \
     145ALTER TABLE `session_attribute` ENGINE = InnoDB; \
     146ALTER TABLE `system` ENGINE = InnoDB; \
     147ALTER TABLE `ticket` ENGINE = InnoDB; \
     148ALTER TABLE `ticket_change` ENGINE = InnoDB; \
     149ALTER TABLE `ticket_custom` ENGINE = InnoDB; \
     150ALTER TABLE `version` ENGINE = InnoDB; \
     151ALTER TABLE `wiki` ENGINE = InnoDB;
     152}}}
     153
     154==== Explicit syncronization ====
     155
     156'''Note''': For more information about the Explicit Syncronization method, please read TracRepositoryAdmin#ExplicitSync
     157
     158First, edit the '''trac.ini''' file, located in ''/var/lib/trac/YourProject/conf/''. Modify the "repository_sync_per_request" directive and set it to an empty value.
     159
     160Now you need to create the Subversion hooks. First, create the post-commit hook the in ''/var/lib/svn/YourProject/hooks/'' directory, with the following content:
     161{{{
     162#!/bin/sh
     163export PYTHON_EGG_CACHE="/path/to/cache/dir"
     164/usr/bin/trac-admin /var/lib/trac/YourProject changeset added "$1" "$2"
     165}}}
     166
     167Make sure you give the script execution perms:
     168{{{
     169sudo chmod +x /var/lib/svn/YourProject/hooks/post-commit
     170}}}
     171
     172Another important hook script to have is post-revprop-change. The procedures are similiar as above, but the script is slightly different:
     173{{{
     174#!/bin/sh
     175export PYTHON_EGG_CACHE="/path/to/cache/dir"
     176/usr/bin/trac-admin /var/lib/trac/YourProject changeset modified "$1" "$2"
     177}}}
     178
     179Again, make sure you give exec perms to the script.
     180
     181Now Trac will be notified about changes you make to your repository and will make them availables in the timeline.
     182
     183
     184=== Apache ===
     185
     186==== Set up Trac handling ====
     187
     188Apache needs to know how to handle Trac. Use the following block to set up Trac handling:
     189{{{
     190<Location /projects> #set up Trac handling
     191    SetHandler mod_python
     192    PythonHandler trac.web.modpython_frontend
     193    PythonOption TracEnvParentDir /var/lib/trac
     194    PythonOption TracUriRoot /projects
     195</Location>
     196}}}
     197
     198Note that it's pointing to the main Trac directory. It means it will expose all of your Trac projects. You may need to apply this configuration to Apache:
     199{{{
     200sudo a2ensite trac
     201}}}
     202
     203==== Authentication ====
     204
     205In order to allow users to log in Trac, you will need the following section in your Apache configuration:
     206{{{
     207<LocationMatch "/projects/[^/]+/login">
     208    AuthType Basic
     209    AuthName "Trac"
     210    AuthUserFile /var/lib/trac/.htpasswd
     211    Require valid-user
     212</LocationMatch>
     213}}}
     214
     215You should now create the .htpasswd file, with an admin user:
     216{{{
     217sudo htpasswd -c .htpasswd admin
     218}}}
     219
     220Go ahead and restart Apache:
     221{{{
     222sudo /etc/init.d/apache2 restart
     223}}}
     224
     225Finally, you must grant admin rights to the user you've just created:
     226{{{
     227sudo trac-admin /var/lib/trac/YourProject permission add admin TRAC_ADMIN
     228}}}
     229
     230== Automatic reference to the SVN changesets in Trac tickets ==
     231
     232Something useful is to reference tickets on your commits. That way you can keep a better track of them and also easly access them from the timeline.
     233
     234Make sure you have the following line in your trac.ini configuration file:
     235{{{
     236[components]
     237tracopt.ticket.commit_updater.* = enabled
     238}}}
     239
     240Now, whenever you commit some change related to a ticket, use ''Refs #tn'' to reference this changeset in #tn ticket. For example:
     241{{{
     242svn commit -m "Refs #123 - added this and that"
     243}}}
     244
     245In order to mark a ticket as fixed, use the following:
     246{{{
     247svn commit -m "Fixes #123 - Removed an infinite loop which was causing the application to freeze"
     248}}}