xref: /onnv-gate/usr/src/cmd/svc/common/r.manifest (revision 11838:32bb5d254240)
1*11838SLiane.Praza@Sun.COM#!/bin/sh
2*11838SLiane.Praza@Sun.COM#
3*11838SLiane.Praza@Sun.COM# CDDL HEADER START
4*11838SLiane.Praza@Sun.COM#
5*11838SLiane.Praza@Sun.COM# The contents of this file are subject to the terms of the
6*11838SLiane.Praza@Sun.COM# Common Development and Distribution License (the "License").
7*11838SLiane.Praza@Sun.COM# You may not use this file except in compliance with the License.
8*11838SLiane.Praza@Sun.COM#
9*11838SLiane.Praza@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*11838SLiane.Praza@Sun.COM# or http://www.opensolaris.org/os/licensing.
11*11838SLiane.Praza@Sun.COM# See the License for the specific language governing permissions
12*11838SLiane.Praza@Sun.COM# and limitations under the License.
13*11838SLiane.Praza@Sun.COM#
14*11838SLiane.Praza@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
15*11838SLiane.Praza@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*11838SLiane.Praza@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
17*11838SLiane.Praza@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
18*11838SLiane.Praza@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
19*11838SLiane.Praza@Sun.COM#
20*11838SLiane.Praza@Sun.COM# CDDL HEADER END
21*11838SLiane.Praza@Sun.COM#
22*11838SLiane.Praza@Sun.COM#
23*11838SLiane.Praza@Sun.COM# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*11838SLiane.Praza@Sun.COM# Use is subject to license terms.
25*11838SLiane.Praza@Sun.COM#
26*11838SLiane.Praza@Sun.COM#
27*11838SLiane.Praza@Sun.COM# r.manifest - smf(5) manifest remove class action script
28*11838SLiane.Praza@Sun.COM#
29*11838SLiane.Praza@Sun.COM
30*11838SLiane.Praza@Sun.COMMFSTSCAN=/lib/svc/bin/mfstscan
31*11838SLiane.Praza@Sun.COMSVCCFG=/usr/sbin/svccfg
32*11838SLiane.Praza@Sun.COMSVCPROP=/usr/bin/svcprop
33*11838SLiane.Praza@Sun.COMSVCADM=/usr/sbin/svcadm
34*11838SLiane.Praza@Sun.COMAWK=/usr/bin/awk
35*11838SLiane.Praza@Sun.COMCP=/usr/bin/cp
36*11838SLiane.Praza@Sun.COMRM=/usr/bin/rm
37*11838SLiane.Praza@Sun.COM
38*11838SLiane.Praza@Sun.COM# number of seconds to wait before killing processes
39*11838SLiane.Praza@Sun.COMSTOP_DELAY=60
40*11838SLiane.Praza@Sun.COM
41*11838SLiane.Praza@Sun.COM#
42*11838SLiane.Praza@Sun.COM# Helper function. Delete the manifest hash value.
43*11838SLiane.Praza@Sun.COM# Arguments: $1: manifest file.
44*11838SLiane.Praza@Sun.COM#
45*11838SLiane.Praza@Sun.COMsvc_delhash()
46*11838SLiane.Praza@Sun.COM{
47*11838SLiane.Praza@Sun.COM	$SVCCFG delhash $1 >/dev/null 2>&1
48*11838SLiane.Praza@Sun.COM	if [ "$?" != "0" ];then
49*11838SLiane.Praza@Sun.COM		# this Solaris release doesn't have delhash command
50*11838SLiane.Praza@Sun.COM		pg_name=`$MFSTSCAN -t $1`
51*11838SLiane.Praza@Sun.COM		if $SVCPROP -q -p $pg_name smf/manifest; then
52*11838SLiane.Praza@Sun.COM			$SVCCFG -s smf/manifest delpg $pg_name
53*11838SLiane.Praza@Sun.COM		fi
54*11838SLiane.Praza@Sun.COM	fi
55*11838SLiane.Praza@Sun.COM}
56*11838SLiane.Praza@Sun.COM
57*11838SLiane.Praza@Sun.COM#
58*11838SLiane.Praza@Sun.COM# Helper function. Handle services deathrow file.
59*11838SLiane.Praza@Sun.COM# Arguments: $1:manifest file, $2:package name.
60*11838SLiane.Praza@Sun.COM#
61*11838SLiane.Praza@Sun.COMsvc_deathrow()
62*11838SLiane.Praza@Sun.COM{
63*11838SLiane.Praza@Sun.COM	DEATHROW_FILE=${PKG_INSTALL_ROOT}/etc/svc/deathrow
64*11838SLiane.Praza@Sun.COM	# remove alternate root from manifest path
65*11838SLiane.Praza@Sun.COM	manifest=`echo "${PKG_INSTALL_ROOT} $1" | $AWK \
66*11838SLiane.Praza@Sun.COM	    '{ print substr($2, length($1)+1); }'`
67*11838SLiane.Praza@Sun.COM	#
68*11838SLiane.Praza@Sun.COM	# Services deathrow file handling, file format:
69*11838SLiane.Praza@Sun.COM	# <fmri>< ><manifest file>< ><package name>
70*11838SLiane.Praza@Sun.COM	# (field separator is a space character)
71*11838SLiane.Praza@Sun.COM	#
72*11838SLiane.Praza@Sun.COM	# Manifest file could be from another Solaris version, bypass the
73*11838SLiane.Praza@Sun.COM	# the service bundle and validation (we only need the fmris list).
74*11838SLiane.Praza@Sun.COM	# Calling svccfg inventory with SVCCFG_NOVALIDATE=1 is safe because
75*11838SLiane.Praza@Sun.COM	# there is no access to the alternate repository.
76*11838SLiane.Praza@Sun.COM	#
77*11838SLiane.Praza@Sun.COM	ENTITIES=`SVCCFG_NOVALIDATE=1 $SVCCFG inventory $1`
78*11838SLiane.Praza@Sun.COM	for fmri in $ENTITIES; do
79*11838SLiane.Praza@Sun.COM		# add to services deathrow file
80*11838SLiane.Praza@Sun.COM		echo ${fmri} ${manifest} $2 >> ${DEATHROW_FILE}
81*11838SLiane.Praza@Sun.COM	done
82*11838SLiane.Praza@Sun.COM}
83*11838SLiane.Praza@Sun.COM
84*11838SLiane.Praza@Sun.COMwait_disable() {
85*11838SLiane.Praza@Sun.COM	svcinst=$1
86*11838SLiane.Praza@Sun.COM	wait_time=$2
87*11838SLiane.Praza@Sun.COM
88*11838SLiane.Praza@Sun.COM	while [ ${nsec:=0} -lt $wait_time ]; do
89*11838SLiane.Praza@Sun.COM		state=`$SVCPROP -p restarter/state $svcinst`
90*11838SLiane.Praza@Sun.COM		if [ "$state" = "disabled" -o "$state" = "maintenance" ]; then
91*11838SLiane.Praza@Sun.COM			nstate=`$SVCPROP -p restarter/next_state $svcinst`
92*11838SLiane.Praza@Sun.COM			if [ "$nstate" = "none" ]; then
93*11838SLiane.Praza@Sun.COM				return 0
94*11838SLiane.Praza@Sun.COM			fi
95*11838SLiane.Praza@Sun.COM		fi
96*11838SLiane.Praza@Sun.COM		/usr/bin/sleep 1
97*11838SLiane.Praza@Sun.COM		nsec=`expr ${nsec} + 1`
98*11838SLiane.Praza@Sun.COM	done
99*11838SLiane.Praza@Sun.COM
100*11838SLiane.Praza@Sun.COM	return 1
101*11838SLiane.Praza@Sun.COM}
102*11838SLiane.Praza@Sun.COM
103*11838SLiane.Praza@Sun.COMif [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" ]; then
104*11838SLiane.Praza@Sun.COM	#
105*11838SLiane.Praza@Sun.COM	# We can't safely disable the service in this case.
106*11838SLiane.Praza@Sun.COM	#
107*11838SLiane.Praza@Sun.COM	smf_alive=no
108*11838SLiane.Praza@Sun.COMelse
109*11838SLiane.Praza@Sun.COM	#
110*11838SLiane.Praza@Sun.COM	# We can verify if the service is disabled prior to
111*11838SLiane.Praza@Sun.COM	# removal.
112*11838SLiane.Praza@Sun.COM	#
113*11838SLiane.Praza@Sun.COM	if [ -r /etc/svc/volatile/repository_door ]; then
114*11838SLiane.Praza@Sun.COM		smf_alive=yes
115*11838SLiane.Praza@Sun.COM	fi
116*11838SLiane.Praza@Sun.COMfi
117*11838SLiane.Praza@Sun.COM
118*11838SLiane.Praza@Sun.COMwhile read mfst; do
119*11838SLiane.Praza@Sun.COM	if [ "$smf_alive" = "yes" ]; then
120*11838SLiane.Praza@Sun.COM		$RM -f $mfst
121*11838SLiane.Praza@Sun.COM
122*11838SLiane.Praza@Sun.COM		$SVCADM restart svc:/system/manifest-import:default
123*11838SLiane.Praza@Sun.COM	else
124*11838SLiane.Praza@Sun.COM		# deathrow handling
125*11838SLiane.Praza@Sun.COM		svc_deathrow $mfst $PKGINST
126*11838SLiane.Praza@Sun.COM
127*11838SLiane.Praza@Sun.COM		$RM -f $mfst
128*11838SLiane.Praza@Sun.COM	fi
129*11838SLiane.Praza@Sun.COM
130*11838SLiane.Praza@Sun.COMdone
131*11838SLiane.Praza@Sun.COM
132*11838SLiane.Praza@Sun.COMexit 0
133