#!/bin/bash #============================================================================== # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE #------------------------------------------------------------------------------ # # Use "chkconfig --add p4broker_REPL_SDP_INSTANCE_init" to set up the script # to start and stop automatically. # # Perforce Init Script. # chkconfig: - 90 30 # description: Start Perforce broker instance REPL_SDP_INSTANCE # Usage: p4broker_REPL_SDP_INSTANCE_init start|stop|status|restart [|all] # The ConfigTag can use the special values 'all'. For example, # 'p4d_REPL_SDP_INSTANCE_init status all' can be used to determine # which broker configuration(s) are running. When starting mulitple # broker configurations, be sure they are not configured to listen on # the same port. If ConfigTag is omitted, it is the equivalent of # specifying 'default'. # # The default broker config is /p4/common/config/p4_N.broker.cfg, (where # N is the instance name), which can be overridden on specifc machines if # there exists a file named /p4/common/config/p4_N.broker..cfg. # # Additional broker config files can be defined by creating broker config # files named /p4/common/config/p4_N.broker.YourTagName.cfg, e.g. # /p4/common/config/p4_N.broker.dfm.cfg (the "Down For Maintenance" config # file.). declare OpMode=${1:-status} declare ConfigTag=${2:-default} declare ConfigTagList= declare -i ExitStatus=0 # Load SDP shell environment for Instance REPL_SDP_INSTANCE. source /p4/common/bin/p4_vars REPL_SDP_INSTANCE || exit 1 if [[ "$ConfigTag" == "all" ]]; then ConfigTagList="default $(cd ${P4CCFG}; ls ${P4SERVER}.broker.*.cfg | cut -d '.' -f 3)" ConfigTagList=$(echo $ConfigTagList) else ConfigTagList=$ConfigTag fi for tag in $ConfigTagList; do if [[ $tag == default ]]; then if [[ -r /p4/common/config/${P4SERVER}.broker.${HOSTNAME%%.*}.cfg ]]; then export P4BROKERCFG=${P4CCFG}/${P4SERVER}.broker.${HOSTNAME%%.*}.cfg else export P4BROKERCFG=${P4CCFG}/${P4SERVER}.broker.cfg fi else export P4BROKERCFG=${P4CCFG}/${P4SERVER}.broker.${tag}.cfg fi if [[ ! -r "$P4BROKERCFG" ]]; then echo -e "\nError: Missing broker config file $P4BROKERCFG.\n" ExitStatus=1 continue fi $P4CBIN/p4broker_base "$OpMode" "$tag" || ExitStatus=1 done exit $ExitStatus