1 #!/bin/sh 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 # 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # 27 # r.manifest - smf(5) manifest remove class action script 28 # 29 30 MFSTSCAN=/lib/svc/bin/mfstscan 31 SVCCFG=/usr/sbin/svccfg 32 SVCPROP=/usr/bin/svcprop 33 SVCADM=/usr/sbin/svcadm 34 AWK=/usr/bin/awk 35 CP=/usr/bin/cp 36 RM=/usr/bin/rm 37 38 # number of seconds to wait before killing processes 39 STOP_DELAY=60 40 41 # 42 # Helper function. Delete the manifest hash value. 43 # Arguments: $1: manifest file. 44 # 45 svc_delhash() 46 { 47 $SVCCFG delhash $1 >/dev/null 2>&1 48 if [ "$?" != "0" ];then 49 # this Solaris release doesn't have delhash command 50 pg_name=`$MFSTSCAN -t $1` 51 if $SVCPROP -q -p $pg_name smf/manifest; then 52 $SVCCFG -s smf/manifest delpg $pg_name 53 fi 54 fi 55 } 56 57 # 58 # Helper function. Handle services deathrow file. 59 # Arguments: $1:manifest file, $2:package name. 60 # 61 svc_deathrow() 62 { 63 DEATHROW_FILE=${PKG_INSTALL_ROOT}/etc/svc/deathrow 64 # remove alternate root from manifest path 65 manifest=`echo "${PKG_INSTALL_ROOT} $1" | $AWK \ 66 '{ print substr($2, length($1)+1); }'` 67 # 68 # Services deathrow file handling, file format: 69 # <fmri>< ><manifest file>< ><package name> 70 # (field separator is a space character) 71 # 72 # Manifest file could be from another Solaris version, bypass the 73 # the service bundle and validation (we only need the fmris list). 74 # Calling svccfg inventory with SVCCFG_NOVALIDATE=1 is safe because 75 # there is no access to the alternate repository. 76 # 77 ENTITIES=`SVCCFG_NOVALIDATE=1 $SVCCFG inventory $1` 78 for fmri in $ENTITIES; do 79 # add to services deathrow file 80 echo ${fmri} ${manifest} $2 >> ${DEATHROW_FILE} 81 done 82 } 83 84 wait_disable() { 85 svcinst=$1 86 wait_time=$2 87 88 while [ ${nsec:=0} -lt $wait_time ]; do 89 state=`$SVCPROP -p restarter/state $svcinst` 90 if [ "$state" = "disabled" -o "$state" = "maintenance" ]; then 91 nstate=`$SVCPROP -p restarter/next_state $svcinst` 92 if [ "$nstate" = "none" ]; then 93 return 0 94 fi 95 fi 96 /usr/bin/sleep 1 97 nsec=`expr ${nsec} + 1` 98 done 99 100 return 1 101 } 102 103 if [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" ]; then 104 # 105 # We can't safely disable the service in this case. 106 # 107 smf_alive=no 108 else 109 # 110 # We can verify if the service is disabled prior to 111 # removal. 112 # 113 if [ -r /etc/svc/volatile/repository_door ]; then 114 smf_alive=yes 115 fi 116 fi 117 118 while read mfst; do 119 if [ "$smf_alive" = "yes" ]; then 120 ENTITIES=`$SVCCFG inventory $mfst` 121 122 for fmri in $ENTITIES; do 123 124 # Determine whether fmri refers to an instance or a service. 125 $SVCPROP -p restarter/state $fmri >/dev/null 2>&1 126 if [ $? -eq 1 ]; then 127 # this is a service fmri, all instances have been deleted 128 $SVCCFG delete $fmri 2>/dev/null 129 # process next instance 130 continue 131 fi 132 133 # 134 # Try to disable the instance within a reasonable amount of time 135 # (eg. 60 secs). If it fails, forcibly delete the instance. 136 # 137 echo "Waiting up to $STOP_DELAY seconds for $fmri to stop..." 138 $SVCADM disable $fmri 2>/dev/null 139 if [ $? -eq 0 ]; then 140 wait_disable $fmri $STOP_DELAY 141 if [ $? -eq 0 ]; then 142 # the instance is disabled and can be safely deleted 143 $SVCCFG delete $fmri 2>/dev/null 144 # process next instance 145 continue 146 fi 147 echo "Failed to disable $fmri after $STOP_DELAY seconds" 148 else 149 echo "Failed to disable $fmri" 150 fi 151 152 echo "Force deleting $fmri" 153 154 ctid=`$SVCPROP -p restarter/contract $fmri 2>/dev/null` 155 tctid=`$SVCPROP -p restarter/transient_contract $fmri 2>/dev/null` 156 157 $SVCCFG delete -f $fmri 158 159 # 160 # Kill any remaining processes. 161 # pkill must occur after the delete to prevent startd 162 # from retrying the STOP method. 163 # 164 if [ -n "${tctid}" -a "${tctid}" -gt 1 ]; then 165 # kill the STOP method processes 166 /usr/bin/pkill -9 -c $tctid 167 fi 168 if [ -n "${ctid}" -a "${ctid}" -gt 1 ]; then 169 # kill any remaining running processes for the instance 170 /usr/bin/pkill -9 -c $ctid 171 fi 172 done 173 174 # 175 # Delete the manifest hash value. 176 # 177 svc_delhash $mfst 178 else 179 # deathrow handling 180 svc_deathrow $mfst $PKGINST 181 fi 182 183 $RM -f $mfst 184 done 185 186 exit 0 187