svc-pkg-sysrepo revision 2310
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#
2310N/A# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2310N/A#
2310N/A
2310N/A. /lib/svc/share/smf_include.sh
2310N/A
2310N/AAPACHE_HOME=/usr/apache2/2.2
2310N/AAPACHE_ETC_ROOT=/etc/pkg/sysrepo
2310N/AAPACHE_BIN=${APACHE_HOME}/bin/64
2310N/AHTTPD=${APACHE_BIN}/httpd
2310N/ALD_LIBRARY_PATH=${APACHE_HOME}/lib/64:${LD_LIBRARY_PATH}
2310N/Aexport LD_LIBRARY_PATH
2310N/A
2310N/Agetprop() {
2310N/A PROPVAL=""
2310N/A svcprop -q -p $1 ${SMF_FMRI}
2310N/A if [ $? -eq 0 ] ; then
2310N/A PROPVAL=`svcprop -p $1 ${SMF_FMRI}`
2310N/A if [ "${PROPVAL}" = "\"\"" ] ; then
2310N/A PROPVAL=""
2310N/A fi
2310N/A return
2310N/A fi
2310N/A return
2310N/A}
2310N/A
2310N/Acheck_failure() {
2310N/A RESULT=$1
2310N/A MESSAGE=$2
2310N/A if [ $RESULT -ne 0 ]; then
2310N/A echo $MESSAGE
2310N/A exit $SMF_EXIT_ERR_FATAL
2310N/A fi
2310N/A}
2310N/A
2310N/Arun_sysrepo() {
2310N/A /usr/lib/pkg.sysrepo \
2310N/A -R / \
2310N/A -c ${SYSREPO_CACHE_DIR} \
2310N/A -h ${SYSREPO_HOST} \
2310N/A -l ${SYSREPO_LOG_DIR} \
2310N/A -p ${SYSREPO_PORT} \
2310N/A -r ${SYSREPO_RUNTIME_DIR} \
2310N/A -s ${SYSREPO_CACHE_MAX} \
2310N/A -t ${SYSREPO_TEMPLATE_DIR}
2310N/A check_failure $? "pkg.sysrepo failed to create Apache configuration"
2310N/A}
2310N/A
2310N/Arun_htcacheclean() {
2310N/A if [ "${SYSREPO_CACHE_DIR}" != "None" ] && \
2310N/A [ "${SYSREPO_CACHE_DIR}" != "memory" ]; then
2310N/A # Start a cache cleaning daemon, scanning every 120 minutes,
2310N/A # being intelligent about only running if the cache has changed,
2310N/A # limiting the cache to ${SYSREPO_CACHE_MAX} megabytes, being
2310N/A # nice about scheduling and removing empty directories if
2310N/A # necessary.
2310N/A /usr/bin/su pkg5srv -c "/usr/apache2/2.2/bin/htcacheclean \
2310N/A -d120 -i -l ${SYSREPO_CACHE_MAX}M -n \
2310N/A -p ${SYSREPO_CACHE_DIR} \
2310N/A -P ${SYSREPO_CACHE_DIR}/../sysrepo_htcacheclean.pid \
2310N/A -t"
2310N/A check_failure $? "htcacheclean failed to run cleanly"
2310N/A fi
2310N/A}
2310N/A
2310N/Akill_htcacheclean() {
2310N/A if [ -f ${SYSREPO_CACHE_DIR}/../sysrepo_htcacheclean.pid ]; then
2310N/A PID=$(< ${SYSREPO_CACHE_DIR}/../sysrepo_htcacheclean.pid)
2310N/A /usr/bin/kill -TERM $PID
2310N/A check_failure $? "failed to kill htcacheclean process $PID"
2310N/A fi
2310N/A}
2310N/A
2310N/Agetprop config/host
2310N/Aif [ "${PROPVAL}" != "" ] ; then
2310N/A SYSREPO_HOST=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/port
2310N/Aif [ "${PROPVAL}" != "" ] ; then
2310N/A SYSREPO_PORT=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/log_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
2310N/A SYSREPO_LOG_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/template_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
2310N/A SYSREPO_TEMPLATE_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/runtime_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
2310N/A SYSREPO_RUNTIME_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/cache_dir
2310N/Aif [ "${PROPVAL}" != "" ] ; then
2310N/A SYSREPO_CACHE_DIR=${PROPVAL}
2310N/Afi
2310N/A
2310N/Agetprop config/cache_max
2310N/Aif [ "${PROPVAL}" != "" ] ; then
2310N/A SYSREPO_CACHE_MAX=${PROPVAL}
2310N/Afi
2310N/A
2310N/Acase "$1" in
2310N/A"start")
2310N/A cmd="start"
2310N/A run_sysrepo
2310N/A run_htcacheclean
2310N/A ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
2310N/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
2310N/A kill_htcacheclean
2310N/A run_htcacheclean
2310N/A ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
2310N/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 kill_htcacheclean
2310N/A ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
2310N/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