2310N/A#!/sbin/sh
2310N/A#
2310N/A# CDDL HEADER START
2310N/A#
2310N/A# The contents of this file are subject to the terms of the
2310N/A# Common Development and Distribution License (the "License").
2310N/A# You may not use this file except in compliance with the License.
2310N/A#
2310N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2310N/A# or http://www.opensolaris.org/os/licensing.
2310N/A# See the License for the specific language governing permissions
2310N/A# and limitations under the License.
2310N/A#
2310N/A# When distributing Covered Code, include this CDDL HEADER in each
2310N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2310N/A# If applicable, add the following below this CDDL HEADER, with the
2310N/A# fields enclosed by brackets "[]" replaced with your own identifying
2310N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2310N/A#
2310N/A# CDDL HEADER END
2310N/A#
2310N/A#
3237N/A# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
2310N/A#
2310N/A
2310N/A. /lib/svc/share/smf_include.sh
2310N/A
3237N/AAPACHE_HOME=/usr/apache2/2.4
2310N/AAPACHE_ETC_ROOT=/etc/pkg/sysrepo
3237N/AAPACHE_BIN=${APACHE_HOME}/bin
2367N/A
3237N/AHTTPD=${APACHE_BIN}/apachectl
2310N/A
2310N/Agetprop() {
3216N/A PROPVAL=""
3216N/A svcprop -q -p $1 ${SMF_FMRI}
3216N/A if [ $? -eq 0 ] ; then
3216N/A PROPVAL=$(svcprop -p $1 ${SMF_FMRI})
3216N/A if [ "${PROPVAL}" = "\"\"" ] ; then
3216N/A PROPVAL=""
3216N/A fi
3216N/A return
3216N/A fi
3216N/A return
2310N/A}
2310N/A
2310N/Acheck_failure() {
3216N/A RESULT=$1
3216N/A MESSAGE=$2
3216N/A NON_FATAL=$3
3216N/A if [ $RESULT -ne 0 ]; then
3216N/A echo $MESSAGE
3216N/A if [ -n "$NON_FATAL" ]; then
3216N/A return
3216N/A fi
3216N/A exit $SMF_EXIT_ERR_FATAL
2367N/A fi
2310N/A}
2310N/A
2310N/Arun_sysrepo() {
2479N/A if [ "$http_proxy" ]; then
2479N/A SYSREPO_HTTP_PROXY="-w ${http_proxy}"
2479N/A fi
2479N/A if [ "$https_proxy" ]; then
2479N/A SYSREPO_HTTPS_PROXY="-W ${https_proxy}"
2479N/A fi
2479N/A
3216N/A # Despite using a scheduled service for the htcacheclean
3216N/A # process, pkg.sysrepo is still used to check the
3216N/A # $SYSREPO_CACHE_* variables for valid values.
3216N/A # See svc:/application/pkg/system-repository-cache-maintenance
3216N/A /usr/lib/pkg.sysrepo \
3216N/A -R / \
3216N/A -c ${SYSREPO_CACHE_DIR} \
3216N/A -h ${SYSREPO_HOST} \
3216N/A -l ${SYSREPO_LOG_DIR} \
3216N/A -p ${SYSREPO_PORT} \
3216N/A -r ${SYSREPO_RUNTIME_DIR} \
3216N/A -s ${SYSREPO_CACHE_MAX} \
3216N/A -t ${SYSREPO_TEMPLATE_DIR} \
3216N/A ${SYSREPO_HTTP_PROXY} \
3216N/A ${SYSREPO_HTTPS_PROXY}
3216N/A check_failure $? "pkg.sysrepo: failed to create Apache configuration"
2310N/A}
2310N/A
2310N/Agetprop config/host
2310N/Aif [ "${PROPVAL}" != "" ] ; then
3216N/A SYSREPO_HOST=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/port
2310N/Aif [ "${PROPVAL}" != "" ] ; then
3216N/A SYSREPO_PORT=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/log_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
3216N/A SYSREPO_LOG_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/template_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
3216N/A SYSREPO_TEMPLATE_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/runtime_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
3216N/A SYSREPO_RUNTIME_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/cache_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
3216N/A SYSREPO_CACHE_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/cache_max
2310N/Aif [ "${PROPVAL}" != "" ] ; then
3216N/A SYSREPO_CACHE_MAX=${PROPVAL}
2310N/Afi
2310N/A
2479N/Agetprop config/http_proxy
2479N/Aif [ "${PROPVAL}" != "" ] ; then
2479N/A http_proxy=${PROPVAL}
2479N/Afi
2479N/A
2479N/Agetprop config/https_proxy
2479N/Aif [ "${PROPVAL}" != "" ] ; then
2479N/A https_proxy=${PROPVAL}
2479N/Afi
2479N/A
2310N/Acase "$1" in
2310N/A"start")
2310N/A cmd="start"
2310N/A run_sysrepo
2858N/A # drop privileges now that we've written our configuration
2858N/A /usr/bin/ppriv -s E=basic,net_privaddr $$
2310N/A ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
3216N/A ${STARTUP_OPTIONS} -k ${cmd} 2>&1
2310N/A check_failure $? "Server failed to start. Check the SMF service log or the error log at ${SYSREPO_LOG_DIR}/error_log for more information, if any."
2310N/A ;;
2310N/A"refresh")
2310N/A cmd="graceful"
2310N/A run_sysrepo
2858N/A # drop privileges now that we've written our configuration
2858N/A /usr/bin/ppriv -s E=basic,net_privaddr $$
2349N/A /usr/bin/pkill -USR1 -ox zoneproxyd
2310N/A ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
3216N/A ${STARTUP_OPTIONS} -k ${cmd} 2>&1
2310N/A check_failure $? "Server failed to refresh. Check the SMF service log or the error log at ${SYSREPO_LOG_DIR}/error_log for more information, if any."
2310N/A ;;
2310N/A"stop")
2310N/A cmd="stop"
2310N/A ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
3216N/A ${STARTUP_OPTIONS} -k ${cmd} 2>&1
2310N/A check_failure $? "Server failed to stop. Check the SMF service log or the error log at ${SYSREPO_LOG_DIR}/error_log for more information, if any."
2310N/A ;;
2310N/A*)
2310N/A echo "Usage: $0 {start|stop|refresh}"
2310N/A exit $SMF_EXIT_ERR_CONFIG
2310N/A ;;
2310N/Aesac
2310N/A
2310N/Aexit $SMF_EXIT_OK