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

« back to all changes in this revision

Viewing changes to source/dist/util/install_modules/inst_execd_uninst.sh

  • 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
# SGE configuration script (Installation/Uninstallation/Upgrade/Downgrade)
 
4
# Scriptname: inst_execd_uninst.sh
 
5
#
 
6
#___INFO__MARK_BEGIN__
 
7
##########################################################################
 
8
#
 
9
#  The Contents of this file are made available subject to the terms of
 
10
#  the Sun Industry Standards Source License Version 1.2
 
11
#
 
12
#  Sun Microsystems Inc., March, 2001
 
13
#
 
14
#
 
15
#  Sun Industry Standards Source License Version 1.2
 
16
#  =================================================
 
17
#  The contents of this file are subject to the Sun Industry Standards
 
18
#  Source License Version 1.2 (the "License"); You may not use this file
 
19
#  except in compliance with the License. You may obtain a copy of the
 
20
#  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
21
#
 
22
#  Software provided under this License is provided on an "AS IS" basis,
 
23
#  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
24
#  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
25
#  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
26
#  See the License for the specific provisions governing your rights and
 
27
#  obligations concerning the Software.
 
28
#
 
29
#  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
30
#
 
31
#  Copyright: 2001 by Sun Microsystems, Inc.
 
32
#
 
33
#  All Rights Reserved.
 
34
#
 
35
##########################################################################
 
36
#___INFO__MARK_END__
 
37
#
 
38
# set -x
 
39
 
 
40
WelcomeUninstall()
 
41
{
 
42
   if [ $AUTO = true ]; then
 
43
      return
 
44
   fi
 
45
 
 
46
   $INFOTEXT -u "Grid Engine uninstallation"
 
47
   if [ "$ALL_EXECDS" = true ]; then
 
48
      $INFOTEXT "\nYou are going to uninstall all execution hosts!\n" \
 
49
                "If you are not sure what you are doing, than please stop\n" \
 
50
                "this procedure with <CTRL-C>!\n" 
 
51
   else
 
52
      $INFOTEXT "\nYou are going to uninstall a execution host %s!\n" \
 
53
                "If you are not sure what you are doing, than please stop\n" \
 
54
                "this procedure with <CTRL-C>!\n" $HOST
 
55
   fi
 
56
   
 
57
   $INFOTEXT -wait -n "\nHit <RETURN> to continue >> "
 
58
   $CLEAR
 
59
}
 
60
 
 
61
FetchHostname()
 
62
{
 
63
   HOSTS=""
 
64
   euid=`$SGE_UTILBIN/uidgid -euid`
 
65
   local_host=`$SGE_UTILBIN/gethostname -aname`
 
66
   LOCAL_UNINST="false"
 
67
   REMOTE_UNINST_ARGS=""
 
68
 
 
69
   if [ $AUTO = "true" ]; then
 
70
      tmp_local=""
 
71
      tmp_host_list=""
 
72
      for h in $EXEC_HOST_LIST_RM; do     #set local_host to the end of the list. problem: on first pos the
 
73
         if [ $h = "$local_host" ]; then  #the local host will be removed from adminhost list, further
 
74
            tmp_local=$h                  #host uninstallation won't work, due to missing permissions
 
75
         else
 
76
            tmp_host_list="$tmp_host_list $h"
 
77
         fi
 
78
      done
 
79
      HOSTS="$tmp_host_list $tmp_local"
 
80
      REMOTE_UNINST_ARGS="-auto $FILE"
 
81
   else
 
82
      HOSTS="$HOST"
 
83
   fi
 
84
 
 
85
   if [ "$ALL_EXECDS" = true ]; then
 
86
      HOSTS=`qconf -sel`
 
87
   fi
 
88
   
 
89
   for h in $HOSTS; do
 
90
      if [ "$NOREMOTE" = "true" -a "$h" = "$local_host" ]; then    #only the local host (from RM list) should be uninstalled and 
 
91
         LOCAL_UNINST="true"                                    #if actual host is equal to local host do uninstallation
 
92
         doUninstall $h
 
93
         break                                                  #break loop, if host found and uninstalled
 
94
      fi
 
95
 
 
96
      if [ "$NOREMOTE" = "false" ]; then                            #also uninstall remote hosts
 
97
         if [ "$h" = "$local_host" ]; then                          #if actual host equals to local_host, no rsh/ssh is used for
 
98
            LOCAL_UNINST="true"                                    #uninstallation
 
99
            doUninstall $h
 
100
         else
 
101
            $INFOTEXT -n "The uninstall script has to login to the uninstalled execution host %s\n" \
 
102
                         "Enter the shell name to be used (rsh/ssh) [%s] >>" $h $SHELL_NAME
 
103
            SHELL_NAME=`Enter $SHELL_NAME`
 
104
            SHELL_NAME=`echo "$SHELL_NAME" | tr [A-Z] [a-z]`
 
105
            if [ "$SHELL_NAME" != "rsh" -a "$SHELL_NAME" != "ssh" ]; then
 
106
               $INFOTEXT -n "Skipping uninstallation of exec host $host.\n"\
 
107
                            "Invalid shell name %s was selected." $SHELL_NAME
 
108
               LOCAL_UNINST="false"
 
109
               continue
 
110
            fi
 
111
            which $SHELL_NAME >/dev/null 2>&1
 
112
            if [ $? -ne 0 ]; then
 
113
               $INFOTEXT ">>%s<< is not on your PATH!" $SHELL_NAME
 
114
               continue
 
115
            fi
 
116
            #h must be admin host
 
117
            qconf -ah $h >/dev/null 2>&1
 
118
            $SHELL_NAME $h "/bin/sh -c \"\
 
119
SGE_ROOT=$SGE_ROOT; export SGE_ROOT;\
 
120
SGE_CELL=$SGE_CELL; export SGE_CELL;\
 
121
SGE_REMOTE_FLAG=REMOTE_EXECD_UNINSTALL; export SGE_REMOTE_FLAG;\
 
122
cd $SGE_ROOT; ./inst_sge -ux $REMOTE_UNINST_ARGS\""
 
123
            #In case we failed we better remove admin host
 
124
            qconf -dh $h >/dev/null 2>&1
 
125
         fi
 
126
         LOCAL_UNINST="false"                                   #reset LOCAL_UNINST variable for following uninstallations
 
127
      fi
 
128
   done
 
129
 
 
130
}
 
