#!/usr/local/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 #------------------------------------------------------------------------------ #============================================================================== # Declarations and Environment set -u EnvFile=/p4/common/bin/p4_vars if [[ -r "$EnvFile" ]]; then source "$EnvFile" hms else echo -e "\n\nERROR: The environment file $EnvFile is missing.\n\n" exit 1 fi if [[ $(id -u) -eq 0 ]]; then exec su - $OSUSER -c "$0 $*" elif [[ $(id -u -n) != $OSUSER ]]; then echo "$0 can only be run by root or $OSUSER" exit 1 fi # Allow override of P4U_HOME, which is set only when testing P4U utility scripts. export P4U_HOME=${P4U_HOME:-$P4CBIN} export P4U_LIB=${P4U_LIB:-$P4CLIB} export P4U_ENV=$P4U_LIB/p4u_env.sh export P4U_LOG=Unset export HMS_HOME=${HMS_HOME:-/p4/common/hms} export HMS_SCRIPTS=$HMS_HOME/scripts # Indicate whether we are called by the broker wrapper. export HMS_CALLED_BY_WRAPPER=${HMS_CALLED_BY_WRAPPER:-0} # Load bash libs. declare BASH_LIBS=$P4U_ENV BASH_LIBS+=" $P4U_LIB/libcore.sh" BASH_LIBS+=" $P4U_LIB/libp4u.sh" BASH_LIBS+=" $P4U_LIB/hms_actions.sh" BASH_LIBS+=" $P4U_LIB/hms_load_and_verify.sh" for bash_lib in $BASH_LIBS; do source $bash_lib done # After sourcing bash libs, set default VERBOSITY for this program, which can # be overridden on the command line. export VERBOSITY=3 # SDP Instance data, with associative arrays (i.e. arrays that can be indexed # by a string rather than a purely numeric name). These Instance* vars are # indexed by the SDP instance name. declare -A InstanceUserPorts declare -A InstanceMasterHost declare -A InstanceServerPort declare -A InstanceBrokerPort declare -A InstanceManaged declare -A InstanceDesc declare -A InstanceComponents declare -A InstanceFailoverOptions # Helix Topology Components data, indexed by the fully qualified component name # of the form "SDPInstance:ComponentName", e.g. "1:p4d-r01". declare -A ComponentType declare -A ComponentMasterHost declare -A ComponentURL declare -A ComponentBackupHost declare -A ComponentManaged declare -A ComponentDesc declare -A ComponentStatusCode declare -A ComponentStatusMsg declare -A ComponentMajorVersion declare -A ComponentMinorVersion declare -A ComponentVersion # Failover Options, indexed by the fully qualified failover option name of the # form "SDPInstance:FailoverOptionName", e.g. "1:dr". declare -A FailoverType declare -A FailoverMasterHost declare -A FailoverBackupHost declare -A FailoverInstanceList declare -A FailoverActive declare -A FailoverDesc declare -i SilentMode=0 # Increment the Version manually on each submit. (We avoid +k filetype of # Perforce due to various complications moving across p4d instances). declare Version=1.0.26 # The RequiredCfgVersion check is done with a lexiographic compare vs. # the value defined in the Helix Topology file. Helix Topology files define # their file format version with 3 digits, e.g. 3.0.0 or 3.0.1. The # RequiredCfgVersion here must be defined with two digits, e.g. "3.0" if #"3.0.0" is good enough, since 3.0.0 is lexiographically greater than 3.0. declare RequiredCfgVersion=1.0 #============================================================================== # Local Functions #------------------------------------------------------------------------------ # Function: terminate function terminate { # Disable signal trapping. trap - EXIT SIGINT SIGTERM # Don't litter. cleanTrash vvmsg "$THISSCRIPT: EXITCODE: $OverallReturnStatus" # Stop logging. [[ "${P4U_LOG}" == off ]] || stoplog # With the trap removed, exit. exit $OverallReturnStatus } #------------------------------------------------------------------------------ # Function: usage (required function) # # Input: # $1 - style, either -h (for short form) or -man (for man-page like format). # The default is -h. # # $2 - error message (optional). Specify this if usage() is called due to # user error, in which case the given message displayed first, followed by the # standard usage message (short or long depending on $1). If displaying an # errror, usually $1 should be -h so that the longer usage message doesn't # obsure the error message. # # Sample Usage: # usage # usage -h # usage -man # usage -h "Incorrect command line usage." #------------------------------------------------------------------------------ function usage { declare style=${1:--h} declare errorMessage=${2:-Unset} if [[ $errorMessage != Unset ]]; then echo -e "\n\nUsage Error:\n\n$errorMessage\n\n" fi echo -e "USAGE for $THISSCRIPT v$Version: $THISSCRIPT show $THISSCRIPT status {all|[:]} [-o] $THISSCRIPT {start|stop} {all|[:]} $THISSCRIPT dfm {start|stop|status} {all|} $THISSCRIPT {update|upgrade} all|[:] $THISSCRIPT failover {i|h}: