1902N/A#!/usr/bin/ksh -p
1902N/A#
1902N/A# CDDL HEADER START
1902N/A#
1902N/A# The contents of this file are subject to the terms of the
1902N/A# Common Development and Distribution License (the "License").
1902N/A# You may not use this file except in compliance with the License.
1902N/A#
1902N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1902N/A# or http://www.opensolaris.org/os/licensing.
1902N/A# See the License for the specific language governing permissions
1902N/A# and limitations under the License.
1902N/A#
1902N/A# When distributing Covered Code, include this CDDL HEADER in each
1902N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1902N/A# If applicable, add the following below this CDDL HEADER, with the
1902N/A# fields enclosed by brackets "[]" replaced with your own identifying
1902N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1902N/A#
1902N/A# CDDL HEADER END
1902N/A#
3356N/A# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
1902N/A#
1902N/A
1902N/A# Load SMF constants and functions
1902N/A. /lib/svc/share/smf_include.sh
1902N/A
1902N/Aif [[ -z "$SMF_FMRI" ]]; then
3356N/A echo "this script can only be invoked by smf(7)"
1902N/A exit $SMF_EXIT_ERR_NOSMF
1902N/Afi
1902N/A
1902N/Acase "$1" in
1902N/A'start')
1902N/A # Handles mDNS depot startup
1902N/A
1902N/A # retrieve the pkg_root property. If the variable is left empty
1902N/A # pkg_root is /
1902N/A pkg_root=$(svcprop -p pkg/pkg_root $SMF_FMRI)
1902N/A if [[ $? -ne 0 ]]; then
1902N/A echo "service property pkg/pkg_root not defined for" \
1902N/A "service: $SMF_FMRI"
1902N/A exit $SMF_EXIT_ERR_CONFIG
1902N/A fi
1902N/A
1902N/A # make sure pkg_root ends with a /
1902N/A echo $pkg_root | grep /$ >/dev/null
1902N/A if [[ $? -ne 0 ]]; then
1902N/A pkg_root="${pkg_root}/"
1902N/A fi
1902N/A
1902N/A # adjust the PYTHONPATH to point to the current environment
1902N/A # we need to make sure to adjust the PYTHONPATH accordingly
3177N/A # to a Python 2.7 or 3.4 environment
1902N/A python_ver=$(head -1 ${pkg_root}usr/lib/pkg.depotd 2>/dev/null |
1902N/A awk -F/ '{print $NF}')
1902N/A if [[ $python_ver != *python* ]]; then
1902N/A echo "invalid python version $python_ver found in"
1902N/A echo "${pkg_root}usr/lib/pkg.depotd"
1902N/A exit $SMF_EXIT_ERR_FATAL
1902N/A fi
1902N/A
1902N/A PYTHONPATH=${pkg_root}usr/lib/${python_ver}/vendor-packages/:$PYTHONPATH
1902N/A
1902N/A export PYTHONPATH
1902N/A
2515N/A #
2515N/A # If this process has net_privaddr, then we pass it along.
2515N/A # If not, we ensure that we don't specify it, since that will
2515N/A # cause ppriv to throw an error.
2515N/A #
2515N/A privaddr=""
2515N/A ppriv -v $$ | grep 'E: ' | grep net_privaddr > /dev/null 2>&1
2515N/A if [[ $? == 0 ]]; then
2515N/A echo "Dropping net_privaddr privilege."
2515N/A privaddr=",net_privaddr"
2515N/A fi
1902N/A
2515N/A #
2515N/A # Build up the privileges available starting with "basic". This
2515N/A # provides some protection even when the depot runs as root.
2515N/A #
2515N/A wrapper="ppriv -s \
2515N/A A=basic,-file_link_any,-proc_info,-proc_session$privaddr -e"
1902N/A
2515N/A # Build the command to start pkg.depotd.
2515N/A cmd="$wrapper ${pkg_root}usr/lib/pkg.depotd --llmirror --cfg $SMF_FMRI"
1902N/A # Echo the command so that the log contains the command used to start
1902N/A # the depot.
1902N/A echo $cmd
1902N/A
1902N/A exec $cmd
1902N/A
1902N/A ;;
1902N/A
1902N/A'stop')
1902N/A #
1902N/A # Strategy: First, try shutting down depot using polite kill. Use up
1902N/A # as much as possible of the allotted timeout period waiting for polite
1902N/A # kill to take effect. As time runs out, try a more aggressive kill.
1902N/A #
1902N/A SVC_TIMEOUT=`svcprop -p stop/timeout_seconds $SMF_FMRI`
1902N/A if [[ $? -ne 0 ]]; then
1902N/A echo "service property stop/timeout_seconds not defined" \
1902N/A "for service: $SMF_FMRI"
1902N/A exit $SMF_EXIT_ERR_CONFIG
1902N/A fi
1902N/A
1902N/A #
1902N/A # Note that we're working around an oddity in smf_kill_contract: it
1902N/A # waits in 5 second chunks and can overshoot the specified timeout
1902N/A # by as many as 4 seconds. Example: a specified wait of 6 will result
1902N/A # in a wait of 10 seconds in reality. Since we may potentially do a
1902N/A # first kill and then a second, we must ensure that at least 8 seconds
1902N/A # of slop is left in reserve. To be paranoid, we go for 10.
1902N/A #
1902N/A ((POLITE=$SVC_TIMEOUT - 10))
1902N/A if [[ $POLITE -gt 0 ]]; then
1902N/A smf_kill_contract $2 TERM 1 $POLITE
1902N/A ret=$?
1902N/A # '2' indicates timeout with non-empty contract.
1902N/A if [[ $ret -eq 2 ]]; then
2515N/A echo "Gentle contract kill timed out after" \
1902N/A "$POLITE seconds, trying SIGKILL." >&2
1902N/A #
1902N/A # Again, despite the specified timeout, this will
1902N/A # take a minimum of 5 seconds to complete.
1902N/A #
1902N/A smf_kill_contract $2 KILL 1 1
1902N/A if [[ $ret -ne 0 ]]; then
1902N/A exit $SMF_EXIT_ERR_FATAL
1902N/A fi
1902N/A fi
1902N/A else
1902N/A # If the timeout is too short, we just try once, politely.
1902N/A smf_kill_contract $2 TERM
1902N/A fi
1902N/A ;;
1902N/A
1902N/A*)
1902N/A echo "Usage: $0 { start | stop }"
1902N/A exit $SMF_EXIT_ERR_CONFIG
1902N/A ;;
1902N/A
1902N/Aesac
1902N/Aexit $SMF_EXIT_OK