131
 
 
132
DisableQueue()
 
133
{
 
134
   exechost=$1
 
135
 
 
136
   for q in `qstat -F -l h=$exechost | grep qname | cut -d"=" -f2`; do
 
137
 
 
138
     $INFOTEXT "Disabling queue %s now" $q
 
139
     $INFOTEXT -log "Disabling queue %s now" $q
 
140
     qmod -d $q@$exechost
 
141
 
 
142
   done
 
143
 
 
144
 
 
145
}
 
146
 
 
147
SuspendQueue()
 
148
{
 
149
   exechost=$1
 
150
 
 
151
   for q in `qstat -F -l h=$exechost | grep qname | cut -d"=" -f2`; do
 
152
 
 
153
     $INFOTEXT "Suspending queue %s now" $q
 
154
     $INFOTEXT -log "Suspending queue %s now" $q
 
155
     qmod -sq $q@$exechost
 
156
 
 
157
   done
 
158
 
 
159
 
 
160
}
 
161
 
 
162
SuspendJobs()
 
163
{
 
164
   exechost=$1
 
165
 
 
166
   for q in `qstat -F -l h=$exechost | grep qname | cut -d"=" -f2`; do
 
167
 
 
168
     $INFOTEXT "Suspending Checkpointing Jobs on queue %s now!" $q 
 
169
     $INFOTEXT -log "Suspending Checkpointing Jobs on queue %s now!" $q 
 
170
     qmod -sj $q@$exechost
 
171
 
 
172
   done
 
173
 
 
174
}
 
175
 
 
176
RescheduleJobs()
 
177
{
 
178
   exechost=$1
 
179
 
 
180
   for q in `qstat -F -l h=$exechost | grep qname | cut -d"=" -f2`; do
 
181
 
 
182
     $INFOTEXT "Rescheduling Jobs on queue %s now!" $q 
 
183
     $INFOTEXT -log "Rescheduling Jobs on queue %s now!" $q 
 
184
     qmod -r $q@$exechost
 
185
 
 
186
   done
 
187
 
 
188
   for q in `qstat -ne -F -l h=$exechost | grep qname | cut -d"=" -f2`; do
 
189
 
 
190
     $INFOTEXT "There are still running jobs on %s!" $q
 
191
     $INFOTEXT -log "There are still running jobs on %s!" $q
 
192
     $INFOTEXT "... trying to force a reschedule!"
 
193
     $INFOTEXT -log "... trying to force a reschedule!"
 
194
     qmod -f -r $q@$exechost 
 
195
 
 
196
   done
 
197
 
 
198
   for q in `qstat -ne -F -l h=$exechost | grep qname | cut -d"=" -f2`; do
 
199
 
 
200
     $INFOTEXT "There are still running jobs on %s!" $q
 
201
     $INFOTEXT -log "There are still running jobs on %s!" $q
 
202
     $INFOTEXT "To make sure, that no date will be lost, the uninstall\n" \
 
203
               "of this executionhost stops now!"
 
204
     $INFOTEXT "Please, check the running jobs and run uninstall again!"
 
205
     $INFOTEXT -log "To make sure, that no date will be lost, the uninstall\n" \
 
206
               "of this executionhost stops now!"
 
207
     $INFOTEXT -log "Please, check the running jobs and run uninstall again!"
 
208
     break
 
209
 
 
210
   done
 
211
}
 
212
 
 
213
RemoveQueues()
 
