mkdirs.sh #15

  • //
  • guest/
  • russell_jackson/
  • sdp/
  • Server/
  • Unix/
  • setup/
  • mkdirs.sh
  • View
  • Commits
  • Open Download .zip Download (14 KB)
#!/bin/bash
#
# Change the first three variables below to match the volume names on the machine
# you are configuring the SDP on. 
# Set the remaining variables appropriately. The meaning of each should be obvious.
#
# In the SDP variable below, the sdp directory needs to contain the contents of:
# //guest/perforce_software/sdp/main/...
#
# Run this script as root, and pass in the instance number you are configuring.
# If you do not have root access, then some commands will be skipped, and you will
# need to have the defined $P4DIR directory already existing (created
# by the root user and the ownership changed to the OS user that you are planning
# to run Perforce under). The Metadata, Depots and Logs volumes will also need
# to be owned by the OS user as well in order for the script to work. You can then
# run this script as the OS user for Perforce and everything should work fine.
#
# This script creates an init script in the $P4DIR/$SDP_INSTANCE/bin directory. You
# can use it from there if you are configuring a cluster, or you can link it in
# /etc/init.d if you are setting up a stand alone machine.  Sample systemd service
# files are included.
#
# After running this script, you also need to set up the crontab based on files
# in $P4DIR/common/etc/cron.d.  For convenience, crontab files are copied to 
# $P4DIR/p4.crontab and $P4DIR/p4.crontab.replica.
#
# Now, put the license file in place and launch the server with the init script.
#
# Then run $P4DIR/common/bin/p4master_run <instance> $P4DIR/common/bin/live_checkpoint.sh
# and then run both the daily_checkpoint.sh and recreate_db_checkpoint.sh to
# make sure everything is working before setting up the crontab.
#
# Also run $P4DIR/common/bin/p4master_run <instance> $P4DIR/common/bin/p4review.py <instance>
# to make sure the review script is working properly.  If you intend to use Swarm,
# you can skip configuration of the review daemon, and instead configure Swarm to
# handle review-style email notifications.
#
# UPGRADING SDP
# Specify the -test parameter to the script.
# In this case the script will NOT make the various directories under $P4DIR, but will instead
# create /tmp/p4 directory structure with the various files processed via templates etc.
# You can then manually compare this directory structure with your existing $P4DIR structure
# and manually copy the various files into it.
#

set -u

bail() {
   declare msg=$1
   echo -e "$msg\n\n" >&2
   exit 1
}

