Trac init.d startup script for Centos

You can find on Guy Rutenberg’s blog a nice script to start tracd as a standalone service on a Debian distrib.

As I have a Centos distrib, I modified that script, here it is.

under root privilege,
– create a file named ‘tracd’ in /etc/init.d, with the content below
– chmod 755 /etc/init.d/tracd
– chkconfig –add /etc/init.d/tracd
– service tracd start

# chkconfig: - 85 15
# description: tracd
# processname: tracd
# pidfile: /var/run/

# Source function library.
. /etc/rc.d/init.d/functions

## Options you should probably change ##
# If you only want to serve one project keep this variable
# empty and set the PROJECT_ENV variable 
# add any additional options (such as authentication) here. If you only have one
# project you should probably add -s here
ADDITIONAL_OPTS="--basic-auth *,/myproject/trac/htpasswd,/myproject/trac /myproject/trac"

DESC="web server"

test -x $DAEMON || exit 1

set -e

DAEMON_OPTS="--daemonize --pidfile=$PIDFILE --port=$PORT $ADDITIONAL_OPTS"
if [ -n "$ENV_PARENT_DIR" ]; then
        DAEMON_OPTS="$DAEMON_OPTS --env-parent-dir=$ENV_PARENT_DIR"


start() {
        if [ -a $LOCKFILE ];
                echo "tracd appears to be running, or has crashed, or was not stopped properly."
                echo "check $PIDFILE, and remove $LOCKFILE to start again."
                return -1;

        echo -n $"Starting $NAME: "
        [ $RETVAL = 0 ] && touch ${LOCKFILE}
        return $RETVAL
stop() {
        if [ -a $PIDFILE ]
                echo -n $"Stopping $NAME: "
                kill -9 `cat ${PIDFILE}`
                [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE}
                echo "tracd appears not to be running."

# See how we were called.
case "$1" in
        echo $"Usage: $NAME {start|stop}"
        exit 1

exit $RETVAL

What you MUST change in the script above is the location:
to put your own trac repository location

in particular, I created
in order to use basic auth, I used htpasswd

htpasswd -c /myproject/trac/htpasswd myTracUsername

Why did I install Trac as a standalone service? Because I am now using Cloudbees, which is offering a free git repo, coupled to a Jenkins instance and a Maven repository, so I don’t need to manage my git repository, nor a jenkins install! The only thing missing on Cloudbees is a nice issues tracker and a little wiki, that’s where Trac fits perfectly the bill!


6 thoughts on “Trac init.d startup script for Centos

  1. For CentOS 5.7, I needed:
    #! /bin/bash ( _ required between “!” and “/bin..”)
    chkconfig –add tracd
    worked for me (see also man chkconfig)

    Thanks for the script! You definitely saved my day!

  2. For CentOS 6.2, I am having trouble. I left DAEMON=/usr/bin/tracd as that’s where trac installed.

    But when I try to start the service it shoots back an error;
    Starting tracd: Error writing to pid file: IOError: [Errno 2] No such file or directory: ‘/var/run/’

    I thought the script generated the pid file? Otherwise I will have to lookup how to create one.

    1. Yes the script will generate the pid file, please note that /var/run is a root directory, this might be a privilege issue, are you starting it from /etc/init.d ? Did you create the script with the root group?
      You can also change the pid file location in the script PIDFILE=/var/run/$ and quickly see if this is a directory/privilege issue

  3. Thought this script would be just the job to finish off and automate the installation.

    On a CentOS 5.8 based server ( and have the same problems with it trying to create the PID file.

    Starting tracd: Error writing to pid file: IOError: [Errno 2] No such file or directory: ‘/var/run/’

    Have tried all manner of options with file permissions and locations, all to no avail. It also won’t write a PID file from the command prompt either.

    Anyone have any bright ideas why this won’t work ? I’m out of ideas !!!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s