#
# 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
#
#
# Load SMF constants and functions
if [[ -z "$SMF_FMRI" ]]; then
echo "this script can only be invoked by smf(7)"
exit $SMF_EXIT_ERR_NOSMF
fi
case "$1" in
'start')
# Handles server startup
# retrieve the pkg_root property. If the variable is left empty
# pkg_root is /
if [[ $? -ne 0 ]]; then
"service: $SMF_FMRI"
exit $SMF_EXIT_ERR_CONFIG
fi
# make sure pkg_root ends with a /
if [[ $? -ne 0 ]]; then
pkg_root="${pkg_root}/"
fi
# if configured readonly & standalone, refresh the depot service,
# if is is present, and exit immediately as a transient service.
standalone=$(svcprop -p pkg/standalone $SMF_FMRI)
"managed_by_depot" \
"svc:/application/pkg/depot configuration updated."
fi
# adjust the PYTHONPATH to point to the current environment
# we need to make sure to adjust the PYTHONPATH accordingly
# to a Python 2.7 or 3.4 environment
python_ver=$(head -1 ${pkg_root}usr/lib/pkg.depotd 2>/dev/null |
if [[ $python_ver != *python* ]]; then
echo "invalid python version $python_ver found in"
echo "${pkg_root}usr/lib/pkg.depotd"
exit $SMF_EXIT_ERR_FATAL
fi
export PYTHONPATH
#
# If this process has net_privaddr, then we pass it along.
# If not, we ensure that we don't specify it, since that will
# cause ppriv to throw an error.
#
privaddr=""
if [[ $? == 0 ]]; then
echo "Dropping net_privaddr privilege."
privaddr=",net_privaddr"
fi
#
# Build up the privileges available starting with "basic". This
# provides some protection even when pkg.depotd runs as root.
#
wrapper="ppriv -s \
A=basic,-file_link_any,-proc_info,-proc_session$privaddr -e"
# Build the command to start pkg.depotd.
# Echo the command so that the log contains the command used to start
# pkg.depotd.
echo $cmd
exec $cmd
;;
'stop')
# if configured readonly & standalone, exit immediately as transient
# unless we've got a running pkg.depotd process, which happens if the
# the server in order to apply those changes.
standalone=$(svcprop -p pkg/standalone $SMF_FMRI)
if [ -z "$2" ] ; then
# there's no existing pkg.depotd - we can exit now.
echo "depot in use, stop method script complete."
exit $SMF_EXIT_OK
fi
fi
#
# Strategy: First, try shutting down pkg.depotd 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.
#
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.
#
ret=$?
# '2' indicates timeout with non-empty contract.
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.
#
exit $SMF_EXIT_ERR_FATAL
fi
fi
else
# If the timeout is too short, we just try once, politely.
fi
;;
*)
echo "Usage: $0 { start | stop }"
exit $SMF_EXIT_ERR_CONFIG
;;
esac
exit $SMF_EXIT_OK