#!/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 #------------------------------------------------------------------------------ export SDP_INSTANCE=${SDP_INSTANCE:-Unset} export SDP_INSTANCE=${1:-$SDP_INSTANCE} if [[ $SDP_INSTANCE == Unset ]]; then echo -e "\nError: Instance parameter not supplied.\n" echo "You must supply the Perforce instance as a parameter to this script." exit 1 fi # Load SDP controlled shell environment. source /p4/common/bin/p4_vars "$SDP_INSTANCE" ||\ { echo -e "\nError: Failed to load SDP environment.\n"; exit 1; } source $P4CBIN/backup_functions.sh ||\ { echo -e "\nError: Failed to load SDP backup_functions.sh lib.\n"; exit 1; } cd $P4CBIN || { echo -e "\nError: Failed to cd to $P4CBIN.\n"; exit 1; } common_dir=`pwd -P` if [[ -d $common_dir ]]; then cd $common_dir || { echo -e "\nError: Failed to cd to $common_dir.\n"; exit 1; } else echo $common_dir does not exist. exit 1 fi ######### Start of Script ########## check_vars set_vars export LOGFILE=$LOGS/upgrade.$P4SERVER.log.$(date +'%Y%m%d-%H%M') echo "Processing. This may take a few minutes depending on time to rotate the active journal and replay to the offline_db." echo "Log file is: $LOGFILE" check_dirs check_uid [[ -f $common_dir/p4 ]] || { echo "No p4 in $common_dir" ; exit 1 ;} [[ -f $common_dir/p4d ]] || { echo "No p4d in $common_dir" ; exit 1 ;} chmod 755 $common_dir/p4 chmod 700 $common_dir/p4d [[ -f $common_dir/p4broker ]] && chmod 700 $common_dir/p4broker [[ -f $common_dir/p4p ]] && chmod 700 $common_dir/p4p P4RELNUM=`./p4 -V | grep -i Rev. | $AWK -F / '{print $3}'` P4DRELNUM=`./p4d -V | grep -i Rev. | $AWK -F / '{print $3}'` P4BLDNUM=`./p4 -V | grep -i Rev. | $AWK -F / '{print $4}' | awk '{print $1}'` P4DBLDNUM=`./p4d -V | grep -i Rev. | $AWK -F / '{print $4}' | awk '{print $1}'` CURRENT_RELNUM=`./p4d_${SDP_INSTANCE}_bin -V | grep -i Rev. | $AWK -F / '{print $3}'` log "Start $P4SERVER Upgrade on $(hostname)." [[ -f p4_$P4RELNUM.$P4BLDNUM ]] || cp p4 p4_$P4RELNUM.$P4BLDNUM [[ -f p4d_$P4DRELNUM.$P4DBLDNUM ]] || cp p4d p4d_$P4DRELNUM.$P4DBLDNUM [[ -f p4_${P4RELNUM}_bin ]] && unlink p4_${P4RELNUM}_bin ln -s p4_$P4RELNUM.$P4BLDNUM p4_${P4RELNUM}_bin >> "$LOGFILE" 2>&1 [[ -f p4d_${P4DRELNUM}_bin ]] && unlink p4d_${P4DRELNUM}_bin ln -s p4d_$P4DRELNUM.$P4DBLDNUM p4d_${P4DRELNUM}_bin >> "$LOGFILE" 2>&1 [[ -f p4_bin ]] && unlink p4_bin ln -s p4_${P4RELNUM}_bin p4_bin >> "$LOGFILE" 2>&1 if [[ -L p4broker_${SDP_INSTANCE}_bin ]]; then if [[ -x /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init stop >> $LOGFILE 2>&1 fi P4BRELNUM=`./p4broker -V | grep -i Rev. | $AWK -F / '{print $3}'` P4BBLDNUM=`./p4broker -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'` [[ -f p4broker_$P4BRELNUM.$P4BBLDNUM ]] || cp p4broker p4broker_$P4BRELNUM.$P4BBLDNUM [[ -L p4broker_${P4BRELNUM}_bin ]] && unlink p4broker_${P4BRELNUM}_bin ln -s p4broker_$P4BRELNUM.$P4BBLDNUM p4broker_${P4BRELNUM}_bin [[ -L p4broker_${SDP_INSTANCE}_bin ]] && unlink p4broker_${SDP_INSTANCE}_bin ln -s p4broker_${P4BRELNUM}_bin p4broker_${SDP_INSTANCE}_bin if [[ -x /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init start >> $LOGFILE 2>&1 fi fi if [[ -L p4p_${SDP_INSTANCE}_bin ]]; then if [[ -x /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init stop >> $LOGFILE 2>&1 fi P4PRELNUM=`./p4p -V | grep -i Rev. | $AWK -F / '{print $3}'` P4PBLDNUM=`./p4p -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'` [[ -f p4p_$P4PRELNUM.$P4PBLDNUM ]] || cp p4p p4p_$P4PRELNUM.$P4PBLDNUM [[ -L p4p_${P4PRELNUM}_bin ]] && unlink p4p_${P4PRELNUM}_bin ln -s p4p_$P4PRELNUM.$P4PBLDNUM p4p_${P4PRELNUM}_bin [[ -L p4p_${SDP_INSTANCE}_bin ]] && unlink p4p_${SDP_INSTANCE}_bin ln -s p4p_${P4PRELNUM}_bin p4p_${SDP_INSTANCE}_bin if [[ -x /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init start >> $LOGFILE 2>&1 fi fi $P4CBIN/p4login -v >> $LOGFILE 2>&1 if [[ -x /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init ]]; then if [[ "$P4REPLICA" == "FALSE" ]] || [[ $EDGESERVER -eq 1 ]]; then get_journalnum fi /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init stop >> $LOGFILE 2>&1 fi # Don't upgrade the database for minor upgrades if [[ $CURRENT_RELNUM != $P4DRELNUM ]]; then # Only rotate the journal on the master. if [[ "$P4REPLICA" == "FALSE" ]] && [[ $EDGESERVER -eq 0 ]]; then p4d_truncate_journal get_offline_journal_num replay_journals_to_offline_db fi unlink p4d_${SDP_INSTANCE}_bin >> "$LOGFILE" 2>&1 ln -s p4d_${P4DRELNUM}_bin p4d_${SDP_INSTANCE}_bin >> "$LOGFILE" 2>&1 log "Upgrading databases in $P4ROOT." $P4DBIN -r $P4ROOT -J off -xu >> "$LOGFILE" 2>&1 # Upgrade the offline database on the master and on edge servers. if [[ "$P4REPLICA" == "FALSE" ]] || [[ $EDGESERVER -eq 1 ]]; then log "Upgrading databases in $OFFLINE_DB" # The value of '-t localhost:0000' is necessary for syntax reasons; # it is ignored. This allows upgade of offline databases without needing # a license file; there isn't one in offline_db, only P4ROOT. A valid # license file is required to actually start the server process and have # it listen on a port. $P4DBIN -r $OFFLINE_DB -J off -xu -t localhost:0000 >> "$LOGFILE" 2>&1 fi fi if [[ -x /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init start >> $LOGFILE 2>&1 sleep 1 fi if [[ "$P4REPLICA" == "FALSE" && $EDGESERVER -eq 0 ]]; then log "Upgrading protections table comment format." $P4BIN protect --convert-p4admin-comments -o | $P4BIN protect -i fi log "Finished $P4SERVER Upgrade" cat $LOGFILE
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 25113 | Robert Cowham | Merge latest changes from dev | ||
#5 | 23430 | Robert Cowham | Merge in changes from dev | ||
#4 | 23205 | Robert Cowham | Merged all changes from dev to test | ||
#3 | 22142 | Robert Cowham | Merge in latest changes from Dev | ||
#2 | 20726 | Robert Cowham | Catch up from dev | ||
#1 | 18586 | Robert Cowham | Branching using cowhamr.sdp.dev | ||
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/upgrade.sh | |||||
#9 | 16563 | C. Thomas Tyler |
Routine Merge Down to dev from main using: p4 merge -b perforce_software-sdp-dev p4 resolve -as |
||
#8 | 16029 | C. Thomas Tyler |
Routine merge to dev from main using: p4 merge -b perforce_software-sdp-dev |
||
#7 | 15778 | C. Thomas Tyler | Routine Merge Down to dev from main. | ||
#6 | 15374 | adrian_waters |
- Ensure backup scripts are run as the OSUSER (to prevent accidental running as root); - in scripts where LOGFILE value is changed from the 'checkpoint.log' set by set_vars, ensure the new assignment is before check_dirs is called, otherwise errors could be written to the 'wrong' log - in 'die()' - detect if running from terminal & also send output to stderr |
||
#5 | 13906 | C. Thomas Tyler |
Normalized P4INSTANCE to SDP_INSTANCE to get Unix/Windows implementations in sync. Reasons: 1. Things that interact with SDP in both Unix and Windows environments shoudn't have to account for this obscure SDP difference between Unix and Windows. (I came across this doing CBD work). 2. The Windows and Unix scripts have different variable names for defining the same concept, the SDP instance. Unix uses P4INSTANCE, while Windows uses SDP_INSTANCE. 3. This instance tag, a data set identifier, is an SDP concept. I prefer the SDP_INSTANCE name over P4INSTANCE, so I prpose to normalize to SDP_INSTANCE. 4. The P4INSTANCE name makes it look like a setting that might be recognized by the p4d itself, which it is not. (There are other such things such as P4SERVER that could perhaps be renamed as a separate task; but I'm not sure we want to totally disallow the P4 prefix for variable names. It looks too right to be wrong in same cases, like P4BIN and P4DBIN. That's a discussion for another day, outside the scope of this task). Meanwhile: * Fixed a bug in the Windows 2013.3 upgrade script that was referencing undefined P4INSTANCE, as the Windows environment defined only SDP_INSTANCE. * Had P4INSTANCE been removed completely, this change would likely cause trouble for users doing updates for existing SDP installations. So, though it involves slight technical debt, I opted to keep a redundant definition of P4INSTANCE in p4_vars.template, with comments indicating SDP_INSTANCE should be used in favor of P4INSTANCE, with a warning that P4INSTANCE may go away in a future release. This should avoid unnecessary upgrade pain. * In mkdirs.sh, the varialbe name was INSTANCE rather than SDP_INSTANCE. I changed that as well. That required manual change rather than sub/replace to avoid corrupting other similar varialbe names (e.g. MASTERINSTANCE). This is a trivial change technically (a substitute/replace, plus tweaks in p4_vars.template), but impacts many files. |
||
#4 | 12169 | Russell C. Jackson (Rusty) |
Updated copyright date to 2015 Updated shell scripts to require an instance parameter to eliminate the need for calling p4master_run. Python and Perl still need it since you have to set the environment for them to run in. Incorporated comments from reviewers. Left the . instead of source as that seems more common in the field and has the same functionality. |
||
#3 | 11485 | Russell C. Jackson (Rusty) |
Brought over changes from RCJ sdp to properly handle Edge servers and to properly replicate shelves when replicating from Windows to Linux |
||
#2 | 11463 | Russell C. Jackson (Rusty) | Updated dev to prepare for Summit agreed changes. | ||
#1 | 10638 | C. Thomas Tyler | Populate perforce_software-sdp-dev. | ||
//guest/perforce_software/sdp/main/Server/Unix/p4/common/bin/upgrade.sh | |||||
#1 | 10148 | C. Thomas Tyler | Promoted the Perforce Server Deployment Package to The Workshop. |