svc-pkg-depot revision 2868
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
#
# Calling $APACHE_BIN/apachectl would source $APACHE_BIN/envvars, which
#
# We want to keep the depot service completely separate from
#
# In this method script, we call httpd directly instead, but as a
# result, we also need to include the relevant contents of
# $APACHE_BIN/envvars - setting $LD_LIBRARY_PATH as it does.
#
export LD_LIBRARY_PATH
function check_prop {
if [ -z "$1" ]; then
echo "ERROR: SMF property for $2 was empty"
exit $SMF_EXIT_ERR_FATAL
fi
}
function get_pair {
NAME=$1
shift 2
echo "${NAME}=\"$@\""
echo "export ${NAME}"
}
# A function to pull in the config properties from the FMRI given
# as the first argument. This allows us to make a single call
# to svcprop, rather than calling svcprop for each value we
# want to retrieve.
function get_smf_props {
IFS="
"
IFS=,
for line in $SMF_PROPS ; do
IFS='
'
done
}
function check_failure {
RESULT=$1
MESSAGE=$2
NON_FATAL=$3
echo $MESSAGE
return
fi
exit $SMF_EXIT_ERR_FATAL
fi
}
function check_apache_failure {
RESULT=$1
MESSAGE=$2
echo $MESSAGE
exit $SMF_EXIT_ERR_FATAL
fi
}
function abspath {
# print a normalized version of a path, needed because
# many utilities will not dereference non-existent directories
# in path names, e.g. cat /etc/no-such-dir/../motd will fail.
'import os.path ; import sys ; print os.path.normpath(sys.stdin.read())'
}
function run_depot {
-S \
-c ${depot_cache_dir} \
-h ${depot_host} \
-l ${depot_log_dir} \
-p ${depot_port} \
-r ${depot_runtime_dir} \
-s ${depot_cache_max} \
-T ${depot_template_dir} \
-t apache2 \
failure=$?
if [ $? -ne 0 ] ; then
# make sure we leave nothing behind
"pkg.depot-config: failed to create Apache config"
fi
}
function run_htcacheclean {
# if we dropped to maintenance and are in the process of
# clearing that state, we may have htcacheclean processes
# hanging around.
if [ "${depot_cache_max}" != "0" ] ; then
# Start a cache cleaning daemon, scanning every 2 weeks,
# being intelligent about only running if the cache has
# changed, limiting the cache to ${depot_cache_max}
# megabytes, being nice about scheduling and removing
# empty directories if necessary.
/usr/apache2/2.2/bin/htcacheclean \
-d${interval} -i -l ${depot_cache_max}M -n \
-p ${depot_cache_dir} \
-P ${depot_cache_dir}/../depot_htcacheclean.pid \
-t
check_failure $? "htcacheclean failed to run cleanly"
fi
}
function kill_htcacheclean {
if [ -f $pid_file ]; then
check_failure $? "failed to kill htcacheclean process\
$PID" "not_fatal"
fi
}
function kill_apache {
# We go to lengths to kill remaining httpd processes: if we kill
# just the pid, then child httpd.worker processes become
# zombies, hanging onto the server port, which causes problems
# when trying to start a service that is transitioning from
# maintenance.
# This function should only be called when the service is
# transitioning to maintenance: normal Apache shutdown is
# preferable.
pid_file=$(abspath ${depot_runtime_dir}/../depot_httpd.pid)
if [ -f $pid_file ]; then
"not_fatal"
fi
}
function server_ping {
# Ping the service, ensuring the index gets built if does
# not exist.
# Since curl --retry uses an exponential backoff algorithm, this
# can result in us waiting 40 seconds, which ought to be long
# enough for Apache to come online. (index refreshes are run in
# the background on the server after it has returned a response)
url="http://${depot_host}:${depot_port}"
ipv6=$(echo ${depot_host} | /usr/bin/grep :)
url="http://\[${depot_host}\]:${depot_port}"
fi
check_failure $? "Unable to access the server at ${url}. Check\
the SMF service log or the error log at ${depot_log_dir}/error_log for\
more information, if any."
}
if [ "${depot_allow_refresh}" == "true" ] ; then
depot_allow_refresh="-A"
else
fi
FAILED_TO_RUN="Server failed to %s. Check the SMF service log or the\
error log at ${depot_log_dir}/error_log for more information, if any."
case "$1" in
"start")
cmd="start"
# drop privileges now that we've written our configuration
;;
"refresh")
cmd="graceful"
# drop privileges now that we've written our configuration
;;
"stop")
cmd="stop"
emsg=$(/usr/bin/printf ${FAILED_TO_RUN} stop)
;;
*)
echo "Usage: $0 {start|stop|refresh}"
exit $SMF_EXIT_ERR_CONFIG
;;
esac
exit $SMF_EXIT_OK