Print this page
    
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/zoneadm/svc-zones
          +++ new/usr/src/cmd/zoneadm/svc-zones
   1    1  #!/sbin/sh
   2    2  #
   3    3  # CDDL HEADER START
   4    4  #
   5    5  # The contents of this file are subject to the terms of the
   6    6  # Common Development and Distribution License (the "License").
   7    7  # You may not use this file except in compliance with the License.
   8    8  #
   9    9  # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10   10  # or http://www.opensolaris.org/os/licensing.
  11   11  # See the License for the specific language governing permissions
  12   12  # and limitations under the License.
  13   13  #
  14   14  # When distributing Covered Code, include this CDDL HEADER in each
  15   15  # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16  # If applicable, add the following below this CDDL HEADER, with the
  17   17  # fields enclosed by brackets "[]" replaced with your own identifying
  18   18  # information: Portions Copyright [yyyy] [name of copyright owner]
  19   19  #
  20   20  # CDDL HEADER END
  21   21  #
  22   22  #
  23   23  # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24  # Copyright 2014 Nexenta Systems, Inc. All rights reserved.
  25   25  
  26   26  . /lib/svc/share/smf_include.sh
  27   27  
  28   28  #
  29   29  # Return a list of running, non-global zones for which a shutdown via
  30   30  # "/sbin/init 0" may work (typically only Solaris zones.)
  31   31  #
  32   32  shutdown_zones()
  33   33  {
  34   34          zoneadm list -p | nawk -F: '{
  35   35                  if (($5 != "lx") && ($2 != "global")) {
  36   36                          print $2
  37   37                  }
  38   38          }'
  39   39  }
  40   40  
  41   41  [ ! -x /usr/sbin/zoneadm ] && exit 0    # SUNWzoneu not installed
  42   42  
  43   43  if [ -z "$SMF_FMRI" ]; then
  44   44          echo "this script can only be invoked by smf(5)"        
  45   45          exit $SMF_EXIT_ERR_NOSMF
  46   46  fi
  47   47  
  48   48  # Make sure working directory is / to prevent unmounting problems.
  49   49  cd /
  50   50  PATH=/usr/sbin:/usr/bin; export PATH
  51   51  
  52   52  case "$1" in
  53   53  'start')
  54   54          egrep -vs '^#|^global:' /etc/zones/index || exit 0  # no local zones
  55   55  
  56   56          #
  57   57          # Boot the installed zones for which the "autoboot" zone property is
  58   58          # set and invoke the sysboot hook for all other installed zones.
  59   59          #
  60   60          ZONES=""
  61   61          for zone in `zoneadm list -pi | nawk -F: '{
  62   62                          if ($3 == "installed") {
  63   63                                  print $2
  64   64                          }
  65   65                  }'`; do
  66   66                  zonecfg -z $zone info autoboot | grep "true" >/dev/null 2>&1
  67   67                  if [ $? -eq 0 ]; then
  68   68                          [ -z "$ZONES" ] && echo "Booting zones:\c"
  69   69                          ZONES=yes
  70   70                          echo " $zone\c"
  71   71                          #
  72   72                          # zoneadmd puts itself into its own contract so
  73   73                          # this service will lose sight of it.  We don't
  74   74                          # support restart so it is OK for zoneadmd to
  75   75                          # to be in an orphaned contract.
  76   76                          #
  77   77                          zoneadm -z $zone boot &
  78   78                  else
  79   79                          zoneadm -z $zone sysboot &
  80   80                  fi
  81   81          done
  82   82  
  83   83          #
  84   84          # Wait for all zoneadm processes to finish before allowing the
  85   85          # start method to exit.
  86   86          #
  87   87          wait
  88   88          [ -n "$ZONES" ] && echo .
  89   89          ;;
  90   90  
  91   91  'stop')
  92   92          egrep -vs '^#|^global:' /etc/zones/index || exit 0  # no local zones
  93   93          [ "`zoneadm list`" = "global" ] && exit 0   # no zones running
  94   94  
  95   95          SVC_TIMEOUT=`svcprop -p stop/timeout_seconds $SMF_FMRI`
  96   96  
  97   97          #
  98   98          # First, try shutting down any running zones for which an "init 0" may
  99   99          # work.
 100  100          #
 101  101          MAXSHUT=`expr 3 \* $SVC_TIMEOUT \/ 4` # 3/4 of time to zone shutdown
 102  102          MAXHALT=`expr $SVC_TIMEOUT \/ 4`      # rest of time goes to halt
 103  103  
 104  104          zonelist=`shutdown_zones`
 105  105  
 106  106          if [ -n "$zonelist" ]; then
 107  107                  SHUTDOWN=0
 108  108                  echo "Shutting down running zones (for up to $MAXSHUT" \
 109  109                      "seconds):\c"
 110  110  
 111  111                  for zone in $zonelist; do
 112  112                          echo " $zone\c"
 113  113                          zoneadm -z $zone shutdown &
 114  114                          SHUTDOWN=1
 115  115                  done
 116  116  
 117  117                  [ $SHUTDOWN -eq 1 ] && echo "."
 118  118  
 119  119                  # Allow time for zones to shutdown cleanly
 120  120  
 121  121                  while [ $MAXSHUT -gt 0 -a "`shutdown_zones`" != "" ]; do
 122  122                          MAXSHUT=`expr $MAXSHUT - 1`
 123  123                          sleep 1 # wait a bit longer
 124  124                  done
 125  125          fi
 126  126  
 127  127          #
 128  128          # Second, try halting any non-global zones still running
 129  129          #
 130  130          WAITPIDS=""
 131  131          for zone in `zoneadm list`; do
 132  132                  if [ "$zone" != "global" ]; then
 133  133                          [ -z "$WAITPIDS" ] &&
 134  134                              echo "Zones failed to shutdown; trying to halt " \
 135  135                              "(for up to $MAXHALT seconds):\c"
 136  136                          echo " $zone\c"
 137  137                          zoneadm -z $zone halt &
 138  138                          WAITPIDS="$WAITPIDS $!"
 139  139                  fi
 140  140          done
 141  141          [ ! -z "$WAITPIDS" ] && echo .
 142  142  
 143  143          # Wait for the 'zoneadm halt' commands to complete.  We will let this
 144  144          # run forever, since the restart daemon will eventually kill us off
 145  145          # anyway if the halts do not complete after a certain period of time.
 146  146          wait $WAITPIDS
 147  147  
 148  148          # If the halts complete but a zone is still not shutdown, it might
 149  149          # be in a state like 'shutting_down' or 'down'.  So we give it some
 150  150          # time to come all the way down.
 151  151  
 152  152          while [ $MAXHALT -gt 0 -a "`zoneadm list`" != "global" ]; do
 153  153                  MAXHALT=`expr $MAXHALT - 1`
 154  154                  sleep 1 # wait a bit longer
 155  155          done
 156  156  
 157  157          # If there are any remaining file systems in zones, try to unmount them.
 158  158          umountall -Z
 159  159  
 160  160          #
 161  161          # Report on zones which failed to shutdown.
 162  162          #
 163  163          for zone in `zoneadm list`; do
 164  164                  if [ "$zone" != "global" ]; then
 165  165                          echo "Zone '$zone' failed to halt."
 166  166                  fi
 167  167          done
 168  168          [ "`zoneadm list`" != "global" ] && exit 1   # zones still running
 169  169          ;;
 170  170  
 171  171  *)
 172  172          echo "Usage: $0 { start | stop }"
 173  173          exit 1
 174  174          ;;
 175  175  esac
 176  176  exit 0
  
    | 
      ↓ open down ↓ | 
    176 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX