#!/bin/bash #------------------------------------------------------------------------------ # Copyright (c) Perforce Software, Inc., 2007-2014. All rights reserved # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1 Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE # SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. #------------------------------------------------------------------------------ # # Mail to the administrator gets sent here: export MAILTO=REPL_MAILTO export P4USER=REPL_ADMINUSER export P4SERVICEUSER=REPL_SVCUSER export OSUSER=REPL_OSUSER export SDP_VERSION="REPL_SDPVERSION" AWK=awk CUT=cut DF="df -h" GREP=grep ID=id MAIL=mail PS=ps OS=`uname` if [ "${OS}" = "SunOS" ] ; then AWK=/usr/xpg4/bin/awk ID=/usr/xpg4/bin/id MAIL=mailx elif [ "${OS}" = "AIX" ] ; then DF="df -m" fi export AWK export ID export MAIL export DF # Which perforce instance are we configuring? Defaults to 1. export P4INSTANCE=${1:-1} export SDP_CLUSTER=REPL_SDP_CLUSTER export P4HOME="/p4/${P4INSTANCE}" # Leave P4PORT empty here. export P4PORT= # The P4INSTANCE value is intended to uniquely identify # a given set of Perforce databases within your enterprise. # # By default, P4INSTANCE is a simple integer value, e.g. # '1'. This drives many other values related to that # instance, such as where databases and checkpoints are # stored. For example, P4ROOT for instance 1 is, # /p4/1/root. # # Use the 'case' block to define a P4PORT value for each # P4INSTANCE where one or more of the following are true: # * You wish to use a tag name rather than the default of # a purely numeric value for P4INSTANCE value. (A short # tag name is recommended, e.g. 'ops'.) # * You will use the "ssl:" or other prefix, # * You need to specify the hostname component of P4PORT even # locally here on the server, as is necessary with some # multiple network interface card configurations, and/or # * You simply don't want to use the numeric calculation of # P4PORT based on an instance number. # # If you use named rather than numbered instances, you must # provide appropriate numeric values for the various # *PORT settings for services you wish to use, such as # P4PORT, P4WEBPORT, P4FTPPORT, etc. The 'abc' and 'sec' # values in the 'case' bloc below are samples. Replace # them with the desired values for your given instance name. # Leave SSL_PREFIX empty here. Set the value to "ssl:" # in the case block below for any instances using SSL. export SSL_PREFIX="" # Leave P4BROKERPORTNUM empty here. Set the value as # needed in the case block below. P4BROKERPORTNUM is # numeric portion of the P4PORT value used to reference # the broker. export P4BROKERPORTNUM="" # Leave P4MASTERPORTNUM empty here. P4MASTERPORTNUM is # the numeric portion of the port number used of the # P4PORT value used by the replica to access the master # server. Often this is the same as the P4PORTNUM # value defined below, but it can differ in some cases. # For example, if the P4PORT value defined on the master # uses the 'localhost:' prefix and replicas access the # master via a broker P4MASTERPORTNUM will be set to # $P4BROKERPORTNUM for that instance. export P4MASTERPORTNUM="" case $P4INSTANCE in (1) export P4WEBPORT=80 ;; (abc) export P4PORT=1742 export P4WEBPORT=8742 export P4FTPPORT=2022 export P4BROKERPORTNUM=1743 export P4MASTERPORTNUM=$P4BROKERPORTNUM ;; (sec) export SSL_PREFIX="ssl:" export P4PORT=${SSL_PREFIX}${P4PORT} ;; esac # If P4PORT is not defined in the case statement above, # and P4INSTANCE is a purely numeric value, calculate a # reasonable default for P4PORT based on the instance # number. if [[ -z "$P4PORT" ]]; then # Check to see whether $P4INSTANCE is purly numeric. if [[ $P4INSTANCE =~ ^[1-9]+[0-9]*$ ]]; then export P4PORT=${P4INSTANCE}REPL_P4PORT_END else echo -e "\nError: Could not determine P4PORT value for named instance [$P4INSTANCE].\n When using a named (rather than numbered) instance, adjust the\n 'case \$P4INSTANCE' block in /p4/common/bin/p4_vars, adding definitions\n for P4PORT and other values for that instance.\n\n" return 1 fi fi # If P4BROKERPORTNUM is not defined in the case statement above, # and P4INSTANCE is a purely numeric value, calculate a # reasonable default for P4BROKERPORTNUM based on the instance # number. if [[ -z "$P4BROKERPORTNUM" ]]; then # Check to see whether $P4INSTANCE is purly numeric. if [[ $P4INSTANCE =~ ^[1-9]+[0-9]*$ ]]; then export P4BROKERPORTNUM=${P4INSTANCE}REPL_P4BROKER_PORT_END else echo "Warning: Could not determine P4BROKERPORTNUM value for instance [$P4INSTANCE]." fi fi # p4d tmp dir, used by init script to setup environment # this is okay to share, as the files are per pid export TMP=${P4HOME}/tmp export P4TMP=${P4HOME}/tmp export P4ROOT=${P4HOME}/root export P4JOURNAL=${P4HOME}/logs/journal export P4CONFIG=${P4HOME}/.p4config export P4TICKETS=${P4HOME}/.p4tickets export P4SSLDIR=${P4HOME}/ssl export DEPOTS=${P4HOME}/depots export CHECKPOINTS=${P4HOME}/checkpoints export LOGS=${P4HOME}/logs export P4LOG=${LOGS}/log export P4LOGS=$P4HOME/logs export P4CBIN=/p4/common/bin export P4CLIB=/p4/common/lib export PERL5LIB=$P4CLIB:${PERL5LIB:-} export PERLHOME=/opt/ActivePerl-5.16 export PATH=$P4HOME/bin:$P4CBIN:/p4/common/python/bin:$PERLHOME/bin:$PATH:. export MANPATH=$PERLHOME/man:${MANPATH:-} # P4PORTNUM is the always strictly the numeric portion of # P4PORT, even in cases where P4PORT contains a prefix # and/or hostname component. export P4PORTNUM=${P4PORT##*:} export P4MASTERPORTNUM=${P4MASTERPORTNUM:-$P4PORTNUM} # General Settings for replication and other muilt-server topologies. export P4MASTER=REPL_DNSNAME # The ACTIVE_NODE variable below is used only in a cluster # configuration. It determines whether a node of a cluster # is active or not, and is used to help avoid split-brain # scenarios. It is always true in a non-cluster environment, # and must be set to 'false' in 'case' blocks below for # inactive nodes in a cluser configuration. export ACTIVE_NODE=false # Some settings key off the current hostname. The SDP_HOST # value can set manually for testing; the default value is # the current hostname. Remove values that are not # relevant to a given host in that host case block. SDP_HOST=${SDP_HOST:-$(hostname)} case $SDP_HOST in (REPL_DNSNAME) export ACTIVE_NODE=true export P4REPLICA=FALSE export P4REPLICANAME= export PROXY_PORT=${SSL_PREFIX}$(($P4PORTNUM+2)) export PROXY_TARGET=${SSL_PREFIX}${P4MASTER}:${P4PORTNUM} ;; (REPL_REPHOST) export ACTIVE_NODE=true export P4REPLICA=TRUE export P4REPLICANAME=REPL_REPNAME ;; (REPL_PROXYHOST) export ACTIVE_NODE=true export PROXY_PORT=${SSL_PREFIX}${P4PORTNUM} export PROXY_TARGET=${SSL_PREFIX}${P4MASTER}:${P4PORTNUM} ;; (*) # This catch-call simplifies testing. It can be disabled # for optimal clarity in a live Production environment. export ACTIVE_NODE=true export P4REPLICA=FALSE export P4REPLICANAME= ;; esac if [[ $P4REPLICA == TRUE ]]; then export P4D_FLAGS="-d -p $P4PORT -r $P4ROOT -In $P4REPLICANAME" else export P4D_FLAGS="-d -p $P4PORT -r $P4ROOT" fi # P4Web Settings. export P4WEBPORT=${P4WEBPORT:-808${P4INSTANCE}} export P4WEBBIN=${P4HOME}/bin/p4web_${P4INSTANCE} export P4WEBLOG=${P4HOME}/logs/p4web.log export P4WEBARGS="-B -p $P4PORT -w $P4WEBPORT -U $OSUSER -L $P4WEBLOG" # P4FTP Settings. export P4FTPPORT=${P4FTPPORT:-202${P4INSTANCE}} export P4FTPBIN=${P4HOME}/bin/p4ftpd_${P4INSTANCE} export P4FTPLOG=${P4HOME}/logs/ftp.log export P4FTPARGS="-d -l $P4FTPPORT -p $P4PORT -u $OSUSER -L $P4FTPLOG" # P4Proxy Settings export P4PCACHE=$P4HOME/cache # Set KEEPCKPS to the number of checkpoint & journal files and their # corresponding log files to keep. Checkpoints and their log file are # numbered with the same journal counter number. Checkpoints/journals # and their logs are removed when daily_backup.bat or weekly_backup.bat # are run. The live_checkpoint.bat script does not remove. # Set KEEPCKPS=0 to avoid automated cleanup of checkpoints and logs. export KEEPCKPS=7 # Set KEEPLOGS to the number of server logs to keep, counting back from # the most recent. Server logs are numbered with their corresponding # journal counter number, since server logs are rotated when checkpoint # logs are rotated. Keep in mind that if scripts are set to run # more than once per day, this will not correspond to the number # of days, just the number of iterations of script calls. # KEEPLOGS affects all log files other than checkpoint logs, which are # governed by KEEPCKPS. # Set KEEPLOGS=0 to avoid automated cleanup of old server logs. export KEEPLOGS=31 # Don't change this; change or comment the above as needed export P4BIN=${P4HOME}/bin/p4_${P4INSTANCE} export P4DBIN=${P4HOME}/bin/p4d_${P4INSTANCE} export P4PBIN=${P4HOME}/bin/p4p_${P4INSTANCE} export P4BROKERBIN=${P4HOME}/bin/p4broker_${P4INSTANCE} export P4WEBBIN=${P4HOME}/bin/p4web_${P4INSTANCE} # Define *_VERSION values. These will look like "2014.1.899321" # or "2015.1_BETA.903064". For example, to specify behavior specific # to 2014.1 or later P4D, test with [[ "$P4D_VERSION" > "2014.1" ]]. # That expression will be true 2014.1 and any subsequent release. Since # the values contain the patch number, all releases of "2014.1.*" will # be greater than the string "2014.1", so "greater than or equal to" is # implied. [[ -x $P4BIN ]] && export P4_VERSION=$($P4BIN -V|$GREP ^Rev.|$CUT -d '/' -f 3).$($P4BIN -V|$GREP ^Rev.|$CUT -d '/' -f 4|$CUT -d ' ' -f 1) [[ -x $P4DBIN ]] && export P4D_VERSION=$($P4DBIN -V|$GREP ^Rev.|$CUT -d '/' -f 3).$($P4DBIN -V|$GREP ^Rev.|$CUT -d '/' -f 4|$CUT -d ' ' -f 1) # Set version values for optional executables. [[ -x $P4PBIN ]] && export P4P_VERSION=$($P4PBIN -V|$GREP ^Rev.|$CUT -d '/' -f 3).$($P4PBIN -V|$GREP ^Rev.|$CUT -d '/' -f 4|$CUT -d ' ' -f 1) [[ -x $P4BROKERBIN ]] && export P4BROKER_VERSION=$($P4BROKERBIN -V|$GREP ^Rev.|$CUT -d '/' -f 3).$($P4BROKERBIN -V|$GREP ^Rev.|$CUT -d '/' -f 4|$CUT -d ' ' -f 1) [[ -x $P4WEBBIN ]] && export P4WEB_VERSION=$($P4WEBBIN -V|$GREP ^Rev.|$CUT -d '/' -f 3).$($P4WEBBIN -V|$GREP ^Rev.|$CUT -d '/' -f 4|$CUT -d ' ' -f 1) export P4_VARS_LOADED=1