svc-pkg-depot revision 3056
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews# CDDL HEADER START
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater# The contents of this file are subject to the terms of the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Common Development and Distribution License (the "License").
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# You may not use this file except in compliance with the License.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# See the License for the specific language governing permissions
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# and limitations under the License.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# When distributing Covered Code, include this CDDL HEADER in each
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# If applicable, add the following below this CDDL HEADER, with the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# fields enclosed by brackets "[]" replaced with your own identifying
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# information: Portions Copyright [yyyy] [name of copyright owner]
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# CDDL HEADER END
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Calling $APACHE_BIN/apachectl would source $APACHE_BIN/envvars, which
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# in turn would source /etc/apache2/2.2/envvars, if it exists.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# We want to keep the depot service completely separate from
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# the site system configuration used by svc:/network/http:apache22
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# avoiding /etc/apache2, which means we must avoid apachectl.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# In this method script, we call httpd directly instead, but as a
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# result, we also need to include the relevant contents of
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# $APACHE_BIN/envvars - setting $LD_LIBRARY_PATH as it does.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinLD_LIBRARY_PATH=${APACHE_HOME}/lib/64:${LD_LIBRARY_PATH}
af40ebed6257e4ac1996144530b3de317cf4da11Tinderbox User# A function to pull in the config properties from the FMRI given
af40ebed6257e4ac1996144530b3de317cf4da11Tinderbox User# as the first argument. This allows us to make a single call
af40ebed6257e4ac1996144530b3de317cf4da11Tinderbox User# to svcprop, rather than calling svcprop for each value we
af40ebed6257e4ac1996144530b3de317cf4da11Tinderbox User# want to retrieve.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt if [ $RESULT -ne 0 ]; then
af40ebed6257e4ac1996144530b3de317cf4da11Tinderbox User if [ $RESULT -ne 0 ]; then
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # print a normalized version of a path, needed because
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # many utilities will not dereference non-existent directories
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # in path names, e.g. cat /etc/no-such-dir/../motd will fail.
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User echo $1 | /usr/bin/python -c \
71c66a876ecca77923638d3f94cc0783152b2f03Mark Andrews 'import os.path ; import sys ; print os.path.normpath(sys.stdin.read())'
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ssl_cert_file_cmd="--cert ${depot_ssl_cert_file}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ssl_ca_cert_file_cmd="--ca-cert ${depot_ssl_ca_cert_file}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ssl_ca_key_file_cmd="--ca-key ${depot_ssl_ca_key_file}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ssl_cert_key_dir_cmd="--cert-key-dir ${depot_ssl_cert_key_dir}"
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User if ! [ -z "${depot_ssl_cert_chain_file}" ]; then
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ssl_cert_chain_file_cmd="--cert-chain ${depot_ssl_cert_chain_file}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if [ ${failure} -ne 0 ] ; then
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "pkg.depot-config: failed to create Apache config"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # if we dropped to maintenance and are in the process of
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # clearing that state, we may have htcacheclean processes
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews # Start a cache cleaning daemon, scanning every 2 weeks,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews # being intelligent about only running if the cache has
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews # changed, limiting the cache to ${depot_cache_max}
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews # megabytes, being nice about scheduling and removing
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews -d${interval} -i -l ${depot_cache_max}M -n \
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews -P ${depot_cache_dir}/../depot_htcacheclean.pid \
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews check_failure $? "htcacheclean failed to run cleanly"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein pid_file=$(abspath ${depot_cache_dir}/../depot_htcacheclean.pid)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if [ -f $pid_file ]; then
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein check_failure $? "failed to kill htcacheclean process\
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $PID" "not_fatal"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # We go to lengths to kill remaining httpd processes: if we kill
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater # just the pid, then child httpd.worker processes become
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater # zombies, hanging onto the server port, which causes problems
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater # when trying to start a service that is transitioning from
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater # This function should only be called when the service is
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater # transitioning to maintenance: normal Apache shutdown is
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater pid_file=$(abspath ${depot_runtime_dir}/../depot_httpd.pid)
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater if [ -f $pid_file ]; then
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater /usr/bin/ptree $PID | /usr/bin/awk '{print $1}' | \
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater check_failure $? "failed to kill apache process $PID" \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # Ping the service, ensuring the index gets built if does
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt # Since curl --retry uses an exponential backoff algorithm, this
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt # can result in us waiting 40 seconds, which ought to be long
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # enough for Apache to come online. (index refreshes are run in
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # the background on the server after it has returned a response)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein /usr/bin/curl -s --max-time 5 --retry 4 -o /dev/null ${url} \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein check_failure $? "Unable to access the server at ${url}. Check\
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein the SMF service log or the error log at ${depot_log_dir}/error_log for\
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein more information, if any."
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeincheck_prop ${depot_template_dir} config/template_dir
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeincheck_prop ${depot_runtime_dir} config/runtime_dir
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeincheck_prop ${depot_allow_refresh} config/allow_refresh
ceeb18e6907a10547859faa340ecad83bedae90cMark AndrewsFAILED_TO_RUN="Server failed to %s. Check the SMF service log or the\
ceeb18e6907a10547859faa340ecad83bedae90cMark Andrews error log at ${depot_log_dir}/error_log for more information, if any."
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt # drop privileges now that we've written our configuration
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ${HTTPD} -f ${depot_runtime_dir}/depot_httpd.conf \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # drop privileges now that we've written our configuration
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein emsg=$(/usr/bin/printf ${FAILED_TO_RUN} refresh)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ${HTTPD} -f ${depot_runtime_dir}/depot_httpd.conf \
3a32ac2a720653083c7a22cb654b86c398f6d4c8Tinderbox User emsg=$(/usr/bin/printf ${FAILED_TO_RUN} stop)
3a32ac2a720653083c7a22cb654b86c398f6d4c8Tinderbox User # If https service is on and user blindly deleted the certificate dir,
3a32ac2a720653083c7a22cb654b86c398f6d4c8Tinderbox User # then the stop method will cause error due to not find certificate
3a32ac2a720653083c7a22cb654b86c398f6d4c8Tinderbox User # and key files. Instead of causing this error, we kill the apache
3a32ac2a720653083c7a22cb654b86c398f6d4c8Tinderbox User # instance manually.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ${HTTPD} -f ${depot_runtime_dir}/depot_httpd.conf \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein echo "Usage: $0 {start|stop|refresh}"