~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/dist/util/sgeST/sge_st

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#
 
4
#
 
5
# Sun Grid Engine service tag management script
 
6
#
 
7
#___INFO__MARK_BEGIN__
 
8
##########################################################################
 
9
#
 
10
#  The Contents of this file are made available subject to the terms of
 
11
#  the Sun Industry Standards Source License Version 1.2
 
12
#
 
13
#  Sun Microsystems Inc., March, 2001
 
14
#
 
15
#
 
16
#  Sun Industry Standards Source License Version 1.2
 
17
#  =================================================
 
18
#  The contents of this file are subject to the Sun Industry Standards
 
19
#  Source License Version 1.2 (the "License"); You may not use this file
 
20
#  except in compliance with the License. You may obtain a copy of the
 
21
#  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
22
#
 
23
#  Software provided under this License is provided on an "AS IS" basis,
 
24
#  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
25
#  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
26
#  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
27
#  See the License for the specific provisions governing your rights and
 
28
#  obligations concerning the Software.
 
29
#
 
30
#  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
31
#
 
32
#  Copyright: 2001 by Sun Microsystems, Inc.
 
33
#
 
34
#  All Rights Reserved.
 
35
#
 
36
##########################################################################
 
37
#___INFO__MARK_END__
 
38
 
 
39
 
 
40
#---------------------------------------------------------------------------
 
41
# This script requires the that $SGE_ROOT and $SGE_CELL be set
 
42
#
 
43
 
 
44
if [ -z "$SGE_ROOT" -o -z "$SGE_CELL" ]; then
 
45
   echo "\$SGE_ROOT and \$SGE_CELL must be set to valid values"
 
46
   exit 1
 
47
fi
 
48
 
 
49
if [ -z "$ARCH" ]; then
 
50
   ARCH=`$SGE_ROOT/util/arch`
 
51
fi
 
52
 
 
53
if [ -z "$V5UTILBIN" ]; then
 
54
   V5UTILBIN=$SGE_ROOT/utilbin/$ARCH              # adminrun, infotext, openssl, uidgid
 
55
fi
 
56
 
 
57
if [ ! -d "$V5UTILBIN" ]; then
 
58
   echo
 
59
   echo "Error: The utilbin directory "$V5UTILBIN" does not exist"
 
60
   echo "Please verify your setup and restart this script. Exit."
 
61
   exit 1
 
62
fi
 
63
 
 
64
if [ -z "$INFOTEXT" ]; then
 
65
   INFOTXT_DUMMY=$V5UTILBIN/infotext
 
66
   INFOTEXT=$INFOTXT_DUMMY
 
67
   if [ ! -x $INFOTXT_DUMMY ]; then
 
68
      echo "Error: Can't find binary \"$INFOTXT_DUMMY\""
 
69
      echo "Please verify your setup and restart this script. Exit."
 
70
      exit 1
 
71
   fi
 
72
 
 
73
   # Test the infotext binary
 
74
   tmp=`$INFOTEXT test 2>&1`
 
75
   if [ $? -ne 0 ]; then
 
76
      echo "Error: Execution of $INFOTEXT failed: $tmp"
 
77
      echo "Please verify your setup and restart this script. Exit."
 
78
      exit 1
 
79
   fi
 
80
 
 
81
   SGE_INFOTEXT_MAX_COLUMN=5000; export SGE_INFOTEXT_MAX_COLUMN
 
82
fi
 
83
 
 
84
# ST are supported just on linux and solaris
 
85
case $ARCH in
 
86
  lx* | sol*)
 
87
   ;;
 
88
  *) 
 
89
   if [ -z "$2" ]; then
 
90
      $INFOTEXT "The service tags are not supported"
 
91
   fi  
 
92
   exit 0
 
93
   ;;  
 
94
esac
 
95
 
 
96
 
 
97
#customized cut
 
98
CUT=cut
 
99
 
 
100
#---------------------------------------------------------------------------
 
101
# show the usage of the standalone command
 
102
# if ADMINUSER = default then execute command unchanged
 
103
STusage()
 
104
{
 
105
   $INFOTEXT "sge_st enable|disable|register|unregister|check|enabled|supported|help"
 
106
   $INFOTEXT " -------------------------------------------------------------------------------"
 
107
   $INFOTEXT "       enable   ... enable The Service Tags"
 
108
   $INFOTEXT "       disable  ... disable The Service Tags"
 
109
   $INFOTEXT "       register ... register product"
 
110
   $INFOTEXT "       unregister . unregister product"
 
111
   $INFOTEXT "       check    ... check if the product is registered"
 
112
   $INFOTEXT "       enabled  ... check if the Service Tags are enabled"
 
113
   $INFOTEXT "       supported .. check if the Service Tags packages are installed on host"
 
114
   $INFOTEXT "       help     ... this help"
 
115
}
 
