svc-pkg-depot revision 2852
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley#!/usr/bin/ksh -p
bd911976d51f102751848568ccf56592fd5f6d77Tinderbox User#
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# CDDL HEADER START
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# The contents of this file are subject to the terms of the
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Common Development and Distribution License (the "License").
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# You may not use this file except in compliance with the License.
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley#
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# or http://www.opensolaris.org/os/licensing.
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# See the License for the specific language governing permissions
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley# and limitations under the License.
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington#
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# When distributing Covered Code, include this CDDL HEADER in each
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# If applicable, add the following below this CDDL HEADER, with the
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley# fields enclosed by brackets "[]" replaced with your own identifying
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley# information: Portions Copyright [yyyy] [name of copyright owner]
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki# CDDL HEADER END
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki. /lib/svc/share/smf_include.sh
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold KrecickiAPACHE_HOME=/usr/apache2/2.2
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold KrecickiAPACHE_ETC_ROOT=/etc/pkg/depot
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold KrecickiAPACHE_BIN=${APACHE_HOME}/bin/64
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki# Calling $APACHE_BIN/apachectl would source $APACHE_BIN/envvars, which
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# in turn would source /etc/apache2/2.2/envvars, if it exists.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# We want to keep the depot service completely separate from
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# the site system configuration used by svc:/network/http:apache22
27bc16fcdc67f9afefefb54ae98dfdae3a5bc1f8Mukund Sivaraman# avoiding /etc/apache2, which means we must avoid apachectl.
27bc16fcdc67f9afefefb54ae98dfdae3a5bc1f8Mukund Sivaraman#
27bc16fcdc67f9afefefb54ae98dfdae3a5bc1f8Mukund Sivaraman# In this method script, we call httpd directly instead, but as a
ecb6c5782ea248307e86c4bceac6c371d27576a6David Lawrence# result, we also need to include the relevant contents of
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington# $APACHE_BIN/envvars - setting $LD_LIBRARY_PATH as it does.
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington#
575737b964590103f60542849d4536b5ccd4eb3cBrian WellingtonHTTPD=${APACHE_BIN}/httpd.worker
575737b964590103f60542849d4536b5ccd4eb3cBrian WellingtonLD_LIBRARY_PATH=${APACHE_HOME}/lib/64:${LD_LIBRARY_PATH}
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellingtonexport LD_LIBRARY_PATH
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellingtonfunction check_prop {
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington if [ -z "$1" ]; then
2d6a6174f108f58458ebafe4120d6df8e28d3e36Brian Wellington echo "ERROR: SMF property for $2 was empty"
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington exit $SMF_EXIT_ERR_FATAL
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington fi
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington}
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinfunction get_pair {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein NAME=$1
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein shift 2
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein echo "${NAME}=\"$@\""
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington echo "export ${NAME}"
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein}
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# A function to pull in the config properties from the FMRI given
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# as the first argument. This allows us to make a single call
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# to svcprop, rather than calling svcprop for each value we
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley# want to retrieve.
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian Wellingtonfunction get_smf_props {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein IFS="
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein"
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian Wellington SMF_PROPS="$(svcprop -t -p config $1 |\
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian Wellington sed -e 's#config/#depot_#g' -e 's/$/,/g')"
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley IFS=,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein for line in $SMF_PROPS ; do
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein IFS='
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein'
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein eval $(get_pair $line)
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley done
985687b4e080182c1a3a2173df02b94a5b78b24fBob Halley}
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinfunction check_failure {
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RESULT=$1
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki MESSAGE=$2
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki NON_FATAL=$3
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki if [ $RESULT -ne 0 ]; then
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews echo $MESSAGE
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews if [ -n "$NON_FATAL" ]; then
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein fi
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews exit $SMF_EXIT_ERR_FATAL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein fi
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews}
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinfunction check_apache_failure {
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews RESULT=$1
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews MESSAGE=$2
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews if [ $RESULT -ne 0 ]; then
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews echo $MESSAGE
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews kill_apache
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein exit $SMF_EXIT_ERR_FATAL
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews fi
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews}
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinfunction abspath {
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # print a normalized version of a path, needed because
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # many utilities will not dereference non-existent directories
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # in path names, e.g. cat /etc/no-such-dir/../motd will fail.
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews echo $1 | /usr/bin/python -c \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews 'import os.path ; import sys ; print os.path.normpath(sys.stdin.read())'
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein}
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewsfunction run_depot {
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein /usr/lib/pkg.depot-config \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -S \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -c ${depot_cache_dir} \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -h ${depot_host} \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -l ${depot_log_dir} \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -p ${depot_port} \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein -r ${depot_runtime_dir} \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -s ${depot_cache_max} \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -T ${depot_template_dir} \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews -t apache2 \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ${depot_allow_refresh}
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews failure=$?
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews if [ $? -ne 0 ] ; then
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein # make sure we leave nothing behind
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews kill_apache
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews kill_htcacheclean
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki check_failure $failure \
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki "pkg.depot-config: failed to create Apache config"
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki fi
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki}
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecickifunction run_htcacheclean {
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki # if we dropped to maintenance and are in the process of
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki # clearing that state, we may have htcacheclean processes
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki # hanging around.
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki kill_htcacheclean
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki if [ "${depot_cache_max}" != "0" ] ; then
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews # Start a cache cleaning daemon, scanning every 2 weeks,
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews # being intelligent about only running if the cache has
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews # changed, limiting the cache to ${depot_cache_max}
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews # megabytes, being nice about scheduling and removing
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews # empty directories if necessary.
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews interval=$((60 * 24 * 14))
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews /usr/bin/su pkg5srv \
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews -c "/usr/apache2/2.2/bin/htcacheclean \
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews -d${interval} -i -l ${depot_cache_max}M -n \
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews -p ${depot_cache_dir} \
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews -P ${depot_cache_dir}/../depot_htcacheclean.pid \
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews -t"
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews check_failure $? "htcacheclean failed to run cleanly"
3678015d3f91ad80e7ea5fc4c6ee00e16c9f40aeFrancis Dupont fi
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews}
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrewsfunction kill_htcacheclean {
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews pid_file=$(abspath ${depot_cache_dir}/../depot_htcacheclean.pid)
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews if [ -f $pid_file ]; then
39c7fc7e00af20144b94ef332943f62c1b3a622fMark Andrews PID=$(< $pid_file)
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews /usr/bin/kill -TERM $PID
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews check_failure $? "failed to kill htcacheclean process\
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews $PID" "not_fatal"
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein fi
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews}
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewsfunction kill_apache {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein # We go to lengths to kill remaining httpd processes: if we kill
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # just the pid, then child httpd.worker processes become
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # zombies, hanging onto the server port, which causes problems
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein # when trying to start a service that is transitioning from
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # maintenance.
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # This function should only be called when the service is
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # transitioning to maintenance: normal Apache shutdown is
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews # preferable.
29daf5bc7738f1cdab7914562269e1129c81acdcBrian Wellington pid_file=$(abspath ${depot_runtime_dir}/../depot_httpd.pid)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if [ -f $pid_file ]; then
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington PID=$(< $pid_file)
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews /usr/bin/ptree $PID | /usr/bin/awk '{print $1}' | \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews /usr/bin/xargs /usr/bin/kill -TERM
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein check_failure $? "failed to kill apache process $PID" \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not_fatal"
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein /usr/bin/rm $pid_file
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein fi
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews}
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinfunction server_ping {
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # Ping the service, ensuring the index gets built if does
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # not exist.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein # Since curl --retry uses an exponential backoff algorithm, this
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # can result in us waiting 40 seconds, which ought to be long
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # enough for Apache to come online. (index refreshes are run in
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews # the background on the server after it has returned a response)
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews url="http://${depot_host}:${depot_port}"
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews ipv6=$(echo ${depot_host} | /usr/bin/grep :)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if [ -n "$ipv6" ] ; then
4d180bd2100d9c848831c08e7f08a75cc21a9c0aBrian Wellington url="http://\[${depot_host}\]:${depot_port}"
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellington fi
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews /usr/bin/curl -s --max-time 5 --retry 4 -o /dev/null ${url} \
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews2> /dev/null
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein check_failure $? "Unable to access the server at ${url}. Check\
4d180bd2100d9c848831c08e7f08a75cc21a9c0aBrian Wellington the SMF service log or the error log at ${depot_log_dir}/error_log for\
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein more information, if any."
60103a02c62cadc72fef61b8bdab9694e3fcf57aBrian Wellington}
4d180bd2100d9c848831c08e7f08a75cc21a9c0aBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinget_smf_props $SMF_FMRI
473af331834c05fd41b36a6de116a724eae77890Brian Wellingtoncheck_prop ${depot_host} config/host
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewscheck_prop ${depot_port} config/port
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewscheck_prop ${depot_log_dir} config/log_dir
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewscheck_prop ${deport_template_dir} config/template_dir
c1e7aff941dbf40090fec49300e728ad017d4f0cMark Andrewscheck_prop ${depot_runtime_dir} config/runtime_dir
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewscheck_prop ${depot_cache_dir} config/cache_dir
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeincheck_prop ${depot_cache_max} config/cache_max
575737b964590103f60542849d4536b5ccd4eb3cBrian Wellingtoncheck_prop ${depot_allow_refresh} config/allow_refresh
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewsif [ "${depot_allow_refresh}" == "true" ] ; then
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews depot_allow_refresh="-A"
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinelse
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews depot_allow_refresh=""
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewsfi
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian WellingtonFAILED_TO_RUN="Server failed to %s. Check the SMF service log or the\
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian Wellington error log at ${depot_log_dir}/error_log for more information, if any."
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeincase "$1" in
6a8832f784bd53aa6afbda22f6187cea6490e1e1Andreas Gustafsson"start")
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian Wellington cmd="start"
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews run_depot
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews run_htcacheclean
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein emsg=$(/usr/bin/printf ${FAILED_TO_RUN} start)
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews ${HTTPD} -f ${depot_runtime_dir}/depot_httpd.conf \
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews ${STARTUP_OPTIONS} -k ${cmd} 2>&1
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews check_apache_failure $? $emsg
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews server_ping
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews ;;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein"refresh")
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews cmd="graceful"
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews run_depot
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews kill_htcacheclean
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein run_htcacheclean
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews emsg=$(/usr/bin/printf ${FAILED_TO_RUN} refresh)
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews ${HTTPD} -f ${depot_runtime_dir}/depot_httpd.conf \
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews ${STARTUP_OPTIONS} -k ${cmd} 2>&1
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews check_apache_failure $? $emsg
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews server_ping
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ;;
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews"stop")
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews cmd="stop"
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews kill_htcacheclean
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein emsg=$(/usr/bin/printf ${FAILED_TO_RUN} stop)
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews ${HTTPD} -f ${depot_runtime_dir}/depot_httpd.conf \
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews ${STARTUP_OPTIONS} -k ${cmd} 2>&1
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews check_apache_failure $? $emsg
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews ;;
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews*)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein echo "Usage: $0 {start|stop|refresh}"
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews exit $SMF_EXIT_ERR_CONFIG
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews ;;
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrewsesac
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrewsexit $SMF_EXIT_OK
d0221bfa6a08f7b284b231886928aa5d8ac87fc2Mark Andrews