#!/bin/sh # # description: Perforce software configuration management (SCM) server # p4d_config=/var/perforce/p4d.config p4d=/usr/sbin/p4d p4_bin=/usr/bin id=/usr/xpg4/bin/id # Source Perforce configuration. [ -f ${p4d_config} ] && . ${p4d_config} export P4JOURNAL P4PORT P4ROOT P4USER P4PASSWD P4LOG umask $P4UMASK # See how we were called. case "$1" in 'start') printf "%s" "Starting p4d: " # Make sure the log is writeable by the perforce admin [ -f $P4LOG ] || touch $P4LOG chown perforce:perforce $P4LOG if [ -f ${p4d_config} -a -x ${p4d} ]; then if [ `$id -u` -eq 0 ]; then env=`grep -v "^#" ${p4d_config} | tr "\n" ' '` exec su - perforce -c "umask $P4UMASK; $env ${p4d} &"& else ${p4d} & fi echo "done." else echo "can't find ${p4d_config} or ${p4d}!" fi echo ;; 'stop') printf "%s" "Stopping p4d: " { ${p4_bin}/p4 admin stop 2>/dev/null && echo 'p4d shutdown'; } || { /usr/bin/pkill -x -u perforce -P 1 p4d && echo 'killed p4d'; } RETVAL=$? echo exit $RETVAL ;; 'restart') $0 stop $0 start ;; *) echo "Usage: p4d {start|stop|restart}" exit 1 ;; esac exit 0