116
 
 
117
#-------------------------------------------------------------------------
 
118
#arch_variables Setting up common variables and paths
 
119
#
 
120
STArchVariables()
 
121
{
 
122
   if [ -f "$SGE_ROOT/util/arch_variables" ]; then
 
123
     . $SGE_ROOT/util/arch_variables
 
124
   else
 
125
      $INFOTEXT "Could not source arch_variables"
 
126
      exit 1
 
127
   fi
 
128
}
 
129
 
 
130
#-------------------------------------------------------------------------
 
131
#Service Tags Setting up 
 
132
#
 
133
STBasicSettings()
 
134
{  
 
135
   stclient=""
 
136
   if [ -f "$SGE_ROOT/util/sgeST/st_settings.sh" ]; then
 
137
      . $SGE_ROOT/util/sgeST/st_settings.sh
 
138
   else
 
139
      $INFOTEXT "Could not source basic settings"
 
140
      exit 1
 
141
   fi
 
142
}
 
143
 
 
144
#---------------------------------------------------------------------------
 
145
# Test the instance_urn is valid
 
146
# urn should start with urn:st
 
147
# USES: parameter $1 "instance_urn" 
 
148
# Return "true" /  "false"  to strdout 
 
149
#
 
150
STvalidateInstanceUrn()
 
151
{  
 
152
   ret="false"
 
153
   if [ -n "$1" ]; then
 
154
      instance_urn_valid=`echo "$1" | $CUT -f1-2 -d:`
 
155
      if [ "$instance_urn_valid" = "urn:st" ]; then
 
156
         ret="true"
 
157
      fi
 
158
   fi
 
159
   echo $ret
 
160
}
 
161
 
 
162
#---------------------------------------------------------------------------
 
163
# The Service Tags Enabled Test
 
164
# Return true if the st.enabled file is present
 
165
#
 
166
# Return "true", the ST are enabled, "false" ST are not enabled
 
167
STShowEnabled()
 
168
{
 
169
   st_file=$SGE_ROOT/$SGE_CELL/common/st.enabled
 
170
   if [ -f "$st_file" ]; then
 
171
      echo "true"
 
172
   else
 
173
      echo "false"
 
174
   fi
 
175
}
 
176
 
 
177
#---------------------------------------------------------------------------
 
178
# Enable the service tegs
 
179
STEnable()
 
180
{
 
181
   st_file=$SGE_ROOT/$SGE_CELL/common/st.enabled
 
182
   if [ ! -f "$st_file" ]; then
 
183
      CreateAndMakeWriteable $st_file
 
184
      echo $PRODUCT_URN >> $st_file
 
185
      result=`STShowEnabled`
 
186
      if [ $result = "true" ]; then
 
187
         $INFOTEXT "Sun Service Tags are now enabled"
 
188
      else
 
189
         $INFOTEXT "Sun Service Tags could not be enabled"
 
190
         return 1
 
191
      fi
 
192
   fi   
 
193
   return 0
 
194
}
 
195
 
 
196
#---------------------------------------------------------------------------
 
197
# Disable The Service Tags
 
198
#
 
199
STDisable()
 
200
{
 
201
   st_file=$SGE_ROOT/$SGE_CELL/common/st.enabled
 
202
   if [ -f "$st_file" ]; then
 
203
      ExecuteAsAdmin $RM $st_file
 
204
      result=`STShowEnabled`
 
205
      if [ $result = "false" ]; then
 
206
         $INFOTEXT "Sun Service Tags are now disabled"
 
207
      else 
 
208
         $INFOTEXT "Sun Service Tags could not be disabled"
 
209
         return 1
 
210
      fi
 
211
   fi      
 
212
   return 0
 
213
}
 
214
 
 
215
#---------------------------------------------------------------------------
 
216
# Get the product instance_URN from ST registry 
 
217
# using the find all instances of the product function
 
218
#
 
219
# PARAMS: $stclient 
 
220
#         $product_defined_id
 
221
# return $instance_urn to stdout
 
222
STgetInstanceUrn()
 
