xref: /illumos-gate/usr/src/cmd/svc/common/r.manifest (revision bbf21555)
17c478bd9Sstevel@tonic-gate#!/bin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6ff17f0caSRenaud Manus# Common Development and Distribution License (the "License").
7ff17f0caSRenaud Manus# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
2323294c7dSSean Wilcox# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate#
27*bbf21555SRichard Lowe# r.manifest - smf(7) manifest remove class action script
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate
30ff17f0caSRenaud ManusMFSTSCAN=/lib/svc/bin/mfstscan
31ff17f0caSRenaud ManusSVCCFG=/usr/sbin/svccfg
32ff17f0caSRenaud ManusSVCPROP=/usr/bin/svcprop
33ff17f0caSRenaud ManusSVCADM=/usr/sbin/svcadm
3470cbfe41SPhilippe JungAWK=/usr/bin/awk
3570cbfe41SPhilippe JungCP=/usr/bin/cp
3670cbfe41SPhilippe JungRM=/usr/bin/rm
37ff17f0caSRenaud Manus
38ff17f0caSRenaud Manus# number of seconds to wait before killing processes
39ff17f0caSRenaud ManusSTOP_DELAY=60
40ff17f0caSRenaud Manus
4170cbfe41SPhilippe Jung#
4270cbfe41SPhilippe Jung# Helper function. Delete the manifest hash value.
4370cbfe41SPhilippe Jung# Arguments: $1: manifest file.
4470cbfe41SPhilippe Jung#
4570cbfe41SPhilippe Jungsvc_delhash()
4670cbfe41SPhilippe Jung{
4770cbfe41SPhilippe Jung	$SVCCFG delhash $1 >/dev/null 2>&1
4870cbfe41SPhilippe Jung	if [ "$?" != "0" ];then
4970cbfe41SPhilippe Jung		# this Solaris release doesn't have delhash command
5070cbfe41SPhilippe Jung		pg_name=`$MFSTSCAN -t $1`
5170cbfe41SPhilippe Jung		if $SVCPROP -q -p $pg_name smf/manifest; then
5270cbfe41SPhilippe Jung			$SVCCFG -s smf/manifest delpg $pg_name
5370cbfe41SPhilippe Jung		fi
5470cbfe41SPhilippe Jung	fi
5570cbfe41SPhilippe Jung}
5670cbfe41SPhilippe Jung
5770cbfe41SPhilippe Jung#
5870cbfe41SPhilippe Jung# Helper function. Handle services deathrow file.
5970cbfe41SPhilippe Jung# Arguments: $1:manifest file, $2:package name.
6070cbfe41SPhilippe Jung#
6170cbfe41SPhilippe Jungsvc_deathrow()
6270cbfe41SPhilippe Jung{
6370cbfe41SPhilippe Jung	DEATHROW_FILE=${PKG_INSTALL_ROOT}/etc/svc/deathrow
6470cbfe41SPhilippe Jung	# remove alternate root from manifest path
6570cbfe41SPhilippe Jung	manifest=`echo "${PKG_INSTALL_ROOT} $1" | $AWK \
6670cbfe41SPhilippe Jung	    '{ print substr($2, length($1)+1); }'`
6770cbfe41SPhilippe Jung	#
6870cbfe41SPhilippe Jung	# Services deathrow file handling, file format:
6970cbfe41SPhilippe Jung	# <fmri>< ><manifest file>< ><package name>
7070cbfe41SPhilippe Jung	# (field separator is a space character)
7170cbfe41SPhilippe Jung	#
7270cbfe41SPhilippe Jung	# Manifest file could be from another Solaris version, bypass the
7370cbfe41SPhilippe Jung	# the service bundle and validation (we only need the fmris list).
7470cbfe41SPhilippe Jung	# Calling svccfg inventory with SVCCFG_NOVALIDATE=1 is safe because
7570cbfe41SPhilippe Jung	# there is no access to the alternate repository.
7670cbfe41SPhilippe Jung	#
7770cbfe41SPhilippe Jung	ENTITIES=`SVCCFG_NOVALIDATE=1 $SVCCFG inventory $1`
7870cbfe41SPhilippe Jung	for fmri in $ENTITIES; do
7970cbfe41SPhilippe Jung		# add to services deathrow file
8070cbfe41SPhilippe Jung		echo ${fmri} ${manifest} $2 >> ${DEATHROW_FILE}
8170cbfe41SPhilippe Jung	done
8270cbfe41SPhilippe Jung}
8370cbfe41SPhilippe Jung
84ff17f0caSRenaud Manuswait_disable() {
85ff17f0caSRenaud Manus	svcinst=$1
86ff17f0caSRenaud Manus	wait_time=$2
87ff17f0caSRenaud Manus
88ff17f0caSRenaud Manus	while [ ${nsec:=0} -lt $wait_time ]; do
89ff17f0caSRenaud Manus		state=`$SVCPROP -p restarter/state $svcinst`
90ff17f0caSRenaud Manus		if [ "$state" = "disabled" -o "$state" = "maintenance" ]; then
91ff17f0caSRenaud Manus			nstate=`$SVCPROP -p restarter/next_state $svcinst`
92ff17f0caSRenaud Manus			if [ "$nstate" = "none" ]; then
93ff17f0caSRenaud Manus				return 0
94ff17f0caSRenaud Manus			fi
95ff17f0caSRenaud Manus		fi
96ff17f0caSRenaud Manus		/usr/bin/sleep 1
97ff17f0caSRenaud Manus		nsec=`expr ${nsec} + 1`
98ff17f0caSRenaud Manus	done
99ff17f0caSRenaud Manus
100ff17f0caSRenaud Manus	return 1
101ff17f0caSRenaud Manus}
102ff17f0caSRenaud Manus
1037c478bd9Sstevel@tonic-gateif [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" ]; then
1047c478bd9Sstevel@tonic-gate	#
1057c478bd9Sstevel@tonic-gate	# We can't safely disable the service in this case.
1067c478bd9Sstevel@tonic-gate	#
1077c478bd9Sstevel@tonic-gate	smf_alive=no
1087c478bd9Sstevel@tonic-gateelse
1097c478bd9Sstevel@tonic-gate	#
1107c478bd9Sstevel@tonic-gate	# We can verify if the service is disabled prior to
1117c478bd9Sstevel@tonic-gate	# removal.
1127c478bd9Sstevel@tonic-gate	#
1137c478bd9Sstevel@tonic-gate	if [ -r /etc/svc/volatile/repository_door ]; then
1147c478bd9Sstevel@tonic-gate		smf_alive=yes
1157c478bd9Sstevel@tonic-gate	fi
1167c478bd9Sstevel@tonic-gatefi
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gatewhile read mfst; do
1197c478bd9Sstevel@tonic-gate	if [ "$smf_alive" = "yes" ]; then
12023294c7dSSean Wilcox		$RM -f $mfst
1217c478bd9Sstevel@tonic-gate
12223294c7dSSean Wilcox		$SVCADM restart svc:/system/manifest-import:default
12370cbfe41SPhilippe Jung	else
12470cbfe41SPhilippe Jung		# deathrow handling
12570cbfe41SPhilippe Jung		svc_deathrow $mfst $PKGINST
12623294c7dSSean Wilcox
12723294c7dSSean Wilcox		$RM -f $mfst
1287c478bd9Sstevel@tonic-gate	fi
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gatedone
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gateexit 0
133