#!/bin/bash
#------------------------------------------------------------------------------
set -u
function msg () { echo -e "$*"; }
function warnmsg () { msg "\nWARNING: ${1:-Unknown Warning}\n"; WarningCount+=1; }
function errmsg () { msg "\nERROR: ${1:-Unknown Error}\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; }
#------------------------------------------------------------------------------
# Functions run($cmd, $desc)
#
# This function is similar to functions defined in SDP core libraries, but we
# need to duplicate them here since this script runs before the SDP is
# available on the machine (and we require no external dependencies for this
# script).
function run {
cmd="${1:-echo Testing run}"
desc="${2:-}"
[[ -n "$desc" ]] && msg "$desc"
msg "Running: $cmd"
if [[ "$NoOp" -eq 0 ]]; then
$cmd
else
msg "NO_OP: Would execute: $cmd"
fi
return $?
}
#------------------------------------------------------------------------------
# Declarations and Environment
declare ThisScript="${0##*/}"
declare Version=1.1.0
declare -i ErrorCount=0
declare -i WarningCount=0
declare -i ResetNeeded=0
declare -i NoOp=1
declare CustomResetScript="${HMS_CUSTOM_RESET_SCRIPT:-}"
declare ThisUser=
#------------------------------------------------------------------------------
# Command Line Parsing
[[ "$*" == "-y" ]] && NoOp=0
#------------------------------------------------------------------------------
# Main Program
ThisUser=$(whoami)
msg "Started $ThisScript v$Version as $ThisUser@${HOSTNAME%%.*} at $(date)."
msg "\nStopping running hms services (if running)."
for bin in p4d p4broker; do
svc=${bin}_hms
initScript=/p4/hms/bin/${bin}_hms_init
if [[ -x "$initScript" ]]; then
ResetNeeded=1
if systemctl cat "$svc" > /dev/null; then
run "sudo systemctl stop $svc" "Stopping with: sudo systemctl stop $svc" ||\
warnmsg "Failed to stop with: sudo systemctl stop $svc"
else
run "$initScript stop" "Stopping with: $initScript stop." ||\
warnmsg "Failed to stop with: $initScript stop"
fi
fi
done
#msg "\nDisabling and removing systemd services (if any)."
#for systemdService in p4d_hms p4broker_hms p4p_hms; do
# systemdServiceFile="/etc/systemd/system/${systemdService}.service"
# if [[ -e "$systemdServiceFile" ]]; then
# ResetNeeded=1
# #run "sudo systemctl disable $systemdService" ||\
# # errmsg "Failed to disable systemd service $systemdService."
# #run "sudo rm -f $systemdServiceFile" ||\
# # errmsg "Failed to remove systemd service file: $systemdServiceFile"
# fi
#done
msg "\nRemoving /mnt/p4*/p4/hms and /p4/hms folders if they exist."
for d in /mnt/p4*/hms /p4/hms/; do
if [[ -d "$d" ]]; then
ResetNeeded=1
run "rm -rf $d" "Removing dir: $d" ||\
errmsg "Failed to remove dir: $d"
else
msg "No dir to remove: $d"
fi
done
msg "\nRemoving hms-specific files (if any)."
for f in /p4/common/config/p4_hms.* /p4/.p4config.SDP /p4/common/bin/p4*_hms_* /p4/sdp/Server/Unix/setup/mkdirs.hms.*; do
if [[ -e "$f" ]]; then
ResetNeeded=1
run "rm -f $f" "Removing file $f" ||\
errmsg "Failed to remove file: $f"
else
msg "No file to remove: $f"
fi
done
if [[ -x "$CustomResetScript" ]]; then
run "$CustomResetScript" \
"Executing custom reset script specified with \$HMS_CUSTOM_RESET_SCRIPT." ||\
errmsg "Custom reset script returned non-zero exit code."
else
msg "No custom reset script found."
fi
if [[ "$ErrorCount" -eq 0 ]]; then
if [[ "$WarningCount" -eq 0 ]]; then
if [[ "$ResetNeeded" -eq 1 ]]; then
if [[ "$NoOp" -eq 0 ]]; then
msg "\nSUCCESS: HMS has been reset."
else
msg "\nSUCCESS: HMS would have been reset (was not without -y)."
fi
else
msg "\nSUCCESS: HMS reset was not needed."
fi
else
msg "\nSUCCESS: HMS has been reset, but with $WarningCount warnings."
fi
else
msg "\nHMS reset has completed, but with $ErrorCount errors and $WarningCount warnings."
fi
[[ "$NoOp" -eq 1 && "$ResetNeeded" -eq 1 ]] && warnmsg "This was preview mode; reset did not actually occur. Specify '-y' to perform an actual reset.\n"
exit "$ErrorCount"
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #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> |