svc-pkg-sysrepo revision 2349
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt#!/sbin/sh
26d8ffe715e74d1e67d268551449b780fec1b95fAutomatic Updater#
26d8ffe715e74d1e67d268551449b780fec1b95fAutomatic Updater# CDDL HEADER START
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater#
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# The contents of this file are subject to the terms of the
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# Common Development and Distribution License (the "License").
26d8ffe715e74d1e67d268551449b780fec1b95fAutomatic Updater# You may not use this file except in compliance with the License.
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt#
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
26d8ffe715e74d1e67d268551449b780fec1b95fAutomatic Updater# or http://www.opensolaris.org/os/licensing.
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# See the License for the specific language governing permissions
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# and limitations under the License.
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt#
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# When distributing Covered Code, include this CDDL HEADER in each
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
26d8ffe715e74d1e67d268551449b780fec1b95fAutomatic Updater# If applicable, add the following below this CDDL HEADER, with the
64affc54f96a2c71cbd10ed71e246ce0746259aaAutomatic Updater# fields enclosed by brackets "[]" replaced with your own identifying
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# information: Portions Copyright [yyyy] [name of copyright owner]
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt#
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# CDDL HEADER END
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater#
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater#
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt#
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt. /lib/svc/share/smf_include.sh
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
553ead32ff5b00284e574dcabc39115d4d74ec66Evan HuntAPACHE_HOME=/usr/apache2/2.2
553ead32ff5b00284e574dcabc39115d4d74ec66Evan HuntAPACHE_ETC_ROOT=/etc/pkg/sysrepo
553ead32ff5b00284e574dcabc39115d4d74ec66Evan HuntAPACHE_BIN=${APACHE_HOME}/bin/64
553ead32ff5b00284e574dcabc39115d4d74ec66Evan HuntHTTPD=${APACHE_BIN}/httpd
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic UpdaterLD_LIBRARY_PATH=${APACHE_HOME}/lib/64:${LD_LIBRARY_PATH}
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntexport LD_LIBRARY_PATH
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updatergetprop() {
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt PROPVAL=""
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater svcprop -q -p $1 ${SMF_FMRI}
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt if [ $? -eq 0 ] ; then
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater PROPVAL=`svcprop -p $1 ${SMF_FMRI}`
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if [ "${PROPVAL}" = "\"\"" ] ; then
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater PROPVAL=""
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater fi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater return
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt fi
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt return
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt}
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntcheck_failure() {
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt RESULT=$1
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater MESSAGE=$2
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if [ $RESULT -ne 0 ]; then
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater echo $MESSAGE
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater exit $SMF_EXIT_ERR_FATAL
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater fi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterrun_sysrepo() {
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt /usr/lib/pkg.sysrepo \
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt -R / \
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater -c ${SYSREPO_CACHE_DIR} \
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt -h ${SYSREPO_HOST} \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -l ${SYSREPO_LOG_DIR} \
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt -p ${SYSREPO_PORT} \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -r ${SYSREPO_RUNTIME_DIR} \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -s ${SYSREPO_CACHE_MAX} \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -t ${SYSREPO_TEMPLATE_DIR}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater check_failure $? "pkg.sysrepo failed to create Apache configuration"
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntrun_htcacheclean() {
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt if [ "${SYSREPO_CACHE_DIR}" != "None" ] && \
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt [ "${SYSREPO_CACHE_DIR}" != "memory" ]; then
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt # Start a cache cleaning daemon, scanning every 120 minutes,
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt # being intelligent about only running if the cache has changed,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater # limiting the cache to ${SYSREPO_CACHE_MAX} megabytes, being
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater # nice about scheduling and removing empty directories if
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater # necessary.
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater /usr/bin/su pkg5srv -c "/usr/apache2/2.2/bin/htcacheclean \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -d120 -i -l ${SYSREPO_CACHE_MAX}M -n \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -p ${SYSREPO_CACHE_DIR} \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -P ${SYSREPO_CACHE_DIR}/../sysrepo_htcacheclean.pid \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater -t"
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater check_failure $? "htcacheclean failed to run cleanly"
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater fi
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater}
64affc54f96a2c71cbd10ed71e246ce0746259aaAutomatic Updater
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updaterkill_htcacheclean() {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if [ -f ${SYSREPO_CACHE_DIR}/../sysrepo_htcacheclean.pid ]; then
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater PID=$(< ${SYSREPO_CACHE_DIR}/../sysrepo_htcacheclean.pid)
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater /usr/bin/kill -TERM $PID
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater check_failure $? "failed to kill htcacheclean process $PID"
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt fi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updatergetprop config/host
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updaterif [ "${PROPVAL}" != "" ] ; then
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater SYSREPO_HOST=${PROPVAL}
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updaterfi
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updatergetprop config/port
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterif [ "${PROPVAL}" != "" ] ; then
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater SYSREPO_PORT=${PROPVAL}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterfi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntgetprop config/log_dir
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntif [ "${PROPVAL}" != "" ] ; then
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt SYSREPO_LOG_DIR=${PROPVAL}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterfi
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updatergetprop config/template_dir
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntif [ "${PROPVAL}" != "" ] ; then
5a24d24c8fba3480d707c0c902379ddb36501e12Automatic Updater SYSREPO_TEMPLATE_DIR=${PROPVAL}
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntfi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntgetprop config/runtime_dir
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterif [ "${PROPVAL}" != "" ] ; then
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt SYSREPO_RUNTIME_DIR=${PROPVAL}
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntfi
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updatergetprop config/cache_dir
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updaterif [ "${PROPVAL}" != "" ] ; then
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater SYSREPO_CACHE_DIR=${PROPVAL}
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updaterfi
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updatergetprop config/cache_max
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterif [ "${PROPVAL}" != "" ] ; then
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt SYSREPO_CACHE_MAX=${PROPVAL}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterfi
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updatercase "$1" in
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater"start")
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt cmd="start"
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt run_sysrepo
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt run_htcacheclean
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater ${STARTUP_OPTIONS} -k ${cmd} 2>&1
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater 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."
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ;;
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater"refresh")
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater cmd="graceful"
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater run_sysrepo
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater /usr/bin/pkill -USR1 -ox zoneproxyd
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater kill_htcacheclean
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater run_htcacheclean
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ${STARTUP_OPTIONS} -k ${cmd} 2>&1
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater 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."
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ;;
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater"stop")
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater cmd="stop"
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater kill_htcacheclean
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ${HTTPD} -f ${SYSREPO_RUNTIME_DIR}/sysrepo_httpd.conf \
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ${STARTUP_OPTIONS} -k ${cmd} 2>&1
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater 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."
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ;;
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater*)
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater echo "Usage: $0 {start|stop|refresh}"
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater exit $SMF_EXIT_ERR_CONFIG
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater ;;
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updateresac
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updaterexit $SMF_EXIT_OK
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt