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

#!/bin/bash
#
# chkconfig: - 85 15
# description: tracd
# processname: tracd
# pidfile: /var/run/tracd.pid

# 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 
ENV_PARENT_DIR=
PROJECT_ENV=/myproject/trac
PORT=9090
# 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"

DAEMON=/usr/bin/tracd
NAME=tracd
DESC="web server"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

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"
else
        DAEMON_OPTS="$DAEMON_OPTS $PROJECT_ENV"
fi

LOCKFILE=${LOCKFILE-/var/lock/subsys/tracd}
RETVAL=0


start() {
        if [ -a $LOCKFILE ];
        then
                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;
        fi

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

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

exit $RETVAL

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

in particular, I created
/myproject/trac/htpasswd
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!

Advertisements

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

  1. For CentOS 5.7, I needed:
    #! /bin/bash ( _ required between “!” and “/bin..”)
    and
    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/tracd.pid’

    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/$NAME.pid 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 (www.contribs.org) 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/tracd.pid’

    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:

WordPress.com Logo

You are commenting using your WordPress.com 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