p4master_run #1

  • //
  • guest/
  • alan_petersen/
  • sdp/
  • dev/
  • Server/
  • Unix/
  • p4/
  • common/
  • bin/
  • p4master_run
  • View
  • Commits
  • Open Download .zip Download (4 KB)
#!/bin/bash
#------------------------------------------------------------------------------
# Copyright (c) Perforce Software, Inc., 2007-2015. All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1  Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# 2.  Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE
# SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#------------------------------------------------------------------------------

set -u

# A safe way to run something only on an active p4 node with
# a controlled shell environment defined by the current
# contents of /p4/common/bin/p4_vars.

# Usage:
#   p4master_run INSTANCE [-c] PROGRAM [PROGRAM_ARGS ...]
#
# where INSTANCE is an SDP instance number or name.
function usage {
   echo -e "\nUsage:
\tp4master_run INSTANCE [-c] PROGRAM [ARGS ...]

where INSTANCE is an SDP instance number or name.

The optional '-c' flag is for running programs from cron that
send their own emails.  It suppresses some errors to avoid
duplicate emails from the cron daemon.  Some errors, such as
failures to start the called program, still are reported by
cron email.

PROGRAM can be a relative or absolute path, with optional arguments.\n"
exit 3
}

# Bail with usage message if there are less than 2 arguments.
[[ $# -lt 2 ]] && usage

Instance=$1

# Do nothing unless $Instance is defined.  Make sure user didn't
# try to pass a flag (e.g. '-c') as the first parameter.
if [[ $Instance == -* ]]; then
   echo -e "\nError: The Perforce instance number or name must be the first paramter. Aborting\n" >&2
   usage
fi

shift

# Bail with usage message if nothing follows '-c'.
if [[ $1 == -c ]]; then
   [[ $# -lt 2 ]] && usage
   CRON=yes
   shift
fi

SDP_CONF=/p4/common/bin/p4_vars

if [[ ! -r "$SDP_CONF" ]]; then
 echo -e "\nError: No readable SDP config file [$SDP_CONF]. Aborting.\n" >&2
 exit 2
fi

source "$SDP_CONF" $Instance || exit 1

if [ `$ID -u` = 0 ]; then
   exec su - $OSUSER -c "$0 $@"
elif [ "`$ID -u -n`" != $OSUSER ]; then
   echo "$0 can only be run by root or $OSUSER"
   exit 1
fi

Program=$1
if [[ $Program == /* || $Program == \.* ]]; then
   # Non-path depedent, absolute or relative path specified.
   ProgramPath=$Program
else
   # Path-dependent path specified.
   ProgramPath=$(which $Program)
fi

if [[ -z "$ProgramPath" ]]; then
   echo -e "\nError: The specified program [$Program] cannot be found.  Aborting.\n" >&2
   exit 3
fi

if [[ ! -r "$ProgramPath" ]]; then
   echo -e "\nError: The specified program [$Program] cannot be found.  Aborting.\n" >&2
   exit 3
fi

if [[ ! -x "$ProgramPath" ]]; then
   echo -e "\nError: The specified program [$Program] is not executable.  Aborting.\n" >&2
   exit 3
fi

shift
Args=$@

$Program $Args
# Change User Description Committed
#1 15465 alan_petersen Merging using sdp_alan_petersen
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/p4master_run
#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 12028 C. Thomas Tyler Refreshed SDP dev branch, merging down from main.
#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/p4/common/bin/p4master_run
#1 10148 C. Thomas Tyler Promoted the Perforce Server Deployment Package to The Workshop.