Showing posts with label bugtracking. Show all posts
Showing posts with label bugtracking. Show all posts

Saturday, June 16, 2012

Trac

Installing Trac:


Tested versions:

  • Fedora: 17 x86_64
  • PostgreSQL: 9.1.4 x86_64
  • Trac: 0.12.3 noarch
PostgreSQL install procedure: here

Official documentation:
http://trac.edgewall.org/wiki/TracInstall

A. Install Trac and PostgreSQL support


1. Minimal installation:

#---
yum -y install \
trac \
python-storm-postgresql
#---

2. Some interresting plugins:

#---
yum -y install \
trac-git-plugin \
trac-iniadmin-plugin \
trac-customfieldadmin-plugin \
trac-accountmanager-plugin \
trac-sumfields-plugin \
trac-ticketdelete-plugin \
trac-tocmacro-plugin
#---

B. Create PostgreSQL database:


Offical documentation:
http://trac.edgewall.org/wiki/DatabaseBackend#Postgresql

1. Create user [trac], pass [pass], and database [trac_db]

#---
createuser -U postgres -W -D -R -S trac
psql -U postgres -W -c "ALTER USER trac WITH PASSWORD 'pass';"
createdb -U postgres -W trac_db
psql -U postgres -W -c "GRANT ALL ON DATABASE trac_db TO trac;"
#---

2. Check connectivity:

#---
psql -U trac -d trac_db -h localhost -p 5432 -W -c "SELECT 1;"
#---

3. In case you need to remove the database:

#---
dropdb -U postgres -W trac_db
#---

4. In case you need to remove the user:

#---
dropuser -U postgres -W trac
#---

C. Standalone version:


1. Create directory:

#---
mkdir /var/local/trac
#---

2. Add user:

#---
useradd -m -d /var/local/trac -s /bin/bash -c "Trac stand-alone daemon user" trac
#---

3. Reset home dir owner:

#---
chown trac:trac /var/local/trac
#---

4. Check trac setup:


#---
su - trac
#---

#---
pwd
#---

Expected:
/var/local/trac

5. Create project dirs

#---
mkdir -p /var/local/trac/projects/tst
#---

6. Initialize Trac project environment:

#---
trac-admin /var/local/trac/projects/tst initenv
#---

When asked about the connection string give the following:
postgres://trac:pass@localhost:5432/trac_db

7. In case you fail, remove all and start it over:


