broker_ctl.sh #2

  • //
  • p4-hms/
  • dev/
  • test/
  • broker_ctl.sh
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#!/bin/bash

declare BrokerPid=
declare BrokerCfg=
declare TmpP4ROOT=$HMS_TEST_HOME/tmp/.p4root
declare -i Debug=1

function msg () { echo -e "$*"; }
function dbg () { [[ $Debug -eq 1 ]] || return; echo -e "DEBUG: $*" >&2; }
function cmd () { msg "Executing: $*"; $*; return $?; }
function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit ${2:-1}; }

function get_broker_pid () {
   pid=$(ps -ef | grep "$P4BROKERBIN" | grep -v " grep " | \
      awk '{print $2}' | head -1)
   echo $pid
}

source ./env.sh
BrokerCfg="$HMS_TEST_HOME/broker.cfg"

case ${1:-status} in
   (start)
      if [[ -r "$BrokerCfg" ]]; then
         msg "Using existing $BrokerCfg."
      else
         msg "Generating $BrokerCfg from template."
         if ! sed -e "s:__HMS_SCRIPTS__:$HMS_SCRIPTS:g" -e "s:__P4PORT__:$P4PORT:g" -e "s:__P4BROKERPORT__:$P4BROKERPORT:g" -e "s:__HMS_TEST_HOME__:$HMS_TEST_HOME:g" "${BrokerCfg}.t" > "$BrokerCfg"; then
            bail "Failed to generate broker config."
         fi
      fi

      cd "$HMS_TEST_HOME" || bail "Failed to cd to $HMS_TEST_HOME."
      cmd "$P4BROKERBIN" -c "$BrokerCfg" -q -d

      # Start a helper p4d.  It does nothing, but needs to be running,
      # otherwise the broker can't do anything except a 'reject' or
      # 'redirect' action.
      unset P4JOURNAL P4AUDIT P4DEBUG P4CHANGE P4AUTH P4LOG
      rm -rf $TmpP4ROOT
      mkdir -p $TmpP4ROOT
      cmd p4d -r $TmpP4ROOT -p $P4PORT -q --daemonsafe --pid-file
   ;;

   (stop)
      if [[ -r "$TmpP4ROOT/server.pid" ]]; then
         msg "Killing helper p4d."
         cmd kill $(cat $TmpP4ROOT/server.pid)
      else
         msg Helper p4d was not running.
      fi

      BrokerPid=$(get_broker_pid)

      if [[ -n "$BrokerPid" ]]; then
         msg "Killing broker."
         cmd kill $BrokerPid

      else
         msg Broker was not running.
      fi

   ;;

   (status)
      if [[ -r "$TmpP4ROOT/server.pid" ]]; then
         msg "Helper p4d appears to be running."
      else
         msg "Helper p4d is not running."
      fi

      BrokerPid=$(get_broker_pid)

      if [[ -n "$BrokerPid" ]]; then
         msg Broker is running as pid $BrokerPid.
      else
         msg Broker is not running.
      fi
   ;;

   (clean)
      msg "Removing: $TmpP4ROOT"
      rm -rf "$TmpP4ROOT"
      msg "Removing: $BrokerCfg"
      rm -f "$BrokerCfg"
   ;;

   (*)
      msg "\nUsage:\n\t${0##*/} {start|stop|status}\n"
   ;;
esac
# Change User Description Committed
#2 33529 C. Thomas Tyler Cosmetic: normalize double-backslash \\n / \\t to single-backslash \n / \t

An older version of ShellCheck once recommended escaping backslash-n and
backslash-t as \\n / \\t in double-quoted strings; a later version reversed
that guidance since it was unnecessary. Both forms behave identically at
runtime, but the double-backslash form is visual clutter. Applied via
tools/sed_fixer.sh across the tree; no functional change.
#1 33516 C. Thomas Tyler Consistency pass: fix absolute URLs, p4ms->hms renames, script/doc typos and bugs

- Convert absolute workshop.perforce.com URLs to relative paths in dlp/ReadMe.md
- Fix case-mismatch link to HMS_Product_Roadmap.md in README.md
- Rename reset_p4ms.sh -> reset_hms.sh and p4broker_p4ms_test -> p4broker_hms_test
- Fix .sh-suffix bugs: bin/hms calling global_replica_status.sh (should be no ext),
  and matching SEE ALSO / doc references for sdp_sync and global_replica_status
- Add missing scripts (gtu, hrun, irun, global_replica_status) to gen_script_man_pages.sh
- Add stub scripts: nj_help.sh, broker_njob.pl, broker_mkproj.pl, broker_jr.pl
- Remove dangling absolute symlinks HostCM/p4 and HostCM/p4d (cruft)
- Rename test/b -> test/broker_ctl.sh for clarity
- Fix real bugs: broker_imply-u.pl broken regex match, gen_dlp_broker_cfg.sh and
  gen_nj_broker_cfg.sh copy-pasted Version-file existence check, garbled comment
  in broker_must_be_owner.pl, unclosed quote in tools/gsr.sh usage(), missing 'h'
  in HMS_SystemComponents.md broker command example (^ms$ -> ^hms$)
- Fix broken sed command and incomplete sentence in HMS_Install_Notes.md and
  SDP_and_HMS_Update_Process.md
- Fix broken markdown table in HMS_Product_Roadmap.md
- Fix unclosed parenthesis, missing verb, and FKA Swarm mislabel in
  HMSDeploymentPlanning.adoc
- Standardize //streams/main/... naming in HostCM/ReadMe.md
- Numerous typo fixes across README.md, HMS_SystemComponents.md,
  SDP_and_HMS_Update_Process.md, HMS_TightShipManagement.adoc,
  HMSDeploymentPlanning.adoc, HostCM/ReadMe.md, and various scripts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>