223
{
 
224
   stclient=$1
 
225
   product_defined_id=$2
 
226
   instance_urn=""
 
227
   #find first product instance with the same product_defined_inst_id
 
228
   urn_list=`$stclient -f -t "$PRODUCT_URN"`
 
229
   for registered_urn in $urn_list ;do
 
230
      valid=`STvalidateInstanceUrn $registered_urn`
 
231
      if [ $valid = "true" ]; then
 
232
         registered_inst_id=`$stclient -g -i $registered_urn | grep product_defined_inst_id | $CUT -f2 -d=`
 
233
          if [ "$registered_inst_id" = "$product_defined_id" ]; then
 
234
            instance_urn=$registered_urn
 
235
            break
 
236
         fi
 
237
      fi;
 
238
   done
 
239
 
 
240
   echo $instance_urn
 
241
}
 
242
 
 
243
#---------------------------------------------------------------------------
 
244
# Test the stclient is valid and installed
 
245
#
 
246
# return stclient or "undefined" if not stclient
 
247
#
 
248
STgetServiceTagClient()
 
249
{
 
250
   if [ -z "$stclient" ]; then
 
251
      # library path setting required only for architectures where RUNPATH is not supported
 
252
      case $ARCH in
 
253
      lx*)
 
254
         stclient=`rpm -ql sun-servicetag 2>/dev/null | grep bin/stclient`
 
255
         ;;
 
256
      sol*)
 
257
         # a strange error message comes from pkgchk -l, need to be filtered out
 
258
         if [ -x /usr/bin/stclient ]; then
 
259
            stclient=/usr/bin/stclient
 
260
         fi   
 
261
         ;;
 
262
      esac
 
263
   fi
 
264
   if [ -z "$stclient" ]; then
 
265
      stclient="undefined"
 
266
   fi
 
267
   echo $stclient
 
268
}
 
269
 
 
270
#---------------------------------------------------------------------------
 
271
# Sub function create st client
 
272
# return registered or not to stdout
 
273
STClient()
 
274
{
 
275
   #get the stclinet with full path
 
276
   stclient=`STgetServiceTagClient`
 
277
   if [ "$stclient" = "undefined" ]; then
 
278
      $INFOTEXT "The service tags are not supported"    
 
279
      return 1
 
280
   fi 
 
281
   #the executeble file must exist
 
282
   if [ ! -x "$stclient" ]; then
 
283
      $INFOTEXT "The service tags are not installed correctly" 
 
284
      return 1
 
285
   fi
 
286
 
 
287
   return 0
 
288
}
 
289
 
 
290
 
 
291
#---------------------------------------------------------------------------
 
292
# The Service Tags Packages are installed on the node
 
293
#
 
294
# Return "true", the ST are supported, "false" ST are not  supported
 
295
STShowSupported()
 
296
{
 
297
   #get the stclinet with full path
 
298
   stclient=`STgetServiceTagClient`
 
299
   if [ "$stclient" = "undefined" ]; then
 
300
      echo "false"
 
301
   else
 
302
      #the executable file must exist
 
303
      if [ -x "$stclient" ]; then
 
304
         echo "true" 
 
305
      else
 
306
         echo "false"
 
307
      fi
 
308
   fi
 
309
}
 
310
 
 
311
#---------------------------------------------------------------------------
 
312
# Get the product instance_URN from ST registry 
 
313
# using the find all instances of the product function
 
314
#
 
315
# PARAMS: $product_defined_id
 
316
# return registered or unregistered
 
317
STShowRegistered()
 
318
{
 
319
   product_defined_id=$1
 
320
 
 
321
   STClient
 
322
   if [ $? = 0 ]; then
 
323
      #check again, to be sure wos done
 
324
      instance_urn=`STgetInstanceUrn "$stclient" "$product_defined_id"`
 
325
      if [ -n "$instance_urn" ]; then
 
326
         $INFOTEXT "registered:%s" "$instance_urn"
 
327
      else
 
328
         $INFOTEXT "unregistered"
 
329
      fi
 
330
   fi   
 
331
}
 
332
 
 
333
#---------------------------------------------------------------------------
 
334
# Add a new instance of product to a ST registry 
 
335
# using the platform CLI command
 
336
# Add only if $instance_urn is empty
 
337
#
 
338
# ARGS: $stclient CLI tool
 
339
#       $instance_urn 
 
340
#       $product_defined_id
 
341
#   
 
342
STaddServiceTag()
 
343
{
 
344
   stclient=$1
 
345
   instance_urn=$2
 
346
   product_defined_id=$3
 
347
   if [ -z "$instance_urn" ]; then
 
348
      platform_name=`uname -p`
 
349
 
 
350
      case $ARCH in
 
351
      lx*)
 
352
         zone=`uname`
 
353
         ;;
 
354
      sol*)
 
355
         zone="global"
 