214
{
 
215
   exechost=$1
 
216
 
 
217
   for q in `qstat -F -l h=$exechost | grep qname | cut -d"=" -f2`; do
 
218
 
 
219
     $INFOTEXT "Deleting queue %s!" $q
 
220
     $INFOTEXT -log "Deleting queue %s!" $q
 
221
     
 
222
     for hgrp in `qconf -shgrpl`; do
 
223
         $SGE_BIN/qconf -dattr hostgroup hostlist $exechost $hgrp
 
224
     done
 
225
 
 
226
   done
 
227
 
 
228
}
 
229
 
 
230
 
 
231
RemoveExecd()
 
232
{
 
233
   exechost=$1
 
234
 
 
235
   $INFOTEXT "Removing exec host %s now!" $exechost
 
236
   $INFOTEXT -log "Removing exec host %s now!" $exechost
 
237
 
 
238
   qconf -ds $exechost
 
239
   sleep 1
 
240
   qconf -ke $exechost
 
241
   sleep 1
 
242
   qconf -de $exechost
 
243
   sleep 1
 
244
   qconf -dh $exechost
 
245
 
 
246
 
 
247
}
 
248
 
 
249
 
 
250
RemoveReferences()
 
251
{
 
252
   exechost=$1
 
253
 
 
254
   $INFOTEXT "Removing exec host references for host %s now!" $exechost
 
255
   $INFOTEXT -log "Removing exec host references for host %s now!" $exechost
 
256
 
 
257
   for q in `qconf -sql`; do
 
258
      qconf -purge queue "*" "$q@$exechost" 
 
259
   done
 
260
 
 
261
}
 
262
 
 
263
 
 
264
RemoveSpoolDir()
 
265
{
 
266
   exechost=$1
 
267
   $INFOTEXT "Checking global spooldir configuration for host \"%s\"!" $exechost
 
268
   $INFOTEXT -log "Checking global spooldir configuration for host \"%s\"!" $exechost
 
269
   SPOOL_DIR=`qconf -sconf | grep execd_spool_dir | awk '{ print $2 }'`
 
270
   HOST_DIR=`echo $exechost | tr "[A-Z]" "[a-z]"`
 
271
 
 
272
   # Check global spool dir for execd host
 
273
   if [ -d "$SPOOL_DIR/$HOST_DIR" ]; then
 
274
      $INFOTEXT "Removing spool directory [%s]" $SPOOL_DIR/$HOST_DIR
 
275
      $INFOTEXT -log "Removing spool directory [%s]" $SPOOL_DIR/$HOST_DIR
 
276
      ExecuteAsAdmin rm -R $SPOOL_DIR/$HOST_DIR
 
277
 
 
278
      if [ `ls -la $SPOOL_DIR | wc -l` -lt 4 ]; then
 
279
         ExecuteAsAdmin rm -R $SPOOL_DIR
 
280
      fi
 
281
 
 
282
   fi
 
283
 
 
284
   $INFOTEXT "Checking local spooldir configuration for host \"%s\"!" $exechost
 
285
   $INFOTEXT -log "Checking local spooldir configuration for host \"%s\"!" $exechost
 
286
   SPOOL_DIR=`qconf -sconf $exechost | grep execd_spool_dir | awk '{ print $2 }'`
 
287
 
 
288
   $INFOTEXT "Delete configuration for host \"%s\"!" $exechost
 
289
   $INFOTEXT -log "Delete configuration for host \"%s\"!" $exechost
 
290
   qconf -dconf $exechost
 
291
 
 
292
   if [ "$SPOOL_DIR" != "" ]; then
 
293
      if [ -d "$SPOOL_DIR/$HOST_DIR" ]; then
 
294
         $INFOTEXT "Removing local spool directory [%s]" "$SPOOL_DIR/$HOST_DIR"
 
295
         $INFOTEXT -log "Removing local spool directory [%s]" "$SPOOL_DIR/$HOST_DIR"
 
296
         ExecuteAsAdmin rm -R $SPOOL_DIR/$HOST_DIR
 
297
      fi
 
298
   fi
 
299
}
 
300
 
 
301
doUninstall() {
 
302
 
 
303
   uhost=$1
 
304
   qconf -se $uhost
 
305
   ret=$?
 
306
   if [ $ret = 0 ]; then
 
307
      $INFOTEXT "Removing execution host %s now!" $uhost
 
308
      $INFOTEXT -log "Removing execution host %s now!" $uhost
 
309
      $INFOTEXT "Disabling queues now!"
 
310
      $INFOTEXT -log "Disabling queues now!"
 
311
      DisableQueue $uhost
 
312
      SuspendQueue $uhost
 
313
      SuspendJobs $uhost
 
314
      RescheduleJobs $uhost
 
315
      RemoveQueues $uhost
 
316
      RemoveSpoolDir $uhost
 
317
      RemoveReferences $uhost
 
318
      RemoveExecd $uhost
 
319
      RemoveRcScript $uhost execd $euid
 
320
   else
 
321
      $INFOTEXT "%s is not an execution host" $uhost
 
322
      $INFOTEXT -log "%s is not an execution host" $uhost
 
323
   fi
 
324
 
 
325
}