xref: /titanic_41/usr/src/cmd/svc/common/r.manifest (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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 2009 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
30MFSTSCAN=/lib/svc/bin/mfstscan
31SVCCFG=/usr/sbin/svccfg
32SVCPROP=/usr/bin/svcprop
33SVCADM=/usr/sbin/svcadm
34AWK=/usr/bin/awk
35CP=/usr/bin/cp
36RM=/usr/bin/rm
37
38# number of seconds to wait before killing processes
39STOP_DELAY=60
40
41#
42# Helper function. Delete the manifest hash value.
43# Arguments: $1: manifest file.
44#
45svc_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#
61svc_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
84wait_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
103if [ "$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
108else
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
116fi
117
118while read mfst; do
119	if [ "$smf_alive" = "yes" ]; then
120		$RM -f $mfst
121
122		$SVCADM restart svc:/system/manifest-import:default
123	else
124		# deathrow handling
125		svc_deathrow $mfst $PKGINST
126
127		$RM -f $mfst
128	fi
129
130done
131
132exit 0
133