if [ $# -lt 1 ] || [ $# -gt 2 ]; then
   echo "Usage: $0 <instance> [-test]"
   exit 1
fi

# Verify instance value
SDP_INSTANCE=$1
if [[ "$SDP_INSTANCE" = "-test" ]]; then
    echo "Error: An instance argument is required."
    exit 1
fi

# Note that if the following is set to 1 then a trial run is done, into /tmp/p4
TEST=0
if [[ $# -gt 1 ]] && [[ "$2" = "-test" ]]; then
   TEST=1
fi

# Check for config file - same dir as this script
mkdirs_config="${0%/*}/mkdirs.cfg"
source $mkdirs_config || bail "Error: failed to source $mkdirs_config"

P4DIR=/p4
P4SERVER=p4_$SDP_INSTANCE

export AWK=awk
export ID=id
export MAIL=mail

OS=`uname`
if [[ "${OS}" = "SunOS" ]] ; then
  export AWK=/usr/xpg4/bin/awk
  export ID=/usr/xpg4/bin/id
  export MAIL=mailx
elif [[ "${OS}" = "AIX" ]] ; then
  export AWK=awk
  export ID=id
  export MAIL=mail
fi

if [[ `$ID -u` -eq 0 ]]; then
   echo "Verified: Running as root."
elif [[ `whoami` == $OSUSER ]]; then
   echo -e "\nWarning:  Not running as root; chown commands will be skipped and basic directories should exist.\n"
else
   echo -e "\nError: $0 must be run as as root or $OSUSER.\n"
   exit 1
fi

if [[ $TEST -eq 1 ]]; then
  DD=tmp
  MD=tmp
  LG=tmp
  CN=tmp
  P4DIR=/tmp/p4
  echo -e "\n*********  -test specified - will install to $DD/p4  *********\n"
fi

SDP_COMMON=$SDP/Server/Unix/p4/common

[[ -f $SDP_COMMON/bin/p4 ]] || { echo "No p4 in $SDP_COMMON/bin" ; exit 1 ;}
[[ -f $SDP_COMMON/bin/p4d ]] || { echo "No p4d in $SDP_COMMON/bin" ; exit 1 ;}

chmod 755 $SDP_COMMON/bin/p4
chmod 700 $SDP_COMMON/bin/p4d

[[ -f $SDP_COMMON/bin/p4broker ]] && chmod 700 $SDP_COMMON/bin/p4broker
[[ -f $SDP_COMMON/bin/p4p ]] && chmod 700 $SDP_COMMON/bin/p4p

# Make sure you update the p4 and p4d versions in the sdp/Server/Unix/p4/common/bin directory when making
# new instances at a later date.

P4RELNUM=`$SDP_COMMON/bin/p4 -V | grep -i Rev. | $AWK -F / '{print $3}'`
P4BLDNUM=`$SDP_COMMON/bin/p4 -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`
P4DRELNUM=`$SDP_COMMON/bin/p4d -V | grep -i Rev. | $AWK -F / '{print $3}'`
P4DBLDNUM=`$SDP_COMMON/bin/p4d -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`

[[ -d $P4DIR ]] || mkdir $P4DIR

[[ -d /$DD/p4 ]] || mkdir /$DD/p4
[[ -d /$DB1/p4 ]] || mkdir /$DB1/p4
[[ -d /$DB2/p4 ]] || mkdir /$DB2/p4
[[ -d /$LG/p4 ]] || mkdir /$LG/p4

mkdir -p /$LG/p4/$SDP_INSTANCE/bin
mkdir -p /$DD/p4/$SDP_INSTANCE/tmp
mkdir -p /$DD/p4/$SDP_INSTANCE/depots
CKPDIR=checkpoints

if [[ $SHAREDDATA == "TRUE" ]]; then
   if [[ $SERVER_TYPE == "p4d_edge" || $SERVER_TYPE == "p4d_edgerep" ]]; then
      CKPDIR=checkpoints.${MASTER_ID}
   fi
fi

mkdir -p /$DD/p4/$SDP_INSTANCE/${CKPDIR}

[[ -d $P4DIR/ssl ]] || mkdir -p $P4DIR/ssl
[[ -d $P4DIR/$SDP_INSTANCE ]] || mkdir -p $P4DIR/$SDP_INSTANCE
[[ -f $SDP/Server/Unix/p4/ssl/config.txt ]] && cp $SDP/Server/Unix/p4/ssl/config.txt $P4DIR/ssl/
[[ -d /$CN/p4/common/bin ]] || mkdir -p /$CN/p4/common/bin
[[ -d /$CN/p4/common/config ]] || mkdir -p /$CN/p4/common/config

mkdir -p /$DB1/p4/$SDP_INSTANCE/db1/save
mkdir -p /$DB2/p4/$SDP_INSTANCE/db2/save
mkdir -p /$LG/p4/$SDP_INSTANCE/journals.rep
mkdir -p /$LG/p4/$SDP_INSTANCE/logs

cd /$P4DIR/$SDP_INSTANCE

if [[ $TEST -eq 0 ]]; then
    [[ -L bin ]] || ln -s /$LG/p4/$SDP_INSTANCE/bin
    [[ -L journals.rep ]] || ln -s /$LG/p4/$SDP_INSTANCE/journals.rep
    [[ -L logs ]] || ln -s /$LG/p4/$SDP_INSTANCE/logs
    [[ -L checkpoints ]] || ln -s /$DD/p4/$SDP_INSTANCE/${CKPDIR} checkpoints
    [[ -L depots ]] || ln -s /$DD/p4/$SDP_INSTANCE/depots
    [[ -L tmp ]] || ln -s /$DD/p4/$SDP_INSTANCE/tmp
    [[ -L root ]] || ln -s /$DB1/p4/$SDP_INSTANCE/db1 root
    [[ -L offline_db ]] || ln -s /$DB2/p4/$SDP_INSTANCE/db2 offline_db
    cd $P4DIR
    [[ -L sdp ]] || ln -s $SDP $P4DIR/sdp
    [[ -L common ]] || ln -s /$CN/p4/common
fi

case "$SERVER_TYPE" in
    (p4d_master|p4d_edge) SERVERID=$MASTER_ID;;
    (*) SERVERID=$REPLICA_ID;;
esac
echo $SERVERID > $P4DIR/$SDP_INSTANCE/root/server.id
echo $SERVER_TYPE > $P4DIR/$SDP_INSTANCE/root/sdp_server_type.txt

[[ -f /$CN/p4/common/bin/p4_$P4RELNUM.$P4BLDNUM ]] || cp $SDP_COMMON/bin/p4 /$CN/p4/common/bin/p4_$P4RELNUM.$P4BLDNUM
[[ -f /$CN/p4/common/bin/p4d_$P4DRELNUM.$P4DBLDNUM ]] || cp $SDP_COMMON/bin/p4d /$CN/p4/common/bin/p4d_$P4DRELNUM.$P4DBLDNUM

if [[ ! -f /$CN/p4/common/bin/p4_vars ]]; then
  cp -R $SDP_COMMON/bin/* /$CN/p4/common/bin

  # Copy certain subdirs of /p4/common if don't already exist.
  for dir in etc; do
     if [[ ! -d /$CN/p4/common/$dir ]]; then
       cp -pr $SDP_COMMON/$dir /$CN/p4/common/.
     fi
  done

  cd /$CN/p4/common/bin
  ln -s p4_$P4RELNUM.$P4BLDNUM p4_${P4RELNUM}_bin
  ln -s p4d_$P4DRELNUM.$P4DBLDNUM p4d_${P4DRELNUM}_bin
  ln -s p4_${P4RELNUM}_bin p4_bin

fi

cd /$CN/p4/common/bin

ln -s p4d_${P4DRELNUM}_bin p4d_${SDP_INSTANCE}_bin

echo $P4ADMINPASS > /$CN/p4/common/config/.p4passwd.${P4SERVER}.admin

# Create broker links if broker exists
if [[ -f $SDP_COMMON/bin/p4broker ]]; then 
  P4BRELNUM=`$SDP_COMMON/bin/p4broker -V | grep -i Rev. | $AWK -F / '{print $3}'`
  P4BBLDNUM=`$SDP_COMMON/bin/p4broker -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`
  [[ -f /$CN/p4/common/bin/p4broker_$P4BRELNUM.$P4BBLDNUM ]] || cp $SDP_COMMON/bin/p4broker /$CN/p4/common/bin/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
  cd $P4DIR/$SDP_INSTANCE/bin
  [[ -L p4broker_${SDP_INSTANCE} ]] || ln -s $P4DIR/common/bin/p4broker_${SDP_INSTANCE}_bin p4broker_${SDP_INSTANCE}
  sed "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" $SDP_COMMON/etc/init.d/p4broker_instance_init.template > p4broker_${SDP_INSTANCE}_init
  chmod +x p4broker_${SDP_INSTANCE}_init
fi

# Create p4p links if p4p exists
cd /$CN/p4/common/bin
if [[ -x $SDP_COMMON/bin/p4p ]]; then 
  P4PRELNUM=`$SDP_COMMON/bin/p4p -V | grep -i Rev. | $AWK -F / '{print $3}'`
  P4PBLDNUM=`$SDP_COMMON/bin/p4p -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}'`
  [[ -f /$CN/p4/common/bin/p4p_$P4PRELNUM.$P4PBLDNUM ]] || cp $SDP_COMMON/bin/p4p /$CN/p4/common/bin/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
  cd $P4DIR/$SDP_INSTANCE/bin
  [[ -L p4p_${SDP_INSTANCE} ]] || ln -s $P4DIR/common/bin/p4p_${SDP_INSTANCE}_bin p4p_${SDP_INSTANCE}
  sed -e "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" \
    -e "s/REPL_DNSNAME/${P4DNSNAME}/g" \
    $SDP_COMMON/etc/init.d/p4p_instance_init.template > p4p_${SDP_INSTANCE}_init
  chmod +x p4p_${SDP_INSTANCE}_init
  mkdir -p /$DD/p4/$SDP_INSTANCE/cache
fi

cd $P4DIR/$SDP_INSTANCE/bin
ln -s $P4DIR/common/bin/p4_bin p4_$SDP_INSTANCE

sed "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" \
  $SDP_COMMON/etc/init.d/p4d_instance_init.template > p4d_${SDP_INSTANCE}_init
chmod +x p4d_${SDP_INSTANCE}_init

# Moved the less commonly used, but always created init scripts to an init directory.
mkdir init
cd init

sed "s/REPL_SDP_INSTANCE/${SDP_INSTANCE}/g" \
  $SDP_COMMON/etc/init.d/p4dtg_instance_init.template > p4dtg_${SDP_INSTANCE}_init
chmod +x p4dtg_${SDP_INSTANCE}_init

cd ..

if [[ $CASE_SENSITIVE -eq 1 ]]; then
  ln -s $P4DIR/common/bin/p4d_${SDP_INSTANCE}_bin p4d_$SDP_INSTANCE
else
  echo '#!/bin/bash' > p4d_$SDP_INSTANCE
  echo P4D=/p4/common/bin/p4d_${SDP_INSTANCE}_bin >> p4d_$SDP_INSTANCE
  echo 'exec $P4D -C1 "$@"' >> p4d_$SDP_INSTANCE
  chmod +x p4d_$SDP_INSTANCE
fi

cd $P4DIR/common/config

sed -e "s/REPL_MAILTO/${MAILTO}/g" \
  -e "s/REPL_MAILFROM/${MAILFROM}/g" \
  -e "s/REPL_ADMINUSER/${ADMINUSER}/g" \
  -e "s/REPL_MASTER_ID/${MASTER_ID}/g" \
  -e "s/REPL_SSLPREFIX/${SSL_PREFIX}/g" \
  -e "s/REPL_P4PORT/${P4_PORT}/g" \
  -e "s/REPL_P4BROKERPORT/${P4BROKER_PORT}/g" \
  -e "s/REPL_DNSNAME/${P4DNSNAME}/g" \
  -e "s/REPL_OSUSER/${OSUSER}/g" \
  $SDP_COMMON/config/instance_vars.template > p4_${SDP_INSTANCE}.vars

sed -e "s/REPL_ADMINISTRATOR/${MAILTO}/g" \
  -e "s/REPL_COMPLAINFROM/${COMPLAINFROM}/g" \
  -e "s/REPL_MAILHOST/${MAILHOST}/g" \
  -e "s/REPL_DNSNAME/${P4DNSNAME}/g" \
  $SDP_COMMON/config/p4review.cfg.template > p4_${SDP_INSTANCE}.p4review.cfg

cd $P4DIR/sdp/Maintenance

sed -e "s/REPL_ADMINISTRATOR/${MAILTO}/g" \
  -e "s/REPL_COMPLAINFROM/${COMPLAINFROM}/g" \
  -e "s/REPL_MAILHOST/${MAILHOST}/g" \
  -e "s/REPL_DOMAIN/${DOMAIN}/g" \
  template.maintenance.cfg > maintenance.cfg

cd $P4DIR
if [[ ! -f ${P4DIR}/p4.crontab ]]; then 
   CRONTAB_NAME=p4.crontab
else
   rm -f ${P4DIR}/p4.crontab.new > /dev/null 2>&1
   CRONTAB_NAME=p4.crontab.new
   echo "Existing crontab found, writing new crontab to ${CRONTAB_NAME}"
fi

sed -e "s/REPL_MAILTO/${MAILTO}/g" \
    -e "s/REPL_MAILFROM/${MAILFROM}/g" \
    -e "s/REPL_INSTANCE/${SDP_INSTANCE}/g" \
    $SDP_COMMON/etc/cron.d/template.crontab > ${CRONTAB_NAME} 

sed -e "s/REPL_MAILTO/${MAILTO}/g" \
    -e "s/REPL_MAILFROM/${MAILFROM}/g" \
    -e "s/REPL_INSTANCE/${SDP_INSTANCE}/g" \
    $SDP_COMMON/etc/cron.d/proxy.crontab > proxy.crontab 

cd $P4DIR/${SDP_INSTANCE}/bin

if [[ `$ID -u` -eq 0 ]]; then
   if [[ $TEST -eq 0 ]]; then
      chown $OSUSER:$OSGROUP /$DD
      chown $OSUSER:$OSGROUP /$LG
      chown $OSUSER:$OSGROUP /$DB1
      chown $OSUSER:$OSGROUP /$DB2
   fi
   chown $OSUSER:$OSGROUP /$DD/p4
   chown $OSUSER:$OSGROUP /$LG/p4
   chown $OSUSER:$OSGROUP /$DB1/p4
   chown $OSUSER:$OSGROUP /$DB2/p4
  
   chown -h $OSUSER:$OSGROUP $P4DIR
   chown -h $OSUSER:$OSGROUP $P4DIR/$SDP_INSTANCE
   chown -h $OSUSER:$OSGROUP $P4DIR/$SDP_INSTANCE/*
   chown -h $OSUSER:$OSGROUP $P4DIR/common
   chown -h $OSUSER:$OSGROUP $P4DIR/sdp
   chown $OSUSER:$OSGROUP $P4DIR/*
   chown $OSUSER:$OSGROUP $P4DIR/ssl/*

   chown -Rh $OSUSER:$OSGROUP $P4DIR/common
   chown -Rh $OSUSER:$OSGROUP $SDP
   chown -Rh $OSUSER:$OSGROUP /$CN/p4/common
   chown -Rh $OSUSER:$OSGROUP /$DB1/p4/$SDP_INSTANCE
   chown -Rh $OSUSER:$OSGROUP /$DB2/p4/$SDP_INSTANCE
   chown -Rh $OSUSER:$OSGROUP /$LG/p4/$SDP_INSTANCE

   if [[ "$SHAREDDATA" == "TRUE" ]]; then
      if [[ "$SERVER_TYPE" == p4d_master ]]; then
         echo "Setting ownership on depot files - this may take some time ..."
         chown -Rh $OSUSER:$OSGROUP /$DD/p4/$SDP_INSTANCE
      fi
   fi

   if [[ "$SHAREDDATA" == "FALSE" || "$SERVER_TYPE" == p4d_master ]]; then
     echo "Setting ownership on depot files - this may take some time ..."
     chown -Rh $OSUSER:$OSGROUP /$DD/p4/$SDP_INSTANCE
   fi
else
   echo "Not running as root, so chown commands were skipped."
fi

chmod 700 /$DB1/p4
chmod 700 /$DB2/p4
chmod 700 /$DD/p4
chmod 700 /$LG/p4

chmod -R 700 /$DB1/p4/$SDP_INSTANCE
chmod -R 700 /$DB2/p4/$SDP_INSTANCE
chmod -R 700 /$CN/p4/common
chmod -R 700 /$LG/p4/$SDP_INSTANCE

if [[ "$SHAREDDATA" == "FALSE" || "$SERVER_TYPE" == p4d_master ]]; then
    echo "Setting permissions on depot files - this may take some time ..."
    chmod -R 700 /$DD/p4/$SDP_INSTANCE
fi

if [[ $SDP_INSTANCE != $MASTERINSTANCE ]]; then
  if [[ -f $P4DIR/$MASTERINSTANCE/root/license ]]; then
    ln -s $P4DIR/$MASTERINSTANCE/root/license $P4DIR/$SDP_INSTANCE/root/license
    chown -h $OSUSER:$OSGROUP $P4DIR/$SDP_INSTANCE/root/license
  fi
fi

chmod 755 $P4DIR/${SDP_INSTANCE}/bin/*_init
chmod 755 $P4DIR/${SDP_INSTANCE}/bin/init/*_init
chmod 600 /$CN/p4/common/config/.p4passwd.${P4SERVER}.admin
[[ -e /$CN/p4/common/bin/*.cfg ]] && chmod 600 /$CN/p4/common/bin/*.cfg
[[ -e /$CN/p4/common/bin/*.html ]] && chmod 600 /$CN/p4/common/bin/*.html
chmod 700 $P4DIR/ssl
[[ -e $P4DIR/ssl/* ]] && chmod 600 $P4DIR/ssl/*

if [[ $TEST -eq 1 ]]; then
  echo ""
  echo "This was done in TEST mode - please run the following command to see any changes should be"
  echo "applied to your live environment (manually):"
  echo ""
  echo "  diff -r /p4/$SDP_INSTANCE/bin $P4DIR/$SDP_INSTANCE/bin"
  echo "  diff -r /p4/common $P4DIR/common"
  echo ""
  echo "If upgrading an older SDP version then be careful to ensure files in /p4/common/config are correct"
  echo "and update that /p4/common/bin/p4_vars is appropriate."
  echo ""
fi

exit 0
# Change User Description Committed
#47 29965 Russell C. Jackson (Rusty) Changes to directories, commands and journalPrefix to implement new process to keep journal rotation to the same volume as the logs volume, but to still move journals to the checkpoints directory so they get backed up.
Also compresses journals to save space.
#46 29732 Russell C. Jackson (Rusty) Add script to copy missing shelf files to the commit server.
#45 29358 Russell C. Jackson (Rusty) Modified chown/chmod commands specifically for db*
#44 29294 Russell C. Jackson (Rusty) Found the ansible problem in the upgrade script.
#43 29292 Russell C. Jackson (Rusty) Another ansible change
#42 29290 Russell C. Jackson (Rusty) Another copy line to try to fix ansible copy issue.
#41 29288 Russell C. Jackson (Rusty) Attempt to fix p4broker copy issue under ansible
#40 29286 Russell C. Jackson (Rusty) Fixed typo
#39 29284 Russell C. Jackson (Rusty) More fixes for bin move
#38 29282 Russell C. Jackson (Rusty) Check p4broker
#37 29280 Russell C. Jackson (Rusty) More cleanup
#36 29276 Russell C. Jackson (Rusty) Fixed more location errors
#35 29273 Russell C. Jackson (Rusty) Fixed cd errors
#34 29271 Russell C. Jackson (Rusty) Moved p4 binaries to instance bin folder.
#33 28943 Russell C. Jackson (Rusty) Change to only chown depot files if owner is incorrect, and simplication in del_shelve.py
#32 28922 Russell C. Jackson (Rusty) Moved some additional settings into the server specific vars file
#31 28911 Russell C. Jackson (Rusty) Added replacements needed for serverid file.
#30 28905 Russell C. Jackson (Rusty) Removing section that unlinks everything.
#29 28875 Russell C. Jackson (Rusty) Added new SDP_UPGRADE variable to skip running chown and chmod on the depots folder.
#28 28828 Russell C. Jackson (Rusty) Changed the name of p4.crontab to always be p4.crontab.new
       This is to allow better use of tools like Ansible to install the crontab
       and allow adding other files such as p4.crontab.extras from the monitoring
       install to be used to create a new p4.crontab that can be loaded without
       losing the contents of p4.crontab.extras when the sdp is upgraded.
#27 28817 Russell C. Jackson (Rusty) Updated chmod and chown to be correct in the case of shareddata
#26 28813 Russell C. Jackson (Rusty) Added change directory back to the instance directory
#25 28811 Russell C. Jackson (Rusty) Added commands to remove existing symlinks
#24 28807 Russell C. Jackson (Rusty) Changed mkdirs.sh to take the name of the config file as the first parameter
       rather than the instance number. This is to support storing the config files
       and to allow ansible to use unique names for each machine, which is required
       when using a shared data volume.

      The SDP_INSTANCE variable is now in template.mkdirs.cfg
#23 28746 Russell C. Jackson (Rusty) Removed a copy of etc that wasn't needed.
#22 28744 Russell C. Jackson (Rusty) Added force to cp on common folder.
#21 28600 Russell C. Jackson (Rusty) Added a serverid.vars file to /p4/common/config in order to support a shared config directory that is part of a shared p4data volume.
#20 28563 Russell C. Jackson (Rusty) Updates from Jake to make it easier to work with Ansible
#19 28095 Russell C. Jackson (Rusty) Added REPL_SHAREDDATA to use the setting from mkdirs.cfg in the instance_vars file.
Removed the logic that accesses the database to read the data from the database since
it will hang when sourcing p4_vars if the database is locked.
#18 28087 Russell C. Jackson (Rusty) Corrected top of the file that got messed up by mistake.
#17 28078 Russell C. Jackson (Rusty) Change default for the physical checkpoints directory name to be checkpoints.P4MASTER_ID, the link is still just checkpoints.
#16 27508 Russell C. Jackson (Rusty) Added support for a separate checkpoints volume.
#15 26686 Russell C. Jackson (Rusty) Added journals.rep back for use on shared depot volumes.
#14 26373 Russell C. Jackson (Rusty) Added a proxy clean script and a proxy crontab.
#13 25955 Russell C. Jackson (Rusty) Fixed logic around edges sharing volumes with the master/standbys and checkpoints folder.
#12 24858 Russell C. Jackson (Rusty) Set rpl.journalcopy.location=1 and removed all journals.rep references since it won't be needed anymore.
#11 24720 Russell C. Jackson (Rusty) Fixed chown for the SDP folder.
#10 24677 Russell C. Jackson (Rusty) Automated the creation of maintenance.cfg to have the values taken from mkdirs.cfg
#9 23519 Russell C. Jackson (Rusty) Moved OSUSER to instance_vars.template so that p4_vars would be standard and all instances,
and could be moved to /p4/common/bin. Adjusted other files to account for this change.
#8 23378 Russell C. Jackson (Rusty) Removed chmod on the service pass file since it has been removed.
#7 23366 Russell C. Jackson (Rusty) Changed layout so that instance dir is on the OS volume, and everything under it is a link.
This avoids a slow NAS depotdata volume does not slow the database and logs volume access now.
#6 23337 Russell C. Jackson (Rusty) Removed references to SERVICEPASS.
Use admin to login the service user.
#5 23269 Russell C. Jackson (Rusty) Updated so that edge servers and replicas of edge server in a shareddata environment use a unique checkpoints folder.
Otherwise, everything is still just checkpoints to maintain compatability.
#4 23247 Russell C. Jackson (Rusty) Modified the checkpoints folder to include an extension of the master or edge server.id
to support sharing the data volume between a master and a workspace edge server in the same
data center.

Updated recover_edge to use variables appropriately and fixed a bug in the naming of the
checkpoint file.
#3 22700 Russell C. Jackson (Rusty) Added chown for the /p4/ssl dir
Removed more unncessary files and settings
#2 22696 Russell C. Jackson (Rusty) Updates to support using journalnum in rotate_last_run_logs.
#1 22693 Russell C. Jackson (Rusty) Branched a Unix only version of the SDP.
Removed extra items to create a cleaner tree.
Moved a few items around to make more sense without Windows in the mix.
//guest/perforce_software/sdp/dev/Server/Unix/setup/mkdirs.sh
#54 22625 Russell C. Jackson (Rusty) Approved in Review 22364
#53 22623 Russell C. Jackson (Rusty) Update to account for Tom's name change.
#52 22201 C. Thomas Tyler Fixed typo.
#51 22200 C. Thomas Tyler More elegant and portable implementation of logic to find config file
in same dir as mkdirs.sh script.  Works on Mac, too.

This works for various means of calling mkdirs.sh, e.g.
./mkdirs.sh
/full/path/to/mkdirs.sh
/path/with/symlink/to/mkdirs.sh
mkdirs.sh (found in PATH)

Approving my own review here for this minor change so I can deploy, as others are on holiday or traveling.
#50 22145 Robert Cowham Update mkdirs to help testing.
#49 22070 Russell C. Jackson (Rusty) Pull the configuration items out into mkdirs.cfg and source that file
in mkdirs.sh. Makes it a little cleaner, and less likely for someone
to mess up the mkdirs.sh script. Also preps for potential future
configure_sdp.sh script to ask questions and create the mkdirs.cfg file.
#48 21418 C. Thomas Tyler Changed CASEINSENSITIVE to CASE_SENSITIVE, to make it harder to
pick the wrong value by miscalculating the double-negative.

Changed the default to be case-sensitive, for several reasons:
* Case-sensitive is better for git interoperability.  Most git repos
in the wild, especially those used in corporate environments, are
case sensitive.
* Case-sensitive is better for importing from most legacy SCM systems,
as it can handle a wider array of data sets.
* Case-sensitive is required for some data sets that have case-only
variants.
* The SDP now includes a case check trigger to help avoid the worst
perils of a case-sensitive server.
* While confusion is always possible if the client OS doesn't match
the case sensitivty setting of the server, the least harmful
permuatations of problems occur with the widest array of client
platforms when you have a case-senstive server.
* Case-insensitive is really only best suited to pure-Windows sites.

Also added a comment indicating you don't need the Review daemon if
you intend to handle review-style email notifications with Swarm.
#47 21327 Russell C. Jackson (Rusty) Update to have mkdirs put the correct instance name into the crontab files.
#46 21267 Robert Cowham Fix failing tests.
Changed default filesystem names to:
DB1=hxmetadata1
DB2=hxmetadata2
DD=hxdepots
LG=hxlogs

hx=Helix. Updated docs to reflect this
#45 21192 Russell C. Jackson (Rusty) Fixed issue with root and offline_db links.
#44 21178 Russell C. Jackson (Rusty) Change the SDP so that root and offline_db can be on different volumes and still accomplish
a fast database recovery using recreate_db_checkpoint.sh and recreate_db_sync_replica.sh.
This is done by switching the links now rather than moving the db files.
#43 21123 Russell C. Jackson (Rusty) Corrected cp path for ssl directory.
#42 21049 Russell C. Jackson (Rusty) Added config.txt to /p4/ssl so we and customers don't have to go find it
in the admin guide.

Added comments and cp command for config.txt and setting up ssl certs.

Uncommented the journalcopy echo commands at the bottom of mkdirs.sh
per discussion with Tom.
#41 20982 Russell C. Jackson (Rusty) Added the new CN setting for /p4/common to the test folder path resets.
#40 20905 Russell C. Jackson (Rusty) Defaulted the SDP to be on the same volume as $CN since that is where it
is usually located.

Changed MAILTO to default to $MAILFROM since that is what it is most of the
time and I am lazy and don't like typing the email address twice.
#39 20904 Russell C. Jackson (Rusty) Added CN=$DD and changed all $DD/p4/common entries to $CN/p4/common in
order to allow you to install an instance on a different depotdata
volume than the 1st instance. Before this change, doing that would
incorrectly create a common folder on the 2nd depotdata volume.

Also removed the lines that copy the binaries from an existing
/p4/common/bin folder back to the SDP. It is perfectly acceptable
to install another instance that is using a newer version than
the existing instance.
#38 20790 C. Thomas Tyler Added '/p4/common/hms' to list of dirs to install.'
#37 20708 C. Thomas Tyler Per discussion: s/checkpoints.rep/journals.rep/g

This directory name changed, used in the journalPrefix configurable, is
intended to clarify that the should be targeted to for a FAST volume
for use with journalcopy, rather than the LARGE volume as would be
implied when using a directory with "checkpoints" in the name.
#36 20432 C. Thomas Tyler Improved edge & daisy chained replica support in instance_vars.template.

Changed so P4MASTER is set dynamically, based on how/whether the
P4TARGET of the current ServerID is set.

This also eliminates a possible discrepancey beteween P4MASTER
as defined in the p4_N.vars/mkdirs.sh and the master hostname as
defined in P4TARGET configurables.  The value defined with
P4TARGET must also work with SSH keys.  (As a best practice
P4TARGET should be a host alias so that it doesn't need to be
changed in case of failvoer of your P4TARGET server).

Changed so SHAREDDATA is set dynamically, based on how/whether the
lbr.replication of the current ServerID is set.  If it is unset,
set to none, ondemand, or cache, then SHAREDDATA is set to TRUE,
otherwise FALSE.

Dynamic queries use 'p4d -cset' so they work regardless of
whether the p4d process is up or not.

Some internal refactoring was necessary to ensure all variables
are set before they are used.

This involved a minor tweak to mkdirs.sh to remove the
now-unnecessary 'sed' for SHAREDDATA when generating p4_N.vars
from the template.  SHAREDDATA must still be configured in
mkdirs.sh because it can be run before a replica is fully
configured.

Goals:
* Simplfy SDP configuration for complex topologies by eliminating
configuration external to p4d where possible/practical.
* Reduce chances for discrepancies and errors as topologies
evolve over time.
* Allow the p4_1.vars file to identical on all hosts in the
topology, an HMS requirement.
#35 20395 C. Thomas Tyler Fixed typo.
#34 20376 C. Thomas Tyler Incorporated HMS service user naming standard into the SDP,
i.e. "svc_<serverid>."

Removed SVCUSER setting from mkdirs.sh accordingly.

Fixed mkdirs.sh so /p4/common/etc is created if it doesn't
already exist, just as the 'lib' dir is handled.

Also a minor structural enhacement in instance_vars.template.

Added SDP_ALWAYS_LOGIN setting to instance_vars.template, setting
the default to 0 to prevent unnecessary logins.
#33 20363 C. Thomas Tyler Removed references to legacy names for checkpoint scripts.
No functional changes.  Bypassing pre-commit code review.

#review-20364
#32 20217 Russell C. Jackson (Rusty) Needed move password creation outside of common area since it is instance specific now.
#31 20170 Russell C. Jackson (Rusty) Moved password and users into the config directory to allow for instance specific
users and passwords. Ran into a case where two different teams were sharing the same
server hardware and needed this type of differentiation. Surprised that we haven't hit
this sooner.

Also defaulted mkdirs to use the numeric ports since this is the most common
installation.
#30 19983 Russell C. Jackson (Rusty) Commented out the echo around using journalcopy until we are ready to support that.
#29 19410 Russell C. Jackson (Rusty) Made out on setting permissions consistent in mkdirs.
Added the new output as valid in test_SDP.
#28 19314 Russell C. Jackson (Rusty) Change p4verify.sh to use -S to verify shelves on a replica instead of printing the files
on the shelf.

Removed the HOST_IP settings from mkdirs and instance_vars since it causes problems in
a shared depotdata environment, and it was a temporary fix to work around a bug with
auth.id that is being fixed.
#27 19311 adrian_waters If creating a replica that shares depot files with master, don't do chown/chmod on the depot files as this can take a significant time when migrating existing Helix servers into the SDP;  In addition, issue 'warning' message that chown/chmod could take some time to complete so user is aware of processing being carried out
#26 18952 C. Thomas Tyler Tweaks to mkdirs.sh:
* Replaced ADMINEMAIL with MAILTO and MAILFROM settings.  This
allows MAILTO to be a distribution list or a comma-delimited
list of email addresses, while MAILFROM must always be exactly
one email address.
* Added quotes to allow handling of adresses like '#P4AdminTeam,"
where the '#' character designates a distribution list.
#25 18930 C. Thomas Tyler Fixed typo; caught by test suite.
 Bypassing pre-commit review
'cuz this is an obivious fix.

#review-18931
#24 18925 C. Thomas Tyler Enhanced p4_vars.template to support operating on an SDP-managed
host where no p4d process runs, such as a p4p (proxy) host, where
no /p4/n/root/server.id file exists.  The $SERVERID value will
be empty (but defined) in this case.

Enhanced to better support operating with replicas that share
/depotdata with their master servers, by making P4TRUST and
P4TICKETS values contain $SERVERID.

Moved SHAREDDATA from p4_vars to instance_vars, since it is not
inherently a global setting.  In sophisticated enterprise
environments, it can vary on a per-replica basis.  Adjusted
mkdirs.sh accordingly.
#23 18618 Russell C. Jackson (Rusty) Added a crontab for the edge servers.
#22 18203 richard_baum Removed hard-coded /p4 path for server.id file location.
 This fixes "-test" mode so server.id file is written to the correct location. Without this it is written to /p4 where there could be an installation with the same instance ID.  In that case the server.id file could get overwritten with different data.  If there is not an existing instance an error message would be displayed.  Now neither of these should occur :-)

Also fixed some typos.
#21 16563 C. Thomas Tyler Routine Merge Down to dev from main using:
p4 merge -b perforce_software-sdp-dev
p4 resolve -as
#20 16373 C. Thomas Tyler Routine Merge Down to dev from main using:
p4 merge -b perforce_software-sdp-dev
#19 16335 C. Thomas Tyler Routine Merge Down to dev from main using:
p4 merge -b perforce_software-sdp-dev
#18 16029 C. Thomas Tyler Routine merge to dev from main using:
p4 merge -b perforce_software-sdp-dev
#17 15701 C. Thomas Tyler Routine merge down using 'p4 merge -b perforce_software-sdp-dev'.
#16 14136 C. Thomas Tyler Routine merge down to dev from main for SDP
using perforce_software-sdp-dev.
#15 14038 C. Thomas Tyler Routine merge-down to SDP dev from main.
#14 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.
#13 13586 C. Thomas Tyler Routine merge down from main -> dev.
Trivial merges, all resolved with 'p4 resolve -as.'
#12 12923 C. Thomas Tyler Routine merge down from main to dev.
Resolved with 'p4 resolve -as', no merges or conflicts.
#11 12170 Russell C. Jackson (Rusty) Merged in changes in Main
#10 12116 Russell C. Jackson (Rusty) Update dev from main.
#9 12107 C. Thomas Tyler Routine merge down from 'main' to 'dev', resolved with
'p4 resolve -as'.
#8 12028 C. Thomas Tyler Refreshed SDP dev branch, merging down from main.
#7 11523 Russell C. Jackson (Rusty) Modified P4BROKERPORTNUM to just be the port number and added P4BROKERPORT to instance_vars
 to be consistent with P4PORT. Also makes it easier to modify p4review.py to use P4BROKERPORT
 rather than P4PORT for the subject line when needed.
#6 11490 Russell C. Jackson (Rusty) Added SSL_PREFIX back and P4MASTERPORTNUM in order to support the sync_replica.sh
and weekly_sync_replica.sh scripts.
#5 11477 Russell C. Jackson (Rusty) Updated to use /usr/bin/env python

Added workshop header.

 Changed cfg to config.
#4 11474 Russell C. Jackson (Rusty) Had to move the cfg directory to the metadata volume and link it under the instance
directory to provide the proper separation in a shared volume environment. The
 instance specific vars cannot be in a shared directory since they need to be different
 on each node using the shared volume.

 Since the files moved back to the instance directory, I changed the names back to:
   instance_vars
   p4review.cfg
 to keep things simple.

 Also moved p4_vars.template to SDP/Server/Unix/p4/common/cfg so that it doesn't get
 copied to the /p4/common/bin folder. Plus, it makes more sense for it to be in that
 directory in the SDP structure.
#3 11468 Russell C. Jackson (Rusty) Added comments regarding configuring Edge and Edge replicas.
#2 11466 Russell C. Jackson (Rusty) Initial work to simplify p4_vars and remove cluster stuff.

 Testing of named instances surfaced some bugs that are in prod sdp,
 now fixed in dev.

 Added three triggers from RCJ SDP

 Moved p4review.cfg into the new /p4/common/cfg to go along with the
 instance_vars files. mkdirs.sh now generates an instance_p4review.cfg
 as well.

 Removed incremental p4verify to clean up a bit. It didn't support replicas
 and was really never used.

 All port settings now live in <instance>_vars file. You set what you want
 the ports to be in mkdirs.sh. There is no more fancy logic to try to guess
 what the port should be. You set it, and that is what it is.

 Remaining to do is to updated scripts to not need p4master_run. Saved
 that work for later since this is tested and works.
#1 10638 C. Thomas Tyler Populate perforce_software-sdp-dev.
//guest/perforce_software/sdp/main/Server/Unix/setup/mkdirs.sh
#1 10148 C. Thomas Tyler Promoted the Perforce Server Deployment Package to The Workshop.