manifest_cleanup.ksh revision b379f220491c0f1b07e7619fec53bb5efcde5fdc
#
# 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
# 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.
#
UPLIST=0
#
# Create a list of service to manifest pairs for the upgrade
# process to determine what files are associated with a service
#
function create_list {
do
do
cl_instance=${cl_invent#*:}
cl_instance=${cl_instance##*/*}
[ $cl_instance ] && continue
eval $cl_invent=\"\$$cl_invent $cl_mfile\"
done
done
UPLIST=1
}
#
# Inventory the instances listed with a manifest file
#
function get_instances {
gi_mfile=$1
lst=""
do
[ $gi_tmp ] && lst="$lst $gi_invent"
done
echo $lst
}
function pid_timeout {
pt_pid=$1
pt_cnt=0
do
sleep 1
done
return 1
else
return 0
fi
}
#
# Process a service to ensure that it's manifests exist
# and are in sync with the service.
#
function process_service {
ps_service=$1
#
# Throw away unsupported services, if there is a false listing
# for manifestfiles support
#
[ $? -eq 0 ] && return
#
# Create the list of instances for this service.
#
#
# Check to see if the manifest files associated with the service are
# missing, or if the manifest file has changed, either caught here
# or by the caller.
#
if [ $? -eq 0 ]; then
ps_ret=0
do
done
fi
fi
ps_mfiles_cnt=${#ps_mfiles[@]}
ps_instances=`$SVCS -H -oFMRI $ps_service 2>/dev/null`
#
# For each manifest file that is listed by the service
# check for its existance. If it exists, then check that
# the instances of the service are supported by at least
# one of the manifest files listed.
#
do
#
# This is an unsupported service just return
# skipping the service.
#
if [ ! -f $mf ]; then
continue
fi
set -A ps_inst_list
do
ps_inst_tmp=""
for j in $ps_instances
do
if [ "$i" == "$j" ]; then
set -A ps_inst_list ${ps_inst_list[*]} $j
continue
else
ps_inst_tmp="$ps_inst_tmp $j"
fi
done
#
# If there are any instances not accounted for add
# them to the list to be cleaned up.
#
done
done
#
# If there are any manifest files set them to the list
# to be cleaned up.
#
set -A ps_mfiles $ps_mfiles_tmp
#
# For each manifest file that was not found remove it from
# the service's list of manifest files.
#
do
#
# list.
#
[ $ps_mfiles_cnt -ne ${#ps_mfiles[@]} ] && \
done
#
# If all the manifest files that were listed in the service have now
# been removed, delete the service.
#
if [ $ps_mfiles_cnt -eq ${#ps_mfiles[@]} ]; then
#
# Disable each of the instances for the service
# then delete the service.
#
# If the restarter is not startd then the service
# will not be online at this point and we need
# to not wait on the disable.
#
# Set the delete opt to -f if the disable is not
# synchronous.
#
$SVCPROP -q -p general/restarter $ps_service
if [ $? -ne 0 ]; then
DISOPT="-s"
DELOP=""
else
DISOPT=""
DELOP="-f"
fi
for i in `$SVCS -H -oFMRI $ps_service`
do
CPID=$!
if [ $? -ne 0 ]; then
DELOPT="-f"
kill $CPID
fi
done
echo "$SVCCFG delete $ps_service"
return
fi
#
# Need to only cleanup instances that are no longer supported
# by the manifest files associated with the service.
#
for i in $ps_instances
do
#
# Ignore any instances that are hand created
#
[ $? -ne 0 ] && continue
#
# If the restarter is not startd then the service
# will not be online at this point and we need
# to not wait on the disable.
#
$SVCPROP -q -p general/restarter $ps_service
if [ $? -ne 0 ]; then
DELOP=""
CPID=$!
if [ $? -ne 0 ]; then
DELOPT="-f"
kill $CPID
fi
else
DELOP="-f"
fi
echo "$SVCCFG delete $i"
done
#
# If instances of the services were removed, refresh the
# additional instances, or cleanup any leftover services.
#
if [ $ps_refresh -ne 0 ]; then
if [ ${#ps_inst_list[@]} -gt 0 ]; then
for i in ${ps_inst_list[@]}
do
done
else
do
done
[ $ps_support -eq 0 ] && $SVCCFG delete $ps_service
fi
fi
}
#
# Upgrade a service to have the manifest files associated with
# listed in the manifestfiles property group.
#
# If the first argument is FALSE, then check to see if the service
# has any previous import indications. If so then delete the
# service, otherwise set the service as a non-supported service
# for the automated manifest deletion process.
#
function add_manifest {
am_service=$1
shift
if [ "$1" == "FALSE" ]; then
#
# Check for a last-import snapshot, if there is not
# one then the service was hand crafted and the support
# should be set to false.
#
if [ $? -eq 0 ]; then
do
done
fi
if [ $am_lisnap -ne 0 ]; then
$SVCCFG -s $am_service setprop $MFSTPG/support = boolean: 0
return
fi
#
# If the service was not hand crafted then check to see if
# directory and therefore a known removed service.
#
if [ $? -eq 0 ]; then
echo "$SVCCFG delete $am_service"
else
#
# Do not know where the service came from so set
# it to false.
#
$SVCCFG -s $am_service setprop $MFSTPG/support = boolean: 0
fi
else
do
done
fi
}
#
# a pointer to the actual manifest file.
#
function upgrade_smfmanifest {
us_unfnd=""
for us_E in `$SVCPROP smf/manifest | grep md5sum | grep var_svc_manifest | awk '{print $1}' | awk -F'/' '{print $1}'`
do
$SVCPROP -q -p $us_E/manifestfile smf/manifest
[ $? -eq 0 ] && continue
us_R=""
do
done
if [ -f $us_S ]; then
[ ! "$R" ] && \
else
fi
done
echo "$us_unfnd"
}
function manifest_cleanup {
#
# If manifest-import had activity then need to make checks to override
# a mfstscan that returns no modifications. This is because the hash
# table will already have been updated by the manifest-import run,
# therefor manifest-cleanup will not see those changes in the mfstscan
# call.
#
# activity indicates changes and overrides the needwork check.
# force can be a list of files that will only be processed
# or force can be set to true, so that all files are checked
# regardless.
#
arg1=$1
[ "$1" ] && shift
argrest=$@
#
#
mfc=`$SVCPROP smf/manifest | grep var_svc_manifest | grep -cw manifestfile`
activity="true"
force="true"
fi
fi
fi
#
# Walk the list of services...
#
export SVCCFG_CHECKHASH=1
do
if [ $? -ne 0 ]; then
if [[ -n $mc_igchk ]]; then
echo "add_manifest $service FALSE"
continue
fi
[ $UPLIST -eq 0 ] && create_list
eval manifestlist=\$$CS
echo "add_manifest $service $manifestlist"
else
echo "add_manifest $service FALSE"
fi
else
fi
done
rm -f $MCLEANUPFILE
unset SVCCFG_CHECKHASH
#
# Check to make sure all work was processed and
# that all the files were removed correctly from
#
for f in $leftover $unfnd_upgrade
do
done
}