#!/bin/bash declare BrokerPid= declare TmpP4ROOT=$HMS_TEST_HOME/tmp/.p4root declare -i Debug=1 source ./env.sh function msg () { echo -e "$*"; } function dbg () { [[ $Debug -eq 1 ]] || return; echo -e "DEBUG: $*" >&2; } function cmd () { msg "Executing: $*"; $*; return $?; } function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit ${2:-1}; } function get_broker_pid () { pid=$(ps -ef | grep "$P4BROKERBIN" | grep -v " grep " | \ awk '{print $2}' | head -1) echo $pid } case ${1:-status} in (start) cd "$HMS_TEST_HOME" || bail "Failed to cd to $HMS_TEST_HOME." cmd $P4BROKERBIN -c $HMS_TEST_HOME/broker.cfg -q -d # Start a helper p4d. It does nothing, but needs to be running, # otherwise the broker can't do anything accept a 'reject' or # 'redirect' action. unset P4JOURNAL P4PORT P4AUDIT P4DEBUG P4CHANGE P4AUTH P4LOG rm -rf $TmpP4ROOT mkdir -p $TmpP4ROOT cmd p4d -r $TmpP4ROOT -p 4738 -q -d --pid-file ;; (stop) if [[ -r "$TmpP4ROOT/server.pid" ]]; then msg "Killing helper p4d." cmd kill $(cat $TmpP4ROOT/server.pid) fi BrokerPid=$(get_broker_pid) if [[ -n "$BrokerPid" ]]; then msg "Killing broker." cmd kill $BrokerPid else msg Broker not running. fi ;; (status) if [[ -r "$TmpP4ROOT/server.pid" ]]; then msg "Helper p4d appears to be running." else msg "Helper p4d is not running." fi BrokerPid=$(get_broker_pid) if [[ -n "$BrokerPid" ]]; then msg Broker is running as pid $BrokerPid. else msg Broker is not running. fi ;; (*) msg "\nUsage:\n\t${0##*/} {start|stop|status}\n" ;; esac