#---
rm -rf /var/local/trac/projects/*
#---

Just in case: recreate the database (dropdb followed by createdb)

8. Check if it is ok:

#---
tracd --port 8000 /var/local/trac/projects/tst
#---

Open your browser and point it to:
http://localhost:8000/tst

D. Apache version:


Official documentation:
http://trac.edgewall.org/wiki/TracModWSGI

1. Install packagers:

#---
yum -y install \
httpd \
mod_wsgi
#---

2. Deploy http content (with CGIs):

#---
trac-admin /var/local/trac/projects/tst deploy /var/local/trac/projects/tst
#---

3. Set permissions:

#---
usermod -a -G apache trac
chown -R apache:apache /var/local/trac
chmod -R g+rw /var/local/trac
#---

4. Set SElinux context:

#---
chcon -R -v --type=httpd_sys_rw_content_t /var/local/
semanage fcontext -a -t httpd_sys_rw_content_t "/var/local/(/.*)?"
#---

5. Check permissions:

#---
ls -lZ /var/local/
#---

Expected:
drwxrwxrwx. apache apache system_u:object_r:httpd_sys_content_t:s0 trac

6. Allow apache to connect to database (SElinux):

#---
setsebool -P httpd_can_network_connect_db 1
#---

7. Create apache conf file:

#---
cat > /etc/httpd/conf.d/trac-tst.conf << __END__
WSGIScriptAlias /trac/tst /var/local/trac/projects/tst/cgi-bin/trac.wsgi


    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all

__END__
#---

8. Put apache to run:

#---
systemctl enable httpd.service
systemctl start httpd.service
#---

9. Check if it is running:

http://localhost/trac/tst

E. Important logs:

/var/log/httpd/error_log
/var/log/messages


F. If you need to create several projects here are some scripts that automate the process:


createprj.sh:
https://dl.dropbox.com/u/9583089/createprj.sh
createdb.sh:
https://dl.dropbox.com/u/9583089/createdb.sh
trac-tpl.conf:
https://dl.dropbox.com/u/9583089/trac-tpl.conf

Put these files into [/var/local/trac/] and execute (as root):

Usage:
./createprj.sh <project> <db username> <db pass> [<project name>]

E.g.:

#---
./createprj.sh test_prj trac pass "My automatically created Test Project"
#---


G. Authentication

This is left out-of-the scope and can be easily implemented following the instructions on the official documentation:
http://trac.edgewall.org/wiki/TracModWSGI#ConfiguringAuthentication
http://trac.edgewall.org/wiki/TracPermissions

To the automated process on section F, just edit the [trac-tpl.conf] file to include the setup for your preferred authentication method.

Related posts:

Saturday, December 04, 2010

Bugtracking using Trac

This documentation is aimed at version 0.12

http://trac.edgewall.org

This documentation heavily based on the official documentation, so if you are unsure about something address it:
http://trac.edgewall.org/wiki/TracInstall

A. Prerequisites:

1. Database

I will use a MySQL database, but you could also use PostgreSQL or a local DB file (through Sqlite). So first you install the Server, if do not have one, and create the database according to the documentation, that I reproduce here.
#---
yum -y install \
mysql-server \
mysql \
MySQL-python
#---

I need "root" access for the following steps. (If have some "root" related problems please address to my corresponding post.)
http://gka-linux.blogspot.com/2010/03/mysql-root-password-reset.html

1.2. Start the server (if necessary):
#---
service mysqld restart
chkconfig --level 345 mysqld on
#---

1.3. Get "root" MySQL shell:
#---
## skip this part if you already have a working MySQL server
## mysql_secure_installation
mysql -u root -p
#---

1.4. Create the database (on the shell):
CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
USE trac;
GRANT ALL ON trac.* TO tracuser@localhost IDENTIFIED BY '<plain text root password for trac>';

NOTE: Your connection string will be (remember it): mysql://tracuser:<plain text root password for trac>@localhost/trac

2. Version Control System:

For this example Subversion (SVN) which I already documented here:
http://gka-linux.blogspot.com/2009/07/subversion-and-apache-with-pam.html
Or Git: 
http://gka-linux.blogspot.com/2011/03/git-server-on-centos-55.html

3. Apache

I assume that you already have an Apache server and want to put Trac along with other pages you may have.

3.1. Additional packages:
#---
yum -y install \
mod_fcgid \
mod_python \
mod_wsgi
#---

B. The Trac:

OBS.: For CentOS boxes, you need RPMForge repository (or else you are bound to the version 0.10):

#---
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
#---

1. Installing things:

1.1. Fedora:
#---
yum -y install \
trac \
trac-git-plugin \
trac-mercurial-plugin \
trac-iniadmin-plugin \
trac-accountmanager-plugin \
trac-customfieldadmin-plugin \
trac-peerreview-plugin \
trac-privateticketsplugin \
trac-ticketdelete-plugin \
trac-spamfilter-plugin
#---

1.2. CentOS:
#---
yum -y install \
trac \
trac-git-plugin \
trac-mercurial-plugin \
trac-iniadmin-plugin \
trac-peerreview-plugin \
trac-ticketdelete-plugin \
trac-spamfilter-plugin
#---

1.2.1 MySQL-python:

Because CentOS comes with MySql-python 1.2.1 (and this version does NOT work with Trac) you need to upgrade this manually:

#---
wget http://dev.centos.org/centos/5/testing/x86_64/RPMS/MySQL-python-1.2.2-3.el5s2.x86_64.rpm
rpm -Uvh MySQL-python-1.2.2-3.el5s2.x86_64.rpm
#---


2. Start the setup process:
#---
PRJ_NAME="<project name>"
PRJ_DIR=`echo $PRJ_NAME | tr [A-Z] [a-z] | sed -e "s/[^[:alnum:]]/\./g"`
DB_CONN="mysql://tracuser:<plain text root password for trac>@localhost/trac"
#DB_CONN="sqlite:db/trac.db"
REPOS_TYPE="git" # could be one of: "git", "mercurie" or "svn"
REPOS_DIR="/var/lib/git/${PRJ_NAME}.git"
TRAC_DIR="/var/local/trac"
TRAC_PRJS_DIR="${TRAC_DIR}/projects"
TRAC_PRJ_DIR="${TRAC_PRJS_DIR}/${PRJ_DIR}"
mkdir -p ${TRAC_PRJ_DIR}
trac-admin ${TRAC_PRJ_DIR} initenv "${PRJ_NAME}" "${DB_CONN}" "${REPOS_TYPE}" "${REPOS_DIR}"
#---

NOTE: If something goes wrong and you want to do it again just remove the directory (but be aware that the Trac content will be lost):
#---
rm -rf ${TRAC_DIR}
#---

2.1. CentOS:
Currently there is an open issue with GitPlugin and Trac working together on CentOS:
http://trac-hacks.org/ticket/3757
http://trac-hacks.org/ticket/8102

2.2. Git Repository setup:
#---
cat >> ${TRAC_PRJ_DIR}/conf/trac.ini << __END__
[git]
cached_repository = false
git_bin = /usr/bin/git
persistent_cache = false
shortrev_len = 7

[components]
tracext.git.* = enabled
__END__
#---



3. Setting up the Apache server:

I prefer this more complicated option because the odds are that you do not need yet another server running. Another assumption is that you will have several projects that also need separated tracking "spaces". For instance, you may start using technology "X" and latter on decide to migrate everything to technology "Y", so you probably do not want to mix bugs from "X" with "Y". This is, of course, obvious if you have software factory.

3.1. Create Web content (per project):

#---
TMP_DIR=`mktemp -d`
rm -rf ${TMP_DIR}
trac-admin ${TRAC_PRJ_DIR} deploy ${TMP_DIR}
mv ${TMP_DIR}/* ${TRAC_PRJ_DIR}
rm -rf ${TMP_DIR}
#---

3.2. Global configuration file (/etc/httpd/conf.d/trac.conf):
#---
cat > /etc/httpd/conf.d/trac.conf << __END__
#Global environment for Trac's CGI
<LocationMatch /cgi-bin/trac\.f?cgi>
SetEnv TRAC_ENV_PARENT_DIR "${TRAC_PRJS_DIR}"
</LocationMatch>
#Special environment for Trac's FastCGI CGI
<IfModule mod_fastcgi.c>
<LocationMatch /cgi-bin/trac\.fcgi>
FCGIDDefaultInitEnv TRAC_ENV_PARENT_DIR ${TRAC_PRJS_DIR}
</LocationMatch>
</IfModule>
#Python environment
<IfModule mod_python.c>
<LocationMatch "/trac/[^/]+/cgi-bin/trac.cgi>
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir ${TRAC_PRJS_DIR}
</LocationMatch>
</IfModule>
##
# Authentication @ ${TRAC_DIR}/trac.htpasswd
# To add a new user:
# htpasswd ${TRAC_DIR}/trac.htpasswd <username>
#
##
<LocationMatch "/trac/[^/]+/login">
AuthType Basic
AuthName "Trac"
AuthUserFile ${TRAC_DIR}/trac.htpasswd
Require valid-user
</LocationMatch>
__END__
#---

3.3. Project specific configuration file (/etc/httpd/conf.d/trac-"<project name>".conf):
#---
cat > /etc/httpd/conf.d/trac-${PRJ_DIR}.conf << __END__
### Regular CGI
#ScriptAlias /trac/${PRJ_DIR} ${TRAC_PRJ_DIR}/cgi-bin/trac.cgi
### Fast CGI (default)
ScriptAlias /trac/${PRJ_DIR} ${TRAC_PRJ_DIR}/cgi-bin/trac.fcgi
__END__
#---

3.4. Authentication (via password file):

3.4.1. Creating the file AND admin user (JUST this ONE time):
#---
htpasswd -c ${TRAC_DIR}/trac.htpasswd admin
#---

3.4.2. Creating a regular user (notice the lack of '-c' parameter):
#---
htpasswd ${TRAC_DIR}/trac.htpasswd <username>
#---

3.4.3. Or use a generic safe single line:
#---
PASSFILE="${TRAC_DIR}/trac.htpasswd"
htpasswd `([[ -f ${PASSFILE} ]] && echo "" || echo "-c")` ${PASSFILE} admin
#---

#---
htpasswd `([[ -f ${PASSFILE} ]] && echo "" || echo "-c")` ${PASSFILE} <username>
#---

3.4.4. Check it out:
#---
cat ${PASSFILE}
#---

3.5. Security and SElinux:

3.5.1. SElinux and Trac:
#---
echo /usr/bin/chcon -R -v -t httpd_t \'${TRAC_DIR}\' | bash
#---

3.5.2. SElinux and Repository:
#---
echo /usr/bin/chcon -R -v -t httpd_t \'${REPOS_DIR}\' | bash
#---

4. Access and test:

#---
service httpd restart
firefox "http://localhost/trac/${PRJ_DIR}"
#---

C. Important files and directories:

1. Content:
/var/local/trac

2. Setup:
/var/local/trac/projects/<your project>/conf/trac.ini

3. Apache config:
3.1. General setup:
/etc/httpd/conf.d/trac.conf
3.2. Your project:
/etc/httpd/conf.d/trac-<your project>.conf

4. Logging:
/var/local/trac/projects/<your project>/log/