Sunday, October 21, 2007

Perforce Init Script

I'm playing around with perforce. Their installation packages leave a bit to be desired. You download the binaries off of their website and drop them into your file system.

I wrote this init script to help start it up on Redhat/CentOS systems:


#!/bin/bash

# chkconfig: 345 90 50
# description: perforce (p4d) is a SCM system.
# processname: /usr/sbin/p4d
# config: /etc/sysconfig/p4d

P4D=/usr/sbin/p4d
P4=/usr/bin/p4

P4ROOT=/var/perforce
P4JOURNAL=/var/perforce/journal
P4LOG=/var/log/p4err
P4PORT=1666
P4USER=perforce
OPTIONS=""

prog="p4d"

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/p4d ]; then
. /etc/sysconfig/perforce
fi


case $1 in
start)
echo -n "Starting $prog: "
daemon --check $P4D --user $P4USER "$P4D -r $P4ROOT -J $P4JOURNAL -L $P4LOG -p $P4PORT -d $OPTIONS 2>&1 > /dev/null"
echo
stop)
echo -n "Stopping $prog: "
killproc $prog
echo
;;
*)
echo "Usage: $0 ( start | stop )"
esac

My script runs perforce as a non-root user. By default, it expects the p4d to be in /usr/sbin and that you have a perforce user. I call this script /etc/init.d/p4d.

I may write a spec file to allow creation of an RPM.

I also want to add a 'backup' option for easy maintenance.

*UPDATE*

I switched the init script to use daemon instead of su.

No comments: