#!/bin/bash Version=1.0.5 # Usage: failover_p4d_from_this_host.sh SDP_INSTANCE Style Type BackupHost NO_OP # This is intended to be called by 'hms', not directly by a human. # Micro-functions. function msg () { echo -e "$*"; } function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit ${2:-1}; } function usage () { msg "Usage:\n\t$UsageSummary\n"; exit 2; } function cmd () { if [[ $NO_OP -eq 0 ]]; then msg "Running: $*" $* return $? else msg "NO_OP: Would run: $*" fi } # Do nothing unless usage is correct. export SDP_INSTANCE=${1:-Unset} declare Style=${2:-Unset} declare Type=${3:-Unset} declare BackupHost=${4:-Unset} declare NO_OP=${5:-Unset} declare ThisScript=${0##*/} declare UsageSummary="$ThisScript SDP_INSTANCE Style Type BackupHost NO_OP" declare P4DInitScript=/p4/$SDP_INSTANCE/bin/p4d_${SDP_INSTANCE}_init [[ $# -eq 5 ]] || bail "Bad Usage! Usage:\n\t$UsageSummary\n" msg "Starting $ThisScript v$Version on ${HOSTNAME%%.*} at $(date)." msg "Args: I=$SDP_INSTANCE S=$Style T=$Type BH=$BackupHost NO_OP=$NO_OP" # Load SDP controlled shell environment. source /p4/common/bin/p4_vars "$SDP_INSTANCE" || \ bail "Failed to load SDP environment for instance $SDP_INSTANCE." [[ $(id -u -n) == $OSUSER ]] || bail "$0 can only be run by $OSUSER" [[ $NO_OP -eq 1 ]] && msg "NO_OP: Preview Mode Enabled." [[ -x $P4DInitScript ]] || bail "$P4DInitScript is not executable." # For unscheduled failover, we attempt to top the server to prevent # split brain, and nothing more. The host alias must be also be # changed externally to this automation. cmd $P4DInitScript stop [[ ${SERVERID^^} == *"MASTER"* ]] ||\ bail "Instance $SDP_INSTANCE ServerID ($SERVERID) indicates it not a master server! Aborting further failover processing on host ${HOSTNAME%%.*}." # For scheduled failover, we go further and preserve the original journal # file verbatim. if [[ $Style == Scheduled ]]; then cmd scp -q -p $P4JOURNAL $BackupHost:$P4JOURNAL.from_old_master ||\ bail "Failed to scp $P4JOURNAL to backup host $BackupHost:$P4JOURNAL.from_old_master." fi
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 25113 | Robert Cowham | Merge latest changes from dev | ||
#1 | 22142 | Robert Cowham | Merge in latest changes from Dev | ||
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/hms/scripts/failover_p4d_from_this_host.sh | |||||
#2 | 21921 | C. Thomas Tyler |
HMS change, to simplify setup on compliant platforms (i.e. those using bash 4.x). The shebang line for all bash scripts has been standardized to /bin/bash, and bash checks for $BASH_VERSION added where needed. References to having a custom-built /usr/local/bin/bash have been removed. As a trade-off, non-compliant platforms (way-old Linux and Mac using bash 3.x) will have a bit more work to do to work with shebang lines. |
||
#1 | 20745 | C. Thomas Tyler |
Approving as is since it isn't changing core SDP functionality, and reviewing it all line by line will take some time. We can do that as we move forward with it. First addition of HMS v1.0 files. This change is a soft launch HMS for initial deployment and testing. Updates to HMS-related files are expected and will bypass pre-commit code review until stabilized. |