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