3
# SGE configuration script (Upgrade/Downgrade)
4
# Scriptname: inst_upgrade.sh
5
# Module: common upgrade functions
8
##########################################################################
10
# The Contents of this file are made available subject to the terms of
11
# the Sun Industry Standards Source License Version 1.2
13
# Sun Microsystems Inc., March, 2001
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
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.
30
# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
32
# Copyright: 2001 by Sun Microsystems, Inc.
34
# All Rights Reserved.
36
##########################################################################
40
#--------------------------------------------------------------------------
41
# WelcomeTheUserUpgrade - upgrade welcome message
43
WelcomeTheUserUpgrade()
45
$INFOTEXT -u "\nWelcome to the Grid Engine Upgrade"
46
$INFOTEXT "\nBefore you continue with the upgrade, read these hints:\n\n" \
47
" - Your terminal window should have a size of at least\n" \
48
" 80x24 characters\n\n" \
49
" - At any time during the upgrade process, use your standard \n" \
50
" interrupt key to abort the upgrade. Typically, the interrupt \n" \
51
" key combination is Ctrl-C.\n\n" \
52
"The upgrade procedure will take approximately 1-2 minutes.\n"
53
$INFOTEXT -wait -auto $AUTO -n "Hit <RETURN> to continue >> "
57
#-------------------------------------------------------------------------------
58
# GetBackupedAdminUser: Get admin user form the cluster configuration backup
59
# TODO: Cleanup duplicit with inst_common.sh GetAdminUser()
60
GetBackupedAdminUser()
62
ADMIN_USER=`BootstrapGetValue "$UPGRADE_BACKUP_DIR/cell" admin_user`
63
euid=`$SGE_UTILBIN/uidgid -euid`
65
TMP_USER=`echo "$ADMINUSER" |tr "A-Z" "a-z"`
66
if [ \( -z "$TMP_USER" -o "$TMP_USER" = "none" \) -a $euid = 0 ]; then
70
if [ "$SGE_ARCH" = "win32-x86" ]; then
71
HOSTNAME=`hostname | tr "a-z" "A-Z"`
72
ADMINUSER="$HOSTNAME+$ADMINUSER"
76
#TODO: Use it in inst_sge
77
#-------------------------------------------------------------------------------
78
# FileGetValue: Get values from a file for appropriate key
79
# $1 - PATH to the file
80
# $2 - key: e.g: qmaster_spool_dir | ignore_fqdn | default_domain, etc.
84
$INFOTEXT "Expecting 2 arguments for FileGetValue. Got %s." $#
87
if [ ! -f "$1" ]; then
88
$INFOTEXT "No file %s found" $1
91
echo `cat $1 | grep "$2" | awk '{ print $2}' 2>/dev/null`
94
#Helper to get bootstrap file values
98
FileGetValue "$1/bootstrap" $2
101
#-------------------------------------------------------------------------------
102
# CheckUpgradeUser: Check if valid user performs the upgrade
106
if [ $euid -ne 0 -a `whoami` != "$ADMINUSER" ]; then
107
$INFOTEXT "\nUpgrade procedure must be started as a root or admin user.\nCurrent user is `whoami`."
109
elif [ "$OLD_ADMIN_USER" != "$ADMIN_USER" ]; then
110
$INFOTEXT "\nCannot use this backup for the upgrade.\n" \
111
" current admin user: '$OLD_ADMIN_USER'\n" \
112
" admin user in the backup: '$ADMIN_USER'\n" \
113
"Seems like this is not a backup of this cluster. If you want really continue \n" \
114
"with this backup manually edit bootstrap file in the backup to have the same \n" \
115
"admin user as your cluster currently has."
120
#-------------------------------------------------------------------------------
121
# GetBackupDirectory: Ask for backup directory. Udes during the upgrade.
126
while [ $done = false ]; do
128
$INFOTEXT -u "\nType the complete path to the Grid Engine configuration backup directory."
129
$INFOTEXT -n " Backup directory >> "
130
eval UPGRADE_BACKUP_DIR=`Enter $UPGRADE_BACKUP_DIR`
131
version=`cat "${UPGRADE_BACKUP_DIR}/version" 2>/dev/null`
132
backup_date=`cat "${UPGRADE_BACKUP_DIR}/backup_date" 2>/dev/null`
133
if [ -n "$version" -a -n "$backup_date" -a -d "${UPGRADE_BACKUP_DIR}/cell" ]; then
135
$INFOTEXT -n "\nFound backup from $version version created on $backup_date"
136
$INFOTEXT -auto $AUTO -ask "y" "n" -def "y" -n "\nContinue with this backup directory (y/n) [y] >> "
137
if [ $? -eq 0 ]; then
142
$INFOTEXT -n "\n$UPGRADE_BACKUP_DIR is not a valid backup directory!"
143
$INFOTEXT -auto $AUTO -ask "y" "n" -def "y" -n "\nEnter a new backup directory or exit ('n') (y/n) [y] >> "
144
if [ $? -ne 0 ]; then
151
#-------------------------------------------------------------------------------
152
# RestoreCell: Restore backuped cell directory
153
# $1 - BACKUPED_CELL_DIRECTORY
157
if [ ! -d "$SGE_ROOT/$SGE_CELL/common" ]; then
158
ExecuteAsAdmin mkdir -p "$SGE_ROOT/$SGE_CELL/common"
169
for f in $FILE_LIST; do
170
if [ -f "${old_cell}/$f" ]; then
171
ExecuteAsAdmin cp -f "${old_cell}/$f" "$SGE_ROOT/$SGE_CELL/common"
175
#Modify bootstrap file
176
ExecuteAsAdmin $CHMOD 666 "$SGE_ROOT/$SGE_CELL/common/bootstrap"
178
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'Version.*' "Version: $SGE_VERSION"
180
if [ $ADMINUSER != default ]; then
181
admin_user_value="admin_user $ADMINUSER"
183
admin_user_value="admin_user none"
185
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'admin_user.*' "$admin_user_value"
186
#TODO: default_domain, ignore_fqdn?
188
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'binary_path.*' "binary_path $SGE_ROOT/bin"
190
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'qmaster_spool_dir.*' "qmaster_spool_dir $QMDIR"
192
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'security_mode.*' "security_mode $PRODUCT_MODE"
194
#Remove gdi_threads if present
195
RemoveLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'gdi_threads.*'
197
#Add threads info if missing
198
cat $SGE_ROOT/$SGE_CELL/common/bootstrap | grep "threads" >/dev/null 2>&1
199
do_bootstrap_upgrade=$?
200
if [ $do_bootstrap_upgrade -eq 1 ]; then
201
$ECHO "listener_threads 2" >> $SGE_ROOT/$SGE_CELL/common/bootstrap
202
$ECHO "worker_threads 2" >> $SGE_ROOT/$SGE_CELL/common/bootstrap
203
$ECHO "scheduler_threads 1" >> $SGE_ROOT/$SGE_CELL/common/bootstrap
206
if [ "$SGE_ENABLE_JMX" = "true" ]; then
207
ReplaceOrAddLine "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'jvm_threads.*' "jvm_threads 1"
209
ReplaceOrAddLine "$SGE_ROOT/$SGE_CELL/common/bootstrap" 666 'jvm_threads.*' "jvm_threads 0"
211
ExecuteAsAdmin $CHMOD 644 "$SGE_ROOT/$SGE_CELL/common/bootstrap"
214
#-------------------------------------------------------------------------------
215
# RestoreJMX: Ask if JMX setting from the backup should be used
216
# $1 - BACKUPED_JMX_DIRECTORY
220
if [ "$SGE_ENABLE_JMX" = "true" -a -d "${old_jmx}" ]; then
222
$INFOTEXT -n "\nFound JMX settings in the backup"
223
$INFOTEXT -auto $AUTO -ask "y" "n" -def "y" -n "\nUse the JMX settings from the backup ('y') or reconfigure ('n') (y/n) [y] >> "
224
if [ $? -eq 0 ]; then
226
ExecuteAsAdmin cp -r "${old_jmx}" "$SGE_ROOT/$SGE_CELL/common"
232
#-------------------------------------------------------------------------------
233
# NewIJS: Ask if JMX setting from the backup should be used
234
# $1 - BACKUPED_JMX_DIRECTORY
239
$INFOTEXT -u "Interactive Job Support (IJS) Selection"
240
$INFOTEXT -auto $AUTO -ask "y" "n" -def "y" -n "\nThe backup configuration includes information for running \n" \
241
"interactive jobs. Do you want to use the IJS information from \n" \
242
"the backup ('y') or use new default values ('n') (y/n) [y] >> "
243
if [ $? -ne 0 ]; then
244
$INFOTEXT -n "\nUsing new interactive job support default setting for a new installation."
247
$INFOTEXT -wait -auto $AUTO -n "\nHit <RETURN> to continue >> "
251
#-------------------------------------------------------------------------------
252
# AskForNewSequenceNumber: Ask for the next sequence number
253
# $1 - file with the seq_number
255
AskForNewSequenceNumber()
258
if [ ! -f "$1" ]; then #set to 0 is no file in backup and don't ask
262
NEXT_SEQ_NUMBER=`cat "${1}" 2>/dev/null`
263
if [ -z "$NEXT_SEQ_NUMBER" -o "$NEXT_SEQ_NUMBER" -lt 0 ]; then
266
#Add 1000 and round up
267
NEXT_SEQ_NUMBER=`expr $NEXT_SEQ_NUMBER / 1000 + 1`
268
NEXT_SEQ_NUMBER=`expr $NEXT_SEQ_NUMBER \* 1000`
270
if [ "$2" != "job" -a "$2" != "AR" ]; then
271
$INFOTEXT "Invalid value '"$2"' provided to AskForNewSequenceNumber"
275
$INFOTEXT -u "Provide a value to use for the next %s ID." "$2"
276
$INFOTEXT -n "\nBackup contains last %s ID. As a suggested value, we added 1000 \n" \
277
"to that number and rounded it to the nearest 1000.\n" \
278
"Increase the value, if appropriate.\n" \
279
"Choose the new next %s ID [%s] >> " "$2" "$2" "$NEXT_SEQ_NUMBER"
280
eval NEXT_SEQ_NUMBER=`Enter $NEXT_SEQ_NUMBER`
281
$INFOTEXT -wait -auto $AUTO -n "\nHit <RETURN> to continue >> "
285
#-------------------------------------------------------------------------------
286
# RestoreSequenceNumberFiles: Ask for the next sequence number
287
# $1 - qmaster_spool_dir
288
RestoreSequenceNumberFiles()
291
AskForNewSequenceNumber "${UPGRADE_BACKUP_DIR}/jobseqnum" "job"
292
SafelyCreateFile "$QMASTER_SPOOL_DIR/jobseqnum" 644 $NEXT_SEQ_NUMBER
293
AskForNewSequenceNumber "${UPGRADE_BACKUP_DIR}/arseqnum" "AR"
294
SafelyCreateFile "$QMASTER_SPOOL_DIR/arseqnum" 644 $NEXT_SEQ_NUMBER
297
#Copy of inst_execd.sh UnInstWinHelperSvc but modified for pre62
298
#TODO: needs to be done on every windows execd host
299
#TODO: cleanup duplicit with UnInstWinHelper()
300
UninstWinHelperPre62() {
302
PATH=/usr/contrib/win32/bin:/common:$SAVED_PATH
305
WIN_SVC="N1 Grid Engine Helper Service"
306
WIN_DIR=`winpath2unix $SYSTEMROOT`
307
$INFOTEXT " Testing, if windows helper service is installed!\n"
308
eval "net pause \"$WIN_SVC\"" > /dev/null 2>&1
310
if [ "$ret" = 0 ]; then
312
$INFOTEXT " ... a service is installed!"
313
$INFOTEXT -log " ... a service is installed!"
314
$INFOTEXT " ... stopping service!"
315
$INFOTEXT -log " ... stopping service!"
317
while [ "$ret" -ne 0 ]; do
318
eval "net continue \"$WIN_SVC\"" > /dev/null 2>&1
322
$INFOTEXT " ... no service installed!"
323
$INFOTEXT -log " ... no service installed!"
326
if [ -f "$WIN_DIR"/N1_Helper_Service.exe ]; then
327
$INFOTEXT " ... found service binary!"
328
$INFOTEXT -log " ... found service binary!"
329
$INFOTEXT " ... uninstalling service!"
330
$INFOTEXT -log " ... uninstalling service!"
331
$WIN_DIR/Sun_Helper_Service.exe -uninstall
332
rm $WIN_DIR/Sun_Helper_Service.exe
339
#Select spooling method
340
# $1 - backued spooling method
343
backuped_spooling_method=$1
344
if [ "$backuped_spooling_method" != "berkeleydb" -a "$backuped_spooling_method" != "classic" ]; then
345
$INFOTEXT "Invalid arg $1 to SelectNewSpooling"
352
$INFOTEXT -auto $AUTO -ask "y" "n" -def "y" -n "\nUse backuped %s spooling method ('y') or use new spooling configuration ('n') (y/n) [y] >> " \
353
$backuped_spooling_method
354
if [ $? -eq 0 ]; then
356
SPOOLING_METHOD=`BootstrapGetValue $SGE_ROOT/$SGE_CELL/common "spooling_method"`
357
SPOOLING_LIB=`BootstrapGetValue $SGE_ROOT/$SGE_CELL/common "spooling_lib"`
358
SPOOLING_ARGS=`BootstrapGetValue $SGE_ROOT/$SGE_CELL/common "spooling_params"`
359
if [ "$SPOOLING_METHOD" = "berkeleydb" ]; then
360
ExecuteAsAdmin rm -rf "$SPOOLING_ARGS"/*
362
tmp_spool=`echo $SPOOLING_ARGS | awk -F";" '{print $1}' | awk '{print $2}'`
367
ExecuteAsAdmin rm -rf "${tmp_spool}/${f}"
374
if [ "$keep" = false ]; then
375
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 644 'spooling_method.*' "spooling_method $SPOOLING_METHOD"
376
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 644 'spooling_lib.*' "spooling_lib $SPOOLING_LIB"
377
ReplaceLineWithMatch "$SGE_ROOT/$SGE_CELL/common/bootstrap" 644 'spooling_params.*' "spooling_params $SPOOLING_ARGS"
381
#AddDummyConfiguration - add a dummy configuration so we can start qmaster
383
AddDummyConfiguration()
385
CFG_EXE_SPOOL=$QMDIR/execd
389
CFG_GID_RANGE=20000-21000
390
QLOGIN_COMMAND=builtin
391
QLOGIN_DAEMON=builtin
392
RLOGIN_COMMAND=builtin
393
RLOGIN_DAEMON=builtin
397
TMPC=/tmp/configuration
399
SafelyCreateFile $TMPC 666 ""
401
ExecuteAsAdmin $SPOOLDEFAULTS configuration $TMPC
402
ExecuteAsAdmin rm -f $TMPC
405
#For copy upgrade type
406
PrepareConfiguration()
409
tmp_range=`FileGetValue "$UPGRADE_BACKUP_DIR/configurations/global" "gid_range"`
410
echo "$tmp_range" | grep -- "-" >/dev/null 2>&1
411
if [ $? -ne 0 ]; then #single value
412
GID_RANGE=`expr $tmp_range + 100`
414
tmp_start=`echo $tmp_range | awk -F"-" ' { print $1 }'`
415
tmp_end=`echo $tmp_range | awk -F"-" ' { print $2 }'`
416
tmp_range=`expr $tmp_end - $tmp_start`
417
tmp_end=`expr $tmp_end + 100`
418
GID_RANGE="${tmp_end}-`expr $tmp_end + $tmp_range`"
420
GetConfiguration "$SGE_ROOT/$SGE_CELL/spool" `FileGetValue "$UPGRADE_BACKUP_DIR/configurations/global" "administrator_mail"`
423
ReplaceLineWithMatch()
425
repFile="${1:?Need the file name to operate}"
426
filePerms="${2:?Need file final permissions}"
427
repExpr="${3:?Need an expression, where to replace}"
428
replace="${4:?Need the replacement text}"
431
grep "${repExpr}" $repFile >/dev/null 2>&1
432
if [ $? -ne 0 ]; then
435
#We need to change the file
436
ExecuteAsAdmin touch ${repFile}.tmp
437
ExecuteAsAdmin chmod 666 ${repFile}.tmp
440
echo "$repExpr $replace" | grep "|" >/dev/null 2>&1
441
if [ $? -eq 0 ]; then
442
echo "$repExpr $replace" | grep "%" >/dev/null 2>&1
443
if [ $? -ne 0 ]; then
446
echo "$repExpr $replace" | grep "?" >/dev/null 2>&1
447
if [ $? -ne 0 ]; then
450
$INFOTEXT "repExpr $replace contains |,% and ? characters: cannot use sed"
455
#We need to change the file
456
sed -e "s${SEP}${repExpr}${SEP}${replace}${SEP}g" "$repFile" >> "${repFile}.tmp"
457
ExecuteAsAdmin mv -f "${repFile}.tmp" "${repFile}"
458
ExecuteAsAdmin chmod "${filePerms}" "${repFile}"
463
repFile="${1:?Need the file name to operate}"
464
filePerms="${2:?Need file final permissions}"
465
repExpr="${3:?Need an expression, where to replace}"
466
replace="${4:?Need the replacement text}"
468
#Does the pattern exists
469
grep "${repExpr}" "${repFile}" > /dev/null 2>&1
470
if [ $? -eq 0 ]; then #match
471
ReplaceLineWithMatch "$repFile" "$filePerms" "$repExpr" "$replace"
472
else #line does not exist
473
echo "$replace" >> "$repFile"
477
#Remove line with maching expression
478
RemoveLineWithMatch()
480
remFile="${1:?Need the file name to operate}"
481
filePerms="${2:?Need file final permissions}"
482
remExpr="${3:?Need an expression, where to remove lines}"
485
grep "${remExpr}" $remFile >/dev/null 2>&1
486
if [ $? -ne 0 ]; then
490
#We need to change the file
491
ExecuteAsAdmin touch ${remFile}.tmp
492
ExecuteAsAdmin chmod 666 ${remFile}.tmp
493
sed -e "/${remExpr}/d" "$remFile" > "${remFile}.tmp"
494
ExecuteAsAdmin mv -f "${remFile}.tmp" "${remFile}"
495
ExecuteAsAdmin chmod "${filePerms}" "${remFile}"