1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
|
#!/bin/sh
#
#+-#+-#+-#-+-#+-#+-#-+-#+-#+-#-+-#+-#+-#-+-#+-#+-#-+-#+-#+-#-+-#+-#+-#-+-#
#
# $SGE_ROOT/util/execd_template
#
# DO NOT EDIT THIS FILE - this file is used as an template
# Don't change the markers #+-#+-#+-# and "#-#-#-#" , they will be removed
#
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
#
# SGE/SGEEE startup script
#
#___INFO__MARK_BEGIN__
##########################################################################
#
# The Contents of this file are made available subject to the terms of
# the Sun Industry Standards Source License Version 1.2
#
# Sun Microsystems Inc., March, 2001
#
#
# Sun Industry Standards Source License Version 1.2
# =================================================
# The contents of this file are subject to the Sun Industry Standards
# Source License Version 1.2 (the "License"); You may not use this file
# except in compliance with the License. You may obtain a copy of the
# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
#
# Software provided under this License is provided on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
# See the License for the specific provisions governing your rights and
# obligations concerning the Software.
#
# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
#
# Copyright: 2001 by Sun Microsystems, Inc.
#
# All Rights Reserved.
#
##########################################################################
#___INFO__MARK_END__
#
# This script can be called with the following arguments:
#
# start start execution daemon
# stop Terminates the execution daemon
# and the shepherd. This only works if the execution daemon
# spool directory is in the default location.
# softstop do not kill the shepherd process
#
# Unix commands which may be used in this script:
# cat cut tr ls grep awk sed basename
#
# This script requires the script $SGE_ROOT/util/arch
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin
#---------------------------------------------------------------------------
# The following lines provide the necessary info for adding a startup script
# according to the Linux Standard Base Specification (LSB) which can
# be found at:
#
# http://www.linuxfoundation.org/spec/booksets/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html
#
### BEGIN INIT INFO
# Provides: GENSGESVC
# Required-Start: $network $remote_fs
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: start Grid Engine execd
### END INIT INFO
#---------------------------------------------------------------------------
SGE_ROOT=GENROOT; export SGE_ROOT
SGE_CELL=GENCELL; export SGE_CELL
SGE_QMASTER_PORT=GENSGE_QMASTER_PORT; export SGE_QMASTER_PORT
SGE_EXECD_PORT=GENSGE_EXECD_PORT; export SGE_EXECD_PORT
unset CODINE_ROOT GRD_ROOT COD_CELL GRD_CELL
count=0
while [ ! -d "$SGE_ROOT" -a $count -le 120 ]; do
count=`expr $count + 1`
sleep 1
done
ARCH=`$SGE_ROOT/util/arch`
# library path setting required only for architectures where RUNPATH is not supported
case $ARCH in
#ENFORCE_SHLIBPATH#sol*|lx*)
#ENFORCE_SHLIBPATH# ;;
*)
shlib_path_name=`$SGE_ROOT/util/arch -lib`
old_value=`eval echo '$'$shlib_path_name`
if [ x$old_value = x ]; then
eval $shlib_path_name=$SGE_ROOT/lib/$ARCH
else
eval $shlib_path_name=$old_value:$SGE_ROOT/lib/$ARCH
fi
export $shlib_path_name
;;
esac
#---------------------------------------------------------------------------
# DetectSMFService - sets service to a mask maching the name
# $1 ... name
#
DetectSMFService()
{
name=$1
service=""
if [ "$noSMF" = true ]; then
return
fi
#Otherwise we try is it's available of the system
if [ -f /lib/svc/share/smf_include.sh ]; then
. /lib/svc/share/smf_include.sh
smf_present
if [ $? -ne 0 ]; then
return
fi
else
return
fi
#Check we have cluster_name file
if [ ! -r "$SGE_ROOT/$SGE_CELL/common/cluster_name" ]; then
echo "Error: could not find $SGE_ROOT/$SGE_CELL/common/cluster_name!"
exit $SMF_EXIT_ERR_CONFIG
fi
#Cluster name must be unique
SGE_CLUSTER_NAME=`cat $SGE_ROOT/$SGE_CELL/common/cluster_name 2>/dev/null`
service="svc:/application/sge/$name:$SGE_CLUSTER_NAME"
if [ -n "$SMF_FMRI" -a "$service" != "$SMF_FMRI" ]; then
#Someone is trying to fool us
echo "Error: $service does not match FMRI $SMF_FMRI provided by SMF!"
echo "Check that service instance $SGE_CLUSTER_NAME exist on your system"
exit $SMF_EXIT_ERR_CONFIG
fi
#Check if service exists
/usr/bin/svcs $service > /dev/null 2>&1
if [ $? -ne 0 ]; then
#No such service found in the system
service=""
fi
}
#---------------------------------------------------------------------------
# ShutdownSMF
#
ShutdownSMF()
{
if [ -z "$service" ]; then
#We don't have any such SMF service we use normal Shutdown
return
fi
pid=`/usr/bin/svcs -l -p $service | grep "/sge_execd$" | grep -v "^grep" | awk '{print $2}'`
if [ -n "$pid" ]; then
usingSMF="true"
/usr/sbin/svcadm disable -st $service
fi
}
#---------------------------------------------------------------------------
# Shutdown
# Send SIGTERM to process name $1 with pid in file $2
#
Shutdown()
{
name=$1
pidfile=$2
if [ -f $pidfile ]; then
pid=`cat $pidfile`
$utilbin_dir/checkprog $pid $name > /dev/null
if [ "$?" = 0 ]; then
kill -TERM $pid
return $?
fi
fi
}
#---------------------------------------------------------------------------
# GetPathToBinaries
# echo the name of the bin_dir on this system
# The check is fullfilled if we can access the qstat binary
# echo "none" if we can't determine the binary path
GetPathToBinaries()
{
cfgname=$SGE_ROOT/$SGE_CELL/common/bootstrap
base=none
if [ -f $cfgname ]; then
base=`grep binary_path $cfgname | awk '{ print $2 }'`
if [ -f $base/qstat ]; then
:
elif [ -f $SGE_ROOT/util/arch ]; then
arch=`$SGE_ROOT/util/arch`
if [ -f $base/$arch/qstat ]; then
base=$base/$arch
fi
fi
fi
echo $base
}
#---------------------------------------------------------------------------
# GetAdminUser
# echo the name of the admin user on this system
# echo "root" if admin user retrieval fails
GetAdminUser()
{
cfgname=$SGE_ROOT/$SGE_CELL/common/bootstrap
user=none
if [ -f $cfgname ]; then
user=`grep admin_user $cfgname | awk '{ print $2 }'`
fi
if [ `echo $user|tr "[A-Z]" "[a-z]"` = "none" ]; then
user=root
fi
echo $user
}
#---------------------------------------------------------------------------
# GetPathToUtilbin
# echo the path to the binaires in utilbin
# The check is fullfilled if we can access the "gethostname" binary
# echo "none" if we can't determine the binary path
#
GetPathToUtilbin()
{
base=none
if [ -f $SGE_ROOT/util/arch ]; then
utilbindir=$SGE_ROOT/utilbin
arch=`$SGE_ROOT/util/arch`
if [ -f $utilbindir/$arch/gethostname ]; then
base=$utilbindir/$arch
fi
fi
echo $base
}
#---------------------------------------------------------------------------
# GetExecdSpoolDir
# get the execution daemon spooling dir from configuration
GetExecdSpoolDir()
{
EXECD_SPOOL_DIR=`$bin_dir/qconf -sconf $UQHOST | grep execd_spool_dir | awk '{ print $2 }'`
if [ "$EXECD_SPOOL_DIR" = "" ]; then
EXECD_SPOOL_DIR=`$bin_dir/qconf -sconf | grep execd_spool_dir | awk '{ print $2 }'`
fi
}
#---------------------------------------------------------------------------
usage()
{
echo "Grid Engine start/stop script. Valid parameters are:"
echo ""
echo " (no parameters): start execution daemon if applicable"
echo " \"start\" dto."
echo " \"stop\" shutdown local Grid Engine processes and jobs"
echo " \"softstop\" shutdown local Grid Engine processes (no jobs)"
echo " \"-nosmf\" force no SMF"
echo ""
echo "Only one of the parameters \"start\", \"stop\" or \"softstop\" is allowed."
echo
echo "Default argument is \"start\" for all components."
echo "Default for \"stop\" is shutting down all components."
echo
exit 1
}
#---------------------------------------------------------------------------
# MAIN Procedure
#
if [ "$#" -gt 2 -o "$1" = "-h" -o "$1" = "help" ]; then
usage
fi
startup=true
execd=true
softstop=false
noSMF=false
for i in $*; do
if [ "$i" = start ]; then
startup=true
elif [ "$i" = stop ]; then
startup=false
elif [ "$i" = softstop ]; then
startup=false
softstop=true
elif [ "$i" = -nosmf ]; then
noSMF=true
else
usage
fi
done
bin_dir=`GetPathToBinaries`
if [ "$bin_dir" = "none" ]; then
echo "can't determine path to Grid Engine binaries"
exit 1
fi
utilbin_dir=`GetPathToUtilbin`
if [ "$utilbin_dir" = "none" ]; then
echo "can't determine path to Grid Engine utility binaries"
exit 1
fi
# HOST is the aliased name (SGE name)
# UQHOST is the local host name (unqualified name)
HOST=`$utilbin_dir/gethostname -aname`
UQHOST=`$utilbin_dir/gethostname -name | cut -f1 -d.`
DetectSMFService execd
if [ "$startup" = true ]; then
#We want to use smf
if [ -z "$SMF_FMRI" -a -n "$service" ]; then
svcadm enable -st $service
exit $?
fi
# execution daemon is started on this host!
if [ -z "$SGE_EXECD_PORT" ]; then
SGE_EXECD_PORT=`$utilbin_dir/getservbyname -number sge_execd`
fi
echo " starting sge_execd"
exec 1>/dev/null 2>&1
$bin_dir/sge_execd
[ $? -eq 0 -a -d /var/lock/subsys ] && touch /var/lock/subsys/sgeexecd
#Don't exit until daemon is up
$bin_dir/qping -info "$HOST" "$SGE_EXECD_PORT" execd 1 > /dev/null 2>&1
ret=$?
loop=0
while [ $ret -ne 0 -a $loop -ne 61 ]; do
sleep 1
$bin_dir/qping -info "$HOST" "$SGE_EXECD_PORT" execd 1 > /dev/null 2>&1
ret=$?
loop=`expr $loop + 1`
done
if [ $loop -eq 61 ]; then
echo "Execd did not start in 61 seconds!"
exit 1
fi
exit 0
else
# Shutdown execution daemon
if [ $execd = true ]; then
GetExecdSpoolDir
execd_spool_dir=$EXECD_SPOOL_DIR/$UQHOST
usingSMF=false
echo " Shutting down Grid Engine execution daemon"
#We try to use SMF
ShutdownSMF
#Otherwise we use normal shutdown
if [ "$usingSMF" != true ]; then
# Send SIGTERM to execd
Shutdown sge_execd $execd_spool_dir/execd.pid
ret=$?
if [ -f /var/lock/subsys/sgeexecd ]; then
uid=`$utilbin_dir/uidgid -uid`
if [ "$uid" = "0" -a "$ret" = "0" ]; then
rm -f /var/lock/subsys/sgeexecd >/dev/null 2>&1
else
echo "Can't shut down execd!"
exit 1
fi
fi
fi
if [ $softstop = false ]; then
# Send SIGTERM to all shepherds
for jobid in `ls $execd_spool_dir/active_jobs`; do
echo " Shutting down Grid Engine shepherd of job $jobid"
Shutdown sge_shepherd $execd_spool_dir/active_jobs/$jobid/pid
done
fi
fi
fi
|