ruoyunbai 2bb9621e30 1
2021-09-29 21:06:16 +08:00

518 lines
16 KiB
Bash

#!/bin/sh
#
#
# OpenPBS (Portable Batch System) v2.3 Software License
#
# Copyright (c) 1999-2000 Veridian Information Solutions, Inc.
# All rights reserved.
#
# ---------------------------------------------------------------------------
# For a license to use or redistribute the OpenPBS software under conditions
# other than those described below, or to purchase support for this software,
# please contact Veridian Systems, PBS Products Department ("Licensor") at:
#
# www.OpenPBS.org +1 650 967-4675 sales@OpenPBS.org
# 877 902-4PBS (US toll-free)
# ---------------------------------------------------------------------------
#
# This license covers use of the OpenPBS v2.3 software (the "Software") at
# your site or location, and, for certain users, redistribution of the
# Software to other sites and locations. Use and redistribution of
# OpenPBS v2.3 in source and binary forms, with or without modification,
# are permitted provided that all of the following conditions are met.
# After December 31, 2001, only conditions 3-6 must be met:
#
# 1. Commercial and/or non-commercial use of the Software is permitted
# provided a current software registration is on file at www.OpenPBS.org.
# If use of this software contributes to a publication, product, or
# service, proper attribution must be given; see www.OpenPBS.org/credit.html
#
# 2. Redistribution in any form is only permitted for non-commercial,
# non-profit purposes. There can be no charge for the Software or any
# software incorporating the Software. Further, there can be no
# expectation of revenue generated as a consequence of redistributing
# the Software.
#
# 3. Any Redistribution of source code must retain the above copyright notice
# and the acknowledgment contained in paragraph 6, this list of conditions
# and the disclaimer contained in paragraph 7.
#
# 4. Any Redistribution in binary form must reproduce the above copyright
# notice and the acknowledgment contained in paragraph 6, this list of
# conditions and the disclaimer contained in paragraph 7 in the
# documentation and/or other materials provided with the distribution.
#
# 5. Redistributions in any form must be accompanied by information on how to
# obtain complete source code for the OpenPBS software and any
# modifications and/or additions to the OpenPBS software. The source code
# must either be included in the distribution or be available for no more
# than the cost of distribution plus a nominal fee, and all modifications
# and additions to the Software must be freely redistributable by any party
# (including Licensor) without restriction.
#
# 6. All advertising materials mentioning features or use of the Software must
# display the following acknowledgment:
#
# "This product includes software developed by NASA Ames Research Center,
# Lawrence Livermore National Laboratory, and Veridian Information
# Solutions, Inc.
# Visit www.OpenPBS.org for OpenPBS software support,
# products, and information."
#
# 7. DISCLAIMER OF WARRANTY
#
# THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT
# ARE EXPRESSLY DISCLAIMED.
#
# IN NO EVENT SHALL VERIDIAN CORPORATION, ITS AFFILIATED COMPANIES, OR THE
# U.S. GOVERNMENT OR ANY OF ITS AGENCIES BE LIABLE FOR ANY DIRECT OR 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.
#
# This license will be governed by the laws of the Commonwealth of Virginia,
# without reference to its choice of law rules.
# pbs_mkdirs:
#
# This will make the various directories that are needed for PBS
# housekeeping.
#
# Usage:
# pbs_mkdirs [-v] [-c] [-C chk_tree_location] what
# -v be verbose
# -c allow usage of chk_tree (do not use this within a make install)
# -C Specify where the location of the chk_tree binary
# what select from the following list
# server -- dirs needed by pbs_server
# mom -- dirs needed by pbs_mom
# aux -- the aux directory
# default -- the default file
# common -- make common directory to all daemons
# check -- run chk_tree (turns on -c automatically)
# all -- do all of the above
#
# SVN INFO:
# $Id$
#
#
# check tree should not be called until it is installed since
# only relative paths are used by autoconf.
#
prefix=@prefix@
exec_prefix=@exec_prefix@
CHK_TREE=${DESTDIR}@bindir@/chk_tree
PBS_DEFAULT_SERVER=@PBS_DEFAULT_SERVER@
PBS_LIB_PATH=@prefix@/lib
PBS_LOAD_LIB_DIR=/etc/ld.so.conf.d
PBS_LOAD_LIB_FILE=/etc/ld.so.conf.d/libtorque.conf
HAVE_LOAD_LIB_FILE=@have_loadlibfile@
# PBS_SERVER_HOME is defined without DESTDIR so that DEFAULT_FILE and EVIRON
# can be based on SERVER_HOME. SERVER_HOME is defined a second time to pick
# up DESTDIR
test -n "$PBS_SERVER_HOME" || PBS_SERVER_HOME=@PBS_SERVER_HOME@
test -n "$PBS_DEFAULT_FILE" || PBS_DEFAULT_FILE=${DESTDIR}@PBS_DEFAULT_FILE@
test -n "$PBS_ENVIRON" || PBS_ENVIRON=${DESTDIR}@PBS_ENVIRON@
PBS_SERVER_HOME=${DESTDIR}$PBS_SERVER_HOME
PBS_NODES_FILE=$PBS_SERVER_HOME/server_priv/nodes
if test @PBS_MACH@ = cygwin; then
# AUX is reserved word in Windows
AUX_PATH=auxx
else
AUX_PATH=aux
fi
verbose=""
display_flags()
{
cat << EOF
Usage:
pbs_mkdirs [-v] [-c] [-C chk_tree_location] what
-v be verbose
-c allow usage of chk_tree (do not use this within a make install)
-C Specify where the location of the chk_tree binary
what select from the following list
server -- dirs needed by pbs_server
mom -- dirs needed by pbs_mom
aux -- the aux directory
default -- the default file
common -- make common directory to all daemons
check -- run chk_tree (turns on -c automatically)
all -- do all of the above
EOF
exit 0
}
#
# this will create a directory and any chain of parent directories
# that might be needed
# All of this is somewhat lame because install-sh is used
# along with install_dir in various places.
#
install_dir()
{
# use the id_ for namespace disambiguation
id_dname="$1"
id_mode=`test -n "$2" && echo "$2" || echo 755`
# dlist will contain a list of directory names to make
id_dlist=""
while [ ! \( -z "$id_dname" -o "$id_dname" = / -o \
"$id_dname" = "." \) ]; do
test -f $id_dname && return 1
test -d $id_dname && break
id_dlist="`basename $id_dname` $id_dlist"
id_dname=`dirname "$id_dname"`
done
id_dir="$id_dname"
for id_d in $id_dlist ""; do
id_dir="$id_dir/$id_d"
test -z "$id_d" && return 0
mkdir $id_dir && chmod $id_mode $id_dir || return 1
done
return 0
}
#
# This will take the name of the variable (not value) and
# make a directory. This is just to stick with the original
# way things were done in the top-level make file in PBS
#
install_dir_by_varname()
{
idv_dvarname="$1"
idv_dname=`eval 'echo $'$idv_dvarname`
idv_mode=`test -n "$2" && echo "$2" || echo 755`
if [ X$idv_dname = X ] ; then
echo $idv_dvarname is not defined 1>&2
return 1
elif [ -f $idv_dname ] ; then
echo $idv_dvarname exists and is not a directory 1>&2
return 1
elif [ -d $idv_dname ] ; then
chmod $idv_mode $idv_dname || return 1
return 0
elif [ ! -d $idv_dname ] ; then
test -n "$verbose" && echo Creating $idv_dname
install_dir `dirname $idv_dname` 755 && \
mkdir $idv_dname && chmod $idv_mode $idv_dname || return 1
fi
return 0
}
check_env()
{
test -n "$verbose" && echo Making environment file
if [ ! -f $PBS_ENVIRON ] ; then
install_dir `dirname $PBS_ENVIRON` || return 1
echo "PATH=/bin:/usr/bin" > $PBS_ENVIRON || return 1
if [ X$TZ != X ] ; then
echo "TZ=$TZ" >> $PBS_ENVIRON || return 1
fi
if [ X$LANG != X ] ; then
echo "LANG=$LANG" >> $PBS_ENVIRON || return 1
fi
if [ X$LC_ALL != X ] ; then
echo "LC_ALL=$LC_ALL" >> $PBS_ENVIRON || return 1
fi
if [ X$LC_COLLATE != X ] ; then
echo "LC_COLLATE=$LC_COLLATE" >> $PBS_ENVIRON || return 1
fi
if [ X$LC_CTYPE != X ] ; then
echo "LC_CTYPE=$LC_CTYPE" >> $PBS_ENVIRON || return 1
fi
if [ X$LC_MONETARY != X ] ; then
echo "LC_MONETARY=$LC_MONETARY" >> $PBS_ENVIRON || return 1
fi
if [ X$LC_NUMERIC != X ] ; then
echo "LC_NUMERIC=$LC_NUMERIC" >> $PBS_ENVIRON || return 1
fi
if [ X$LC_TIME != X ] ; then
echo "LC_TIME=$LC_TIME" >> $PBS_ENVIRON || return 1
fi
chmod 644 $PBS_ENVIRON || return 1
fi
}
chk_tree_wrap()
{
if test -n "$chktree";then
$CHK_TREE $* || return 1
fi
}
mk_server_dirs()
{
test -n "$verbose" && echo Creating Directories required for the Server
install_dir_by_varname PBS_SERVER_HOME 755 || return 1
install_dir $PBS_SERVER_HOME/spool 1777 || return 1
install_dir $PBS_SERVER_HOME/checkpoint 1777 || return 1
install_dir $PBS_SERVER_HOME/server_priv 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/jobs 750 || return 1
# make the numbered directories (used if use_jobs_subdirs server parameter set)
for i in {0..9}; do
install_dir $PBS_SERVER_HOME/server_priv/jobs/$i 750 || return 1
done
install_dir $PBS_SERVER_HOME/server_priv/hostlist 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/queues 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/acl_svr 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/acl_hosts 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/acl_users 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/acl_groups 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/disallowed_types 750 || return 1
install_dir $PBS_SERVER_HOME/server_priv/accounting 755 || return 1
install_dir $PBS_SERVER_HOME/job_logs 755 || return 1
install_dir $PBS_SERVER_HOME/server_logs 755 || return 1
install_dir $PBS_SERVER_HOME/sched_priv 750 || return 1
install_dir $PBS_SERVER_HOME/sched_priv/accounting 755 || return 1
install_dir $PBS_SERVER_HOME/sched_logs 755 || return 1
install_dir $PBS_SERVER_HOME/server_priv/arrays 750 || return 1
# make the numbered directories (used if use_jobs_subdirs server parameter set)
for i in {0..9}; do
install_dir $PBS_SERVER_HOME/server_priv/arrays/$i 750 || return 1
done
install_dir $PBS_SERVER_HOME/server_priv/credentials 750 || return 1
test -f $PBS_ENVIRON || check_env || return 1
chk_tree_wrap -d -n $PBS_SERVER_HOME/server_priv/jobs \
$PBS_SERVER_HOME/server_priv/hostlist \
$PBS_SERVER_HOME/server_priv/queues \
$PBS_SERVER_HOME/server_priv/acl_svr \
$PBS_SERVER_HOME/server_priv/acl_hosts \
$PBS_SERVER_HOME/server_priv/acl_users \
$PBS_SERVER_HOME/server_priv/acl_groups \
$PBS_SERVER_HOME/server_priv/accounting \
$PBS_SERVER_HOME/job_logs \
$PBS_SERVER_HOME/server_logs \
$PBS_SERVER_HOME/server_priv/arrays \
$PBS_SERVER_HOME/server_priv/credentials || return 1
chk_tree_wrap -d -n -s $PBS_SERVER_HOME/spool || return 1
chk_tree_wrap -n $PBS_ENVIRON || return 1
test -n "$verbose" && echo "Making default nodes file"
# Add an empty nodes file with a brief example
# and a link to more information in the documentation
if [ ! -e $PBS_NODES_FILE ]; then
rm -f $PBS_NODES_FILE > /dev/null 2>&1
echo -e "## This is the TORQUE server \"nodes\" file." \
"\n## \n## To add a node, enter its hostname, optional processor count (np=)," \
"\n## and optional feature names.\n##" \
"\n## Example:\n## host01 np=8 featureA featureB" \
"\n## host02 np=8 featureA featureB\n##" \
"\n## for more information, please visit:\n##" \
"\n## http://www.adaptivecomputing.com/resources/docs/\n" > $PBS_NODES_FILE && \
chmod 644 $PBS_NODES_FILE || return 1
fi
}
mk_mom_dirs()
{
test -n "$verbose" && echo Creating Directories required for MOM
install_dir_by_varname PBS_SERVER_HOME 755 || return 1
test -d $PBS_SERVER_HOME/spool || \
install_dir $PBS_SERVER_HOME/spool 1777 || return 1
install_dir $PBS_SERVER_HOME/checkpoint 1777 || return 1
install_dir $PBS_SERVER_HOME/undelivered 1777 || return 1
install_dir $PBS_SERVER_HOME/mom_priv 751 || return 1
install_dir $PBS_SERVER_HOME/mom_priv/jobs 751 || return 1
install_dir $PBS_SERVER_HOME/mom_logs 755 || return 1
mk_default_file || return 1
test -f $PBS_ENVIRON || check_env || return 1
chk_tree_wrap -d -n $PBS_SERVER_HOME/checkpoint \
$PBS_SERVER_HOME/mom_priv/jobs \
$PBS_SERVER_HOME/mom_logs || return 1
chk_tree_wrap -d -n -s $PBS_SERVER_HOME/spool \
$PBS_SERVER_HOME/undelivered || return 1
chk_tree_wrap -n $PBS_ENVIRON || return 1
}
mk_default_ld_lib_file()
{
echo "loadlibfile = $HAVE_LOAD_LIB_FILE"
test -n "$verbose" && echo "loadlibfile = $HAVE_LOAD_LIB_FILE"
if [ "$HAVE_LOAD_LIB_FILE" = "yes" ]; then
test -n "$verbose" && echo Making libtorque.conf
if [ ! -d $PBS_LOAD_LIB_DIR ]; then
echo $PBS_LOAD_LIB_DIR missing
else
echo $PBS_LIB_PATH > $PBS_LOAD_LIB_FILE && \
chmod 644 $PBS_LOAD_LIB_FILE || return 1
chk_tree_wrap -n $PBS_LOAD_LIB_FILE || return 1
fi
fi
}
mk_default_file()
{
test -n "$verbose" && echo Making default server file
install_dir `dirname $PBS_DEFAULT_FILE` || return 1
# I think I know better than pbs. --pw
if [ ! -e $PBS_DEFAULT_FILE ]; then
rm -f $PBS_DEFAULT_FILE > /dev/null 2>&1
echo $PBS_DEFAULT_SERVER > $PBS_DEFAULT_FILE && \
chmod 644 $PBS_DEFAULT_FILE || return 1
fi
mk_default_ld_lib_file || return 1
chk_tree_wrap -n $PBS_DEFAULT_FILE || return 1
}
mk_common()
{
echo $PBS_LIB_PATH > $PBS_LOAD_LIB_FILE
$ECHO "$PBS_LOAD_LIB_FILE"
mk_default_file || return 1
mk_ld_lib_file
mk_aux_dir || return 1
install_dir $PBS_SERVER_HOME/spool 1777 || return 1
check_env || return 1
}
mk_aux_dir()
{
install_dir $PBS_SERVER_HOME/$AUX_PATH 755 || return 1
chk_tree_wrap -d -n $PBS_SERVER_HOME/$AUX_PATH || return 1
}
do_check_tree()
{
chk_tree_wrap -d $PBS_SERVER_HOME/server_priv/jobs \
$PBS_SERVER_HOME/server_priv/queues \
$PBS_SERVER_HOME/server_priv/acl_svr \
$PBS_SERVER_HOME/server_priv/acl_hosts \
$PBS_SERVER_HOME/server_priv/acl_users \
$PBS_SERVER_HOME/server_priv/acl_groups \
$PBS_SERVER_HOME/server_priv/accounting \
$PBS_SERVER_HOME/job_logs || return 1
$PBS_SERVER_HOME/server_logs || return 1
chk_tree_wrap -d $PBS_SERVER_HOME/checkpoint \
$PBS_SERVER_HOME/mom_priv/jobs \
$PBS_SERVER_HOME/mom_logs || return 1
chk_tree_wrap -d -s $PBS_SERVER_HOME/spool \
$PBS_SERVER_HOME/undelivered || return 1
chk_tree_wrap -d $PBS_SERVER_HOME/$AUX_PATH || return 1
chk_tree_wrap $PBS_DEFAULT_FILE || return 1
}
# mk_dirs() will generate the set of directories needed
# for server and mom execution.
mk_dirs()
{
chktree=yes
mk_server_dirs || return 1
mk_mom_dirs || return 1
mk_default_file || return 1
mk_aux_dir || return 1
}
getopt vcd:C:h "$@" > /dev/null || display_flags
set -- `getopt vcd:C:h "$@"`
while true
do
case "$1" in
-v)
verbose=yes
shift
;;
-d)
PBS_SERVER_HOME=$2
shift 2
;;
-h)
display_flags
;;
-c)
chktree=yes
shift
;;
-C)
CHK_TREE=$2
shift 2
;;
--)
shift; break
;;
esac
done
while [ $# -gt 0 ]
do
case "$1" in
serv*)
mk_server_dirs || exit 1
break
;;
mom*)
mk_mom_dirs || exit 1
break
;;
aux*)
mk_aux_dir || exit 1
break
;;
default*)
mk_default_file || exit 1
break
;;
common*)
mk_common || exit 1
break
;;
check*)
chktree=yes
do_check_tree || exit 1
break
;;
all*)
mk_dirs || exit 1
break
;;
*)
echo "$1 is unknown flag"
display_flags
break
;;
esac
shift
done