r.manifest revision 70cbfe41f2338b77c15f79c6625eca6e70c412f3
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence#!/bin/sh
816e576f77e2c46df3e3d97d65822aa8aded7c4bDavid Lawrence#
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# CDDL HEADER START
77527513f94fe78413221a63fd6d383cec32bcafAndreas Gustafsson#
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence# The contents of this file are subject to the terms of the
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# Common Development and Distribution License (the "License").
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# You may not use this file except in compliance with the License.
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson#
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# or http://www.opensolaris.org/os/licensing.
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# See the License for the specific language governing permissions
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# and limitations under the License.
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson#
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson# When distributing Covered Code, include this CDDL HEADER in each
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson# If applicable, add the following below this CDDL HEADER, with the
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson# fields enclosed by brackets "[]" replaced with your own identifying
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# information: Portions Copyright [yyyy] [name of copyright owner]
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson#
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson# CDDL HEADER END
77527513f94fe78413221a63fd6d383cec32bcafAndreas Gustafsson#
77527513f94fe78413221a63fd6d383cec32bcafAndreas Gustafsson#
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# Use is subject to license terms.
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson#
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson#
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson# r.manifest - smf(5) manifest remove class action script
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson#
b976f9c60a09f4a098852d0653ad5df6842557a7Andreas Gustafsson
b976f9c60a09f4a098852d0653ad5df6842557a7Andreas GustafssonMFSTSCAN=/lib/svc/bin/mfstscan
3d4a70fe38769e42b943717256208b63fec05f32Andreas GustafssonSVCCFG=/usr/sbin/svccfg
3d4a70fe38769e42b943717256208b63fec05f32Andreas GustafssonSVCPROP=/usr/bin/svcprop
b976f9c60a09f4a098852d0653ad5df6842557a7Andreas GustafssonSVCADM=/usr/sbin/svcadm
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas GustafssonAWK=/usr/bin/awk
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas GustafssonCP=/usr/bin/cp
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas GustafssonRM=/usr/bin/rm
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson# number of seconds to wait before killing processes
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas GustafssonSTOP_DELAY=60
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson#
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson# Helper function. Delete the manifest hash value.
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson# Arguments: $1: manifest file.
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson#
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafssonsvc_delhash()
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson{
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson $SVCCFG delhash $1 >/dev/null 2>&1
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson if [ "$?" != "0" ];then
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson # this Solaris release doesn't have delhash command
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson pg_name=`$MFSTSCAN -t $1`
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson if $SVCPROP -q -p $pg_name smf/manifest; then
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson $SVCCFG -s smf/manifest delpg $pg_name
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson fi
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson fi
63404af69b0b99b8fa551e92702921f01c3bbfd7Andreas Gustafsson}
77527513f94fe78413221a63fd6d383cec32bcafAndreas Gustafsson
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson#
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson# Helper function. Handle services deathrow file.
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson# Arguments: $1:manifest file, $2:package name.
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson#
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafssonsvc_deathrow()
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson{
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson DEATHROW_FILE=${PKG_INSTALL_ROOT}/etc/svc/deathrow
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson # remove alternate root from manifest path
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson manifest=`echo "${PKG_INSTALL_ROOT} $1" | $AWK \
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson '{ print substr($2, length($1)+1); }'`
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson #
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson # Services deathrow file handling, file format:
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson # <fmri>< ><manifest file>< ><package name>
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson # (field separator is a space character)
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson #
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson # Manifest file could be from another Solaris version, bypass the
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson # the service bundle and validation (we only need the fmris list).
f5eb48652c7ec98514256b5b6e6fd7cbc22b1916Andreas Gustafsson # Calling svccfg inventory with SVCCFG_NOVALIDATE=1 is safe because
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson # there is no access to the alternate repository.
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson #
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson ENTITIES=`SVCCFG_NOVALIDATE=1 $SVCCFG inventory $1`
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson for fmri in $ENTITIES; do
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson # add to services deathrow file
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson echo ${fmri} ${manifest} $2 >> ${DEATHROW_FILE}
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson done
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson}
20df5357b17d31a3adc4d6f7cfdd9d4f1c5addf2Andreas Gustafsson
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafssonwait_disable() {
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson svcinst=$1
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson wait_time=$2
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson while [ ${nsec:=0} -lt $wait_time ]; do
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson state=`$SVCPROP -p restarter/state $svcinst`
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson if [ "$state" = "disabled" -o "$state" = "maintenance" ]; then
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson nstate=`$SVCPROP -p restarter/next_state $svcinst`
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson if [ "$nstate" = "none" ]; then
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson return 0
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson fi
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson fi
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson /usr/bin/sleep 1
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson nsec=`expr ${nsec} + 1`
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson done
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson return 1
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson}
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafssonif [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" ]; then
20df5357b17d31a3adc4d6f7cfdd9d4f1c5addf2Andreas Gustafsson #
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson # We can't safely disable the service in this case.
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson #
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafsson smf_alive=no
f7aa8ce0b3cf7f5df618a42beecf8d5517c000acAndreas Gustafssonelse
c7d445ce7f4db5262ba3412eac7b1ee9d053b93dAndreas Gustafsson #
3d4a70fe38769e42b943717256208b63fec05f32Andreas Gustafsson # We can verify if the service is disabled prior to
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson # removal.
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson #
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson if [ -r /etc/svc/volatile/repository_door ]; then
b976f9c60a09f4a098852d0653ad5df6842557a7Andreas Gustafsson smf_alive=yes
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson fi
77527513f94fe78413221a63fd6d383cec32bcafAndreas Gustafssonfi
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson
20df5357b17d31a3adc4d6f7cfdd9d4f1c5addf2Andreas Gustafssonwhile read mfst; do
20df5357b17d31a3adc4d6f7cfdd9d4f1c5addf2Andreas Gustafsson if [ "$smf_alive" = "yes" ]; then
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson ENTITIES=`$SVCCFG inventory $mfst`
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson for fmri in $ENTITIES; do
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson
76458ec215a57c6806afdd831b9c9a30b93344b0Andreas Gustafsson # Determine whether fmri refers to an instance or a service.
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson $SVCPROP -p restarter/state $fmri >/dev/null 2>&1
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson if [ $? -eq 1 ]; then
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson # this is a service fmri, all instances have been deleted
36bc6a0a8312de762caf1e984efe15c8e7170d9dAndreas Gustafsson $SVCCFG delete $fmri 2>/dev/null
2d54cf04fc02db7c369592b6f91bbd1330df3387Andreas Gustafsson # process next instance
continue
fi
#
# Try to disable the instance within a reasonable amount of time
# (eg. 60 secs). If it fails, forcibly delete the instance.
#
echo "Waiting up to $STOP_DELAY seconds for $fmri to stop..."
$SVCADM disable $fmri 2>/dev/null
if [ $? -eq 0 ]; then
wait_disable $fmri $STOP_DELAY
if [ $? -eq 0 ]; then
# the instance is disabled and can be safely deleted
$SVCCFG delete $fmri 2>/dev/null
# process next instance
continue
fi
echo "Failed to disable $fmri after $STOP_DELAY seconds"
else
echo "Failed to disable $fmri"
fi
echo "Force deleting $fmri"
ctid=`$SVCPROP -p restarter/contract $fmri 2>/dev/null`
tctid=`$SVCPROP -p restarter/transient_contract $fmri 2>/dev/null`
$SVCCFG delete -f $fmri
#
# Kill any remaining processes.
# pkill must occur after the delete to prevent startd
# from retrying the STOP method.
#
if [ -n "${tctid}" -a "${tctid}" -gt 1 ]; then
# kill the STOP method processes
/usr/bin/pkill -9 -c $tctid
fi
if [ -n "${ctid}" -a "${ctid}" -gt 1 ]; then
# kill any remaining running processes for the instance
/usr/bin/pkill -9 -c $ctid
fi
done
#
# Delete the manifest hash value.
#
svc_delhash $mfst
else
# deathrow handling
svc_deathrow $mfst $PKGINST
fi
$RM -f $mfst
done
exit 0