3
# Sun Grid Engine SMF support script
6
##########################################################################
8
# The Contents of this file are made available subject to the terms of
9
# the Sun Industry Standards Source License Version 1.2
11
# Sun Microsystems Inc., March, 2001
14
# Sun Industry Standards Source License Version 1.2
15
# =================================================
16
# The contents of this file are subject to the Sun Industry Standards
17
# Source License Version 1.2 (the "License"); You may not use this file
18
# except in compliance with the License. You may obtain a copy of the
19
# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
21
# Software provided under this License is provided on an "AS IS" basis,
22
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
23
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
24
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
25
# See the License for the specific provisions governing your rights and
26
# obligations concerning the Software.
28
# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
30
# Copyright: 2001 by Sun Microsystems, Inc.
32
# All Rights Reserved.
34
##########################################################################
38
#1 - Do not match case QMaster = qmaster
39
#2 - Need to get the host where we will install the service. Problem root on remote host?
41
#---------------------------------------------------------------------------
42
# This script requires the that $SGE_ROOT and $SGE_CELL be set
45
SVCADM="/usr/sbin/svcadm"
46
SVCCFG="/usr/sbin/svccfg"
51
SGE_SMF_SUPPORT_SOURCED=true
53
if [ -z "$SGE_ROOT" -o -z "$SGE_CELL" ]; then
54
if [ -z "$INFOTEXT" ]; then
57
$INFOTEXT "\$SGE_ROOT and \$SGE_CELL must be set!"
61
#Standalone setup (Warning: Overwrites inst_sge settings)
62
if [ -z "$QMASTER" -a -z "$EXECD" -a -z "$SHADOW" -a -z "$BERKELEY" -a -z "$DBWRITER" ]; then
68
SGE_ARCH=`$SGE_ROOT/util/arch`
69
SGE_UTILBIN="$SGE_ROOT/utilbin/$SGE_ARCH"
71
. $SGE_ROOT/util/install_modules/inst_common.sh
75
if [ -z "$INFOTEXT" ]; then
76
INFOTEXT=$SGE_ROOT/utilbin/$SGE_ARCH/infotext
77
if [ ! -x $INFOTEXT ]; then
78
echo "Error: Can't find binary \"$INFOTEXT\""
79
echo "Please verify your setup and restart this script. Exit."
83
# Test the infotext binary
84
tmp=`$INFOTEXT test 2>&1`
86
echo "Error: Execution of $INFOTEXT failed: $tmp"
87
echo "Please verify your setup and restart this script. Exit."
90
SGE_INFOTEXT_MAX_COLUMN=5000; export SGE_INFOTEXT_MAX_COLUMN
94
#---------------------------------------------------------------------------
95
# Show the usage of the standalone command
98
$INFOTEXT "Usage: sge_smf <command>"
100
$INFOTEXT "Commands:"
101
$INFOTEXT " register qmaster|shadowd|execd|bdb|dbwriter [SGE_CLUSTER_NAME]"
102
$INFOTEXT " ... register SGE as SMF service"
103
$INFOTEXT " unregister qmaster|shadowd|execd|bdb|dbwriter [SGE_CLUSTER_NAME]"
104
$INFOTEXT " ... unregister SGE SMF service"
105
$INFOTEXT " supported ... check if the SMF can be used on current host"
106
$INFOTEXT " help ... this help"
108
$INFOTEXT "SGE_CLUSTER_NAME ... name of this cluster (installation), used as instance name in SMF"
109
$INFOTEXT " CAN be omitted if defined as an environment variable"
110
$INFOTEXT " MUST be the same as you entered during the installation"
113
#-------------------------------------------------------------------------
114
# SMFImportService: Import service descriptor
119
SMFValidateContent $file
121
if [ "$res" != 0 ]; then
122
$INFOTEXT "Service descriptor %s is corrupted, exiting!" $file
125
#Strangely svccfg import does not return non-zero exit code if there was
126
#an error such as permission denied
127
res=`$SVCCFG import $file 2>&1 | head -1`
128
if [ -n "$res" ]; then
130
$INFOTEXT "Importing service was NOT successful!"
135
#-------------------------------------------------------------------------
136
# SMFValidateContent: Validate service descriptor
140
return `$SVCCFG validate "$1"`
143
#-------------------------------------------------------------------------
144
# SMFReplaceXMLTemplateValues: replace variables
146
SMFReplaceXMLTemplateValues()
149
ExecuteAsAdmin $TOUCH $file.tmp
150
ExecuteAsAdmin $CHMOD 666 $file.tmp
151
$CAT $template_file > $file.tmp
153
$SED -e "s|@@@CLUSTER_NAME@@@|$SGE_CLUSTER_NAME|g" \
154
-e "s|@@@SGE_ROOT@@@|$SGE_ROOT|g" \
155
-e "s|@@@SGE_CELL@@@|$SGE_CELL|g" \
156
-e "s|@@@SGE_QMASTER_PORT@@@|$SGE_QMASTER_PORT|g" \
157
-e "s|@@@SGE_EXECD_PORT@@@|$SGE_EXECD_PORT|g" \
158
-e "s|@@@BDB_DEPENDENCY@@@|$BDB_DEPENDENCY|g" $file.tmp > $file
160
ExecuteAsAdmin $RM $file.tmp
163
#---------------------------------------------------------------------------
164
# ServiceAlreadyExists - sets service to a mask maching the name
165
# SGE_CLUSTER_NAME must be set
167
# return 0 if does not exist
168
# 1 if service exists
170
ServiceAlreadyExists()
174
service_name="svc:/application/sge/qmaster:$SGE_CLUSTER_NAME"
177
service_name="svc:/application/sge/$1:$SGE_CLUSTER_NAME"
180
#Check if service exists
181
$SVCS $service_name > /dev/null 2>&1
182
if [ $? -ne 0 ]; then
189
#-------------------------------------------------------------------------
190
# SMFCreateAndImportServiceFromTemplate: Replaces template values and
191
# imports it to the repository
193
SMFCreateAndImportService()
195
if [ "$1" != "dbwriter" ]; then
198
prefix="$SGE_ROOT/dbwriter"
200
template_file="$prefix/util/sgeSMF/$1_template.xml"
201
suffix="${SGE_CLUSTER_NAME}"
202
service_file="$SGE_ROOT/$SGE_CELL/tmp_$1_$suffix.xml"
203
if [ ! -f $template_file ]; then
204
$INFOTEXT "%s is missing!" $template_file
207
ExecuteAsAdmin $TOUCH $service_file
208
ExecuteAsAdmin $CHMOD 666 $service_file
209
$CAT $template_file > $service_file
210
SMFReplaceXMLTemplateValues $service_file
211
SMFImportService $service_file
213
ExecuteAsAdmin $RM $service_file
217
#---------------------------------------------------------------------------
218
# Register SMF service
219
# return Registered messages or nothing
224
if [ "$2" = "true" ]; then
225
ServiceAlreadyExists bdb
226
#Service exists and BDB server was chosen as spooling method
227
if [ $? -eq 1 ]; then
228
BDB_DEPENDENCY="<dependency name='bdb' grouping='require_all' restart_on='none' type='service'><service_fmri value=\'svc:/application/sge/bdb:$SGE_CLUSTER_NAME\' /></dependency>"
230
#Error we expect BDB to be using SMF as well
231
$INFOTEXT "You chose to install qmaster with SMF and you use Berkley DB server, but bdb \n" \
232
"SMF service was not found!\n" \
233
"Either start qmaster installation with -nosmf, or reinstall Berkley DB server \n" \
234
"to use SMF (do not use -nosmf flag)."
240
SMFCreateAndImportService "qmaster"
243
SMFCreateAndImportService "shadowd"
246
SMFCreateAndImportService "execd"
249
SMFCreateAndImportService "bdb"
252
SMFCreateAndImportService "dbwriter"
255
$INFOTEXT "Unknown parameter to sge_smf register"
263
#-------------------------------------------------------------------------
264
# SMFHaltAndDeleteService: Stops the service and deletes it
265
# arg1 ... SMF service name
266
SMFHaltAndDeleteService()
268
ServiceAlreadyExists $1
270
if [ $ret -eq 0 ]; then
271
$INFOTEXT "Service %s does not exists!" $service_name
272
$INFOTEXT "Check existing SGE services with svcs \"*sge*\""
276
#Service might be in maintanence
277
#In theory process can still be running after we remove it
278
$SVCADM disable -s "$service_name"
279
if [ "$?" -ne 0 ]; then
280
$INFOTEXT "Could not disable the service %s!" $service_name
283
$SVCCFG delete "$service_name"
284
if [ "$?" -ne 0 ]; then
285
$INFOTEXT "Could not delete the service %s!" $service_name
288
#Check if we should remove the whole service (no more instances)
289
$SVCCFG export "svc:/application/sge/$1" | grep "<instance " 1>/dev/null 2>&1
290
if [ "$?" -ne 0 ]; then
291
$SVCCFG delete "svc:/application/sge/$1"
292
if [ "$?" -ne 0 ]; then
293
$INFOTEXT "Could not delete empty service %s!" "svc:/application/sge/$1"
299
#---------------------------------------------------------------------------
300
# Unregister SMF service
301
# return registered or not to stdout
306
SMFHaltAndDeleteService "qmaster"
309
SMFHaltAndDeleteService "shadowd"
312
SMFHaltAndDeleteService "execd"
315
SMFHaltAndDeleteService "bdb"
318
SMFHaltAndDeleteService "dbwriter"
321
$INFOTEXT "Unknown parameter to sge_smf unregister"
329
#---------------------------------------------------------------------------
332
# return a stdout output
335
if [ -f /lib/svc/share/smf_include.sh ]; then
336
. /lib/svc/share/smf_include.sh
339
if [ $hasSMF -eq 0 ]; then
344
if [ "$hasSMF" != "true" ]; then
345
$INFOTEXT "SMF is NOT supported on your system."
351
if [ "$#" -lt 1 -o "$#" -gt 3 -o "$cmd" = "-h" -o "$cmd" = "help" -o "$cmd" = "-help" "$cmd" = "--help" ]; then
357
if [ "$cmd" = "register" -o "$cmd" = "unregister" ]; then
358
if [ "$#" -lt 2 ]; then
359
$INFOTEXT "Missing an argument!"
364
#We source the settings if we don't have qmaster or execd port
365
if [ -z "$SGE_QMASTER_PORT" -o -z "$SGE_EXECD_PORT" ]; then
366
if [ -r $SGE_ROOT/$SGE_CELL/common/settings.sh ]; then
367
. "$SGE_ROOT/$SGE_CELL/common/settings.sh"
369
$INFOTEXT "Can't read \$SGE_ROOT/\$SGE_CELL/common/settings.sh"
370
$INFOTEXT "Missing SGE_QMASTER_PORT or SGE_EXECD_PORT!"
374
if [ -z "$SGE_CLUSTER_NAME" -a -z "$3" ]; then
375
$INFOTEXT "Missing SGE_CLUSTER_NAME argument!"
380
SGE_CLUSTER_NAME="$3"
385
if [ "$cmd" = "supported" ]; then
386
$INFOTEXT "SMF is supported on your system."
388
elif [ "$cmd" = "register" ]; then
391
if [ $ret -ne 0 ]; then
392
$INFOTEXT "Register failed."
394
elif [ "$cmd" = "unregister" ]; then
397
if [ $ret -ne 0 ]; then
398
$INFOTEXT "Unregister failed."