356
 
 
357
         if [ -x /usr/bin/zonename ]; then
 
358
            zone=`/usr/bin/zonename`
 
359
         fi
 
360
         ;;
 
361
      esac
 
362
      
 
363
      ExecuteAsAdmin ${stclient} -a \
 
364
      -p "${PRODUCT_NAME}" \
 
365
      -e "${PRODUCT_VERSION}" \
 
366
      -t "${PRODUCT_URN}" \
 
367
      -P "${PRODUCT_PARENT_NAME}" \
 
368
      -I "${product_defined_id}" \
 
369
      -m "${PRODUCT_VENDOR}" \
 
370
      -A "${platform_name}" \
 
371
      -z "${zone}" \
 
372
      -S "${PRODUCT_SOURCE}" > /dev/null 2>&1
 
373
   fi
 
374
}
 
375
 
 
376
#---------------------------------------------------------------------------
 
377
# Remove instance of product to a ST registry 
 
378
# using the platform CLI command
 
379
# Remove only if $instance_urn is not empty
 
380
#
 
381
# USES: $stclient CLI tool
 
382
#       $instance_urn 
 
383
 
384
STremoveServiceTag()
 
385
{
 
386
   stclient=$1
 
387
   instance_urn=$2
 
388
   if [ -n "$instance_urn" ]; then
 
389
      ExecuteAsAdmin $stclient -d -i "$instance_urn"  > /dev/null  2>&1
 
390
   fi
 
391
}
 
392
 
 
393
#---------------------------------------------------------------------------
 
394
# show the usage of the standalone command
 
395
# PARAMS: $product_defined_id
 
396
# return registered or not to stdout
 
397
STRegister()
 
398
{   
 
399
   product_defined_id=$1
 
400
 
 
401
   #get the stclinet with full path
 
402
   STClient
 
403
   if [ $? = 0 ]; then
 
404
      STEnable
 
405
      if [ $? = 0 ]; then
 
406
         # get instance_urn
 
407
         instance_urn=`STgetInstanceUrn "$stclient" "$product_defined_id"`
 
408
         STaddServiceTag "$stclient" "$instance_urn" "$product_defined_id"
 
409
         STShowRegistered "$product_defined_id"
 
410
      fi   
 
411
   fi   
 
412
}
 
413
 
 
414
#---------------------------------------------------------------------------
 
415
# show the usage of the standalone command
 
416
# PARAMS: $product_defined_id
 
417
# return registered or not to stdout
 
418
STUnregister()
 
419
{
 
420
   product_defined_id=$1
 
421
 
 
422
   STClient
 
423
   if [ $? = 0 ]; then
 
424
      # get instance_urn
 
425
      instance_urn=`STgetInstanceUrn "$stclient" "$product_defined_id"`
 
426
      STremoveServiceTag "$stclient" "$instance_urn"
 
427
      STShowRegistered "$product_defined_id"
 
428
   fi   
 
429
}
 
430
 
 
431
#---------------------------------------------------------------------------
 
432
# Main routine
 
433
# PARAMS: $command 
 
434
#         check ... called from install script
 
435
# return a customer stdout output
 
436
STServiceTag()
 
437
{   
 
438
   command="$1"
 
439
   if [ "$#" -lt 1 -o  "$#" -gt 2 -o "$command" = "-h" -o "$command" = "help" ]; then
 
440
      STusage
 
441
      return 0
 
442
   fi
 
443
 
 
444
   #Architecture related variables
 
445
   STArchVariables
 
446
   #ExecuteAsAdmin
 
447
   SetAdminUser
 
448
   #load static data from file
 
449
   STBasicSettings
 
450
   #redefine dynamic data for instalation
 
451
   product_defined_id=$SGE_ROOT/$SGE_CELL
 
452
 
 
453
   if [ "$command" = "enable" ]; then
 
454
      STEnable 
 
455
   elif [ "$command" = "disable" ]; then
 
456
      STDisable 
 
457
   elif [ "$command" = "register" ]; then
 
458
      STRegister "$product_defined_id"
 
459
   elif [ "$command" = "unregister" ]; then
 
460
      STUnregister "$product_defined_id"
 
461
   elif [ "$command" = "enabled" ]; then
 
462
      STShowEnabled
 
463
   elif [ "$command" = "supported" ]; then
 
464
      STShowSupported
 
465
   elif [ "$command" = "check" ]; then
 
466
      STShowRegistered "$product_defined_id"
 
467
   else
 
468
      STusage
 
469
      return 1
 
470
   fi
 
471
   return 0
 
472
}
 
473
 
 
474
STServiceTag $1