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