svc-pkg-mdns revision 1902
229N/A#!/usr/bin/ksh -p
229N/A#
229N/A# CDDL HEADER START
229N/A#
229N/A# The contents of this file are subject to the terms of the
229N/A# Common Development and Distribution License (the "License").
229N/A# You may not use this file except in compliance with the License.
229N/A#
229N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
229N/A# or http://www.opensolaris.org/os/licensing.
229N/A# See the License for the specific language governing permissions
229N/A# and limitations under the License.
229N/A#
229N/A# When distributing Covered Code, include this CDDL HEADER in each
229N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
229N/A# If applicable, add the following below this CDDL HEADER, with the
229N/A# fields enclosed by brackets "[]" replaced with your own identifying
229N/A# information: Portions Copyright [yyyy] [name of copyright owner]
229N/A#
229N/A# CDDL HEADER END
3817N/A#
229N/A# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
229N/A#
229N/A
1244N/A# Load SMF constants and functions
229N/A. /lib/svc/share/smf_include.sh
229N/A
618N/Aif [[ -z "$SMF_FMRI" ]]; then
229N/A echo "this script can only be invoked by smf(5)"
1258N/A exit $SMF_EXIT_ERR_NOSMF
229N/Afi
3817N/A
3817N/Acase "$1" in
229N/A'start')
229N/A # Handles mDNS depot startup
229N/A
229N/A # short_option_props are properties which are communicated to the depot
229N/A # via a single character flag which takes an argument.
229N/A short_option_props="port"
229N/A set -A short_option_cmd_line "p"
229N/A
229N/A long_option_props="file_root"
1522N/A
1522N/A set -A long_option_cmd_line "file-root"
1522N/A
1938N/A # retrieve the pkg_root property. If the variable is left empty
1938N/A # pkg_root is /
3817N/A pkg_root=$(svcprop -p pkg/pkg_root $SMF_FMRI)
231N/A if [[ $? -ne 0 ]]; then
231N/A echo "service property pkg/pkg_root not defined for" \
814N/A "service: $SMF_FMRI"
229N/A exit $SMF_EXIT_ERR_CONFIG
229N/A fi
229N/A
229N/A # make sure pkg_root ends with a /
229N/A echo $pkg_root | grep /$ >/dev/null
229N/A if [[ $? -ne 0 ]]; then
229N/A pkg_root="${pkg_root}/"
229N/A fi
229N/A
229N/A # adjust the PYTHONPATH to point to the current environment
229N/A # we need to make sure to adjust the PYTHONPATH accordingly
229N/A # to a Python 2.4 or 2.6 environment
229N/A python_ver=$(head -1 ${pkg_root}usr/lib/pkg.depotd 2>/dev/null |
229N/A awk -F/ '{print $NF}')
229N/A if [[ $python_ver != *python* ]]; then
3817N/A echo "invalid python version $python_ver found in"
3817N/A echo "${pkg_root}usr/lib/pkg.depotd"
3817N/A exit $SMF_EXIT_ERR_FATAL
fi
PYTHONPATH=${pkg_root}usr/lib/${python_ver}/vendor-packages/:$PYTHONPATH
export PYTHONPATH
# Go through each property in short_option_props and, if its value is
# set to something other than "", add the appropriate command line
# flag and argument to the string.
cnt=0
for o in $short_option_props; do
val=$(svcprop -p pkg/$o $SMF_FMRI)
if [[ $? -ne 0 ]]; then
echo "service property pkg/$o not defined for" \
"service: $SMF_FMRI"
exit $SMF_EXIT_ERR_CONFIG
fi
# If the SMF property is set to something other than 'none', add
# the flag and its argument to the command.
if [[ $val != '""' ]]; then
option_ops="$option_ops -${short_option_cmd_line[$cnt]} $val"
fi
cnt=$(($cnt + 1))
done
# Go through each property in long_option_props and, if its value is
# set to something other than "", add the appropriate command line
# flag and argument to the string.
cnt=0
for o in $long_option_props; do
val=$(svcprop -p pkg/$o $SMF_FMRI)
if [[ $? -ne 0 ]]; then
echo "service property pkg/$o not defined for" \
"service: $SMF_FMRI"
exit $SMF_EXIT_ERR_CONFIG
fi
if [[ $val != '""' ]]; then
option_ops="$option_ops --${long_option_cmd_line[$cnt]}=$val"
fi
cnt=$(($cnt + 1))
done
# In order to run in mdns mode, we need to append the --llmirror
# flag to the list of command options. Do that last, here.
option_ops="$option_ops --llmirror"
# Build the command to start pkg.depotd with the specified options.
cmd="${pkg_root}usr/lib/pkg.depotd $option_ops"
# Echo the command so that the log contains the command used to start
# the depot.
echo $cmd
exec $cmd
;;
'stop')
#
# Strategy: First, try shutting down depot using polite kill. Use up
# as much as possible of the allotted timeout period waiting for polite
# kill to take effect. As time runs out, try a more aggressive kill.
#
SVC_TIMEOUT=`svcprop -p stop/timeout_seconds $SMF_FMRI`
if [[ $? -ne 0 ]]; then
echo "service property stop/timeout_seconds not defined" \
"for service: $SMF_FMRI"
exit $SMF_EXIT_ERR_CONFIG
fi
#
# Note that we're working around an oddity in smf_kill_contract: it
# waits in 5 second chunks and can overshoot the specified timeout
# by as many as 4 seconds. Example: a specified wait of 6 will result
# in a wait of 10 seconds in reality. Since we may potentially do a
# first kill and then a second, we must ensure that at least 8 seconds
# of slop is left in reserve. To be paranoid, we go for 10.
#
((POLITE=$SVC_TIMEOUT - 10))
if [[ $POLITE -gt 0 ]]; then
smf_kill_contract $2 TERM 1 $POLITE
ret=$?
# '2' indicates timeout with non-empty contract.
if [[ $ret -eq 2 ]]; then
echo "Gentle contract kill timed out after"
"$POLITE seconds, trying SIGKILL." >&2
#
# Again, despite the specified timeout, this will
# take a minimum of 5 seconds to complete.
#
smf_kill_contract $2 KILL 1 1
if [[ $ret -ne 0 ]]; then
exit $SMF_EXIT_ERR_FATAL
fi
fi
else
# If the timeout is too short, we just try once, politely.
smf_kill_contract $2 TERM
fi
;;
*)
echo "Usage: $0 { start | stop }"
exit $SMF_EXIT_ERR_CONFIG
;;
esac
exit $SMF_EXIT_OK