Monday, February 18, 2013

Setup Trac on Raspberry Pi as a Wiki and Issue Tracking Tool

Trac with GIT

Trac is a wiki and issue tracking tool. There are other choices such as redmind and mantisbt. However, Trac is the most suitable one for running on Raspberry Pi because:
  1. it is run by python, which is installed by default for raspbian. (php and ruby are not required)
  2. it is relatively light weight. It can use sqlite as the database, rather than MySQL or PostgresSQL.
  3. it can be run in standalone mode, without using apache or lighttpd. (although I will still use lighttpd to 'proxy' Trac)
  4. It supports modern version control tool such as Subversion and GIT. (redmine also supports, but again, it's not that light weight)
  5. with making use of virtual environment (virutalenv), you can setup Trac without using a privilege account.
  6. it is a mature product and many organizations are using it (http://trac.edgewall.org/wiki/TracUsers)

Install and setup Trac

First, make sure virtualenv is already installed. (apt-get install virtualenv)


  1. Create a directory and setup the virtual environment
    • mkdir trac; virtualenv --no-site-packages trac
  2. Source the environment
    • cd trac; . bin/active
  3. Install trac
    $ easy_install trac
    Searching for trac
    Reading http://pypi.python.org/simple/trac/
    Reading http://trac.edgewall.org/
    Reading http://trac.edgewall.org/wiki/TracDownload
    Reading http://trac.edgewall.com/
    Reading http://projects.edgewall.com/trac
    Reading http://projects.edgewall.com/trac/wiki/TracDownload
    Best match: Trac 1.0.1
    ...
    Installed /xxx/trac_test/lib/python2.7/site-packages/Genshi-0.6-py2.7.egg
    Finished processing dependencies for trac
  4. Create a project directory (ie. projects/project1)
    $ mkdir -p projects/project1
  5. Setup the project1 environment
    • $ trac-admin . initenv
      Creating a new Trac environment at xxxxxxxxx
      
      Trac will first ask a few questions about your environment
      in order to initialize and prepare the project database.
      
       Please enter the name of your project.
       This name will be used in page titles and descriptions.
      
      Project Name [My Project]> Project1
      
       Please specify the connection string for the database to use.
       By default, a local SQLite database is created in the environment
       directory. It is also possible to use an already existing
       PostgreSQL database (check the Trac documentation for the exact
       connection string syntax).
      
      Database connection string [sqlite:db/trac.db]>
      
      Creating and Initializing Project
       Installing default wiki pages
      ...
      
      ---------------------------------------------------------------------
      Project environment for 'Project1' created.
      
      You may now configure the environment by editing the file:
      
        /xxxx/projects/project1/conf/trac.ini
      
      If you'd like to take this new project environment for a test drive,
      try running the Trac standalone web server `tracd`:
      
        tracd --port 8000 /xxxx/projects/project1
      
      Then point your browser to http://localhost:8000/project1.
      There you can also browse the documentation for your installed
      version of Trac, including information on further setup (such as
      deploying Trac to a real web server).
      
      The latest documentation can also always be found on the project
      website:
      
        http://trac.edgewall.org/
      
      Congratulations!
  6. Download the digest.py and prepare the password file (digest.txt)
    • $python digest.py -u test -p test
      test:trac:36c6af7afdad707bbcc185a18a2febbf
      $ python digest.py -u test -p test >> project1/digest.txt
  7. Set the account created to be ADMIN.
    • trac-admin . permission add test TRAC_ADMIN
  8. Change the logo by modifying project1/conf/trac.ini
    [header_logo]
    alt = (please configure the [header_logo] section in trac.ini)
    height = -1
    link =
    src = site/your_project_logo.png
    width = -1
  9. Startup TRAC using a high port (say, 50080)
    cd project1
    tracd -s --port 50080 --auth=project1,/xxx/trac_test/projects/project1/digest.txt,trac .


Configure lighttpd with trac (optional)

For example, if we want to access trac behind lighttpd, the simplest method is to make use the proxy plugin. ( http:///trac will go to http://:50080/trac )
  1. Start tracd with base path "/trac"
    • tracd -s --base-path=/trac --port 50080 --auth=project1,/xxx/trac_test/projects/project1/digest.txt,trac .
  2. Modify lighttpd.conf.
    • $HTTP["url"] =~ "^/trac/" {
           proxy.server = ("" =>
              (
                      ( "host" => "127.0.0.1", "port" => 50080) ,
              ),
           )
      }
  3. Make sure mod_proxy is active
    • lighty-enable-mod proxy; /etc/init.d/lighttpd force-reload

Enable GIT

By default Trac doesn't recognize GIT, but it is very simple to support GIT by changing "trac.ini" and restart tracd:
 
[components]
tracopt.versioncontrol.git.* = enabled

[git]
cached_repository = false
git_bin = /usr/bin/git
git_fs_encoding = utf-8
persistent_cache = false
shortrev_len = 7
trac_user_rlookup = false
use_committer_id = true
use_committer_time = true
wikishortrev_len = 40

[trac]
repository_dir = /xxx/.git

Then restart tracd

Ref:

4 comments:

lv10 said...

Thanks for the great article. I'm a bit confused by the digest.py part. Where can I download this file?

Unknown said...

Also from me - thank you for the arcticle.
But also the digest.py part is confusing. ... as matter of fact you want to build the "md5" digest - correct?
I have done this using the python md5 lib:

from hashlib import md5
md5("%s:%s:%s" % (username, realm, password)).hexdigest()

Poor IT Guy said...

the new version changed the filename to htdigest.py. Please note that TRAC got an awesome cousin called "Apache Bloodhound". I will test it and share my experience soon.

Poor IT Guy said...

the new version changed the filename to htdigest.py. Please note that TRAC got an awesome cousin called "Apache Bloodhound". I will test it and share my experience soon.