#!/bin/bash ##### # ESGF STATS API # description: REST APIs for the collection of federated statistics... # #**************************************************************************** #* * #* Copyright (c) 2009, Lawrence Livermore National Security, LLC. * #* Produced at the Lawrence Livermore National Laboratory * #* Written by: Gavin M. Bell (gavin@llnl.gov) * #* LLNL-CODE-420962 * #* * #* All rights reserved. This file is part of the: * #* Earth System Grid Fed (ESGF) Node Software Stack, Version 1.0 * #* * #* For details, see http://esgf.org/ * #* Please also read this link * #* http://esgf.org/LICENSE * #* * #* * Redistribution and use in source and binary forms, with or * #* without modification, are permitted provided that the following * #* conditions are met: * #* * #* * Redistributions of source code must retain the above copyright * #* notice, this list of conditions and the disclaimer below. * #* * #* * Redistributions in binary form must reproduce the above copyright * #* notice, this list of conditions and the disclaimer (as noted below) * #* in the documentation and/or other materials provided with the * #* distribution. * #* * #* Neither the name of the LLNS/LLNL nor the names of its contributors * #* may be used to endorse or promote products derived from this * #* software without specific prior written permission. * #* * #* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * #* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * #* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * #* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE * #* LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR * #* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * #* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * #* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * #* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * #* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * #* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * #* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * #* SUCH DAMAGE. * #* * #**************************************************************************** DEBUG=${DEBUG:-0} VERBOSE=${VERBOSE:-0} envfile="/etc/esg.env" esgf_stats_api_version=${esgf_stats_api_version:-"0.9"} #-------------- #User Defined / Settable (public) #-------------- install_prefix=${install_prefix:-"/usr/local"} workdir=${workdir:-${installer_home:-"/usr/local/src/esgf"}/workbench/esg} esg_root_dir=${esg_root_dir:-${ESGF_HOME:-"/esg"}} esg_config_dir=${esg_root_dir}/config esgf_stats_api_config_dir=${esg_config_dir}/stats-api install_manifest=${install_manifest:-"${esg_root_dir}/esgf-install-manifest"} #-------------- date_format=${date_format:-"+%Y_%m_%d_%H%M%S"} force_install=${force_install:-0} tomcat_user=${tomcat_user:-tomcat} tomcat_group=${tomcat_group:-$tomcat_user} tomcat_install_dir=${CATALINA_HOME:-${install_prefix}/tomcat} stats_api_context_root=esgf-stats-api stats_api_service_app_home=${tomcat_install_dir}/webapps/${stats_api_context_root} init() { [ -n "${envfile}" ] && [ -e "${envfile}" ] && source ${envfile} && ((VERBOSE)) && printf "stats-api: sourcing environment from: ${envfile} \n" stats_api_dist_url=${esg_dist_url}/esgf-stats-api/esgf-stats-api.war } ##### # Install the REST APIs ##### # - Takes boolean arg: 0 = setup / install mode (default) # 1 = updated mode # # In setup mode it is an idempotent install (default) # In update mode it will always pull down latest after archiving old # setup_stats_api() { init echo -n "Checking for stats-api ${esgf_stats_api_version}" check_webapp_version "${stats_api_context_root}" "${esgf_stats_api_version}" local ret=$? ((ret == 0)) && (( ! force_install )) && echo " [OK]" && return 0 echo echo "*******************************" echo "Setting up The ESGF STATS APIs" echo "*******************************" echo local upgrade=${1:-0} local default="Y" ((force_install)) && default="N" local dosetup if [ -d ${stats_api_service_app_home} ]; then echo "Detected an existing stats-api installation..." read -p "Do you want to continue with stats-api installation and setup? $([ "$default" = "N" ] && echo "[y/N]" || echo "[Y/n]") " dosetup [ -z "${dosetup}" ] && dosetup=${default} if [ "${dosetup}" != "Y" ] && [ "${dosetup}" != "y" ]; then echo "Skipping stats-api installation and setup - will assume it's setup properly" return 0 fi local dobackup="Y" read -p "Do you want to make a back up of the existing distribution?? [Y/n] " dobackup [ -z "${dobackup}" ] && dobackup=${default} if [ "${dobackup}" = "Y" ] || [ "${dobackup}" = "y" ]; then echo "Creating a backup archive of this web application $stats_api_service_app_home" backup ${stats_api_service_app_home} fi echo fi mkdir -p ${workdir} [ $? != 0 ] && return 1 pushd ${workdir} >& /dev/null local stats_api_dist_file=$(pwd)/${stats_api_dist_url##*/} checked_get ${stats_api_dist_file} ${stats_api_dist_url} $((force_install)) (( $? > 1 )) && echo " ERROR: Could not download ${node_dist_url} :-(" && popd >& /dev/null && checked_done 1 stop_tomcat #---------------------------- #make room for new install set_aside_web_app ${stats_api_service_app_home} mkdir -p ${stats_api_service_app_home} [ $? != 0 ] && echo "Could not create dir ${stats_api_service_app_home}" && popd >& /dev/null && checked_done 1 cd ${stats_api_service_app_home} echo "Expanding war ${stats_api_dist_file} in $(pwd)" $JAVA_HOME/bin/jar xf ${stats_api_dist_file} set_aside_web_app_cleanup ${stats_api_service_app_home} $? chown -R ${tomcat_user} ${stats_api_service_app_home} chgrp -R ${tomcat_group} ${stats_api_service_app_home} popd >& /dev/null #---------------------------- popd >& /dev/null write_stats_api_install_log setup_config post_stats_api_install checked_done 0 } setup_config() { echo -n "Setting up config file(s) for stats-api... " local multimedia_config_filename="multimedia.txt.template" if [ -e ${esgf_stats_api_config_dir}/${multimedia_config_filename%.*} ] && ((!force_install)); then ((DEBUG)) && echo "${multimedia_config_filename%.*} file already present " echo ":-) " return 0 fi mkdir -p ${esgf_stats_api_config_dir} >& /dev/null ((DEBUG)) && echo "cp -v ${stats_api_service_app_home}/WEB-INF/classes/${multimedia_config_filename} ${esgf_stats_api_config_dir}/${multimedia_config_filename%.*}" cp ${stats_api_service_app_home}/WEB-INF/classes/${multimedia_config_filename} ${esgf_stats_api_config_dir}/${multimedia_config_filename%.*} && echo "[OK]" || echo "[FAIL]" } stats_api_startup_hook() { echo -n "Desktop Startup Hook: " setup_config } post_stats_api_install() { echo -n "performing post install cleanup... " ([ -d "${tomcat_install_dir}/work" ] && rm -rf ${tomcat_install_dir}/work) && echo "[OK]" || echo "[FAIL]" } write_stats_api_install_log() { echo "$(date ${date_format}) webapp:${stats_api_context_root}=${esgf_stats_api_version} ${stats_api_service_app_home}" >> ${install_manifest} dedup ${install_manifest} write_as_property stats_api_service_endpoint http://${esgf_host}/${stats_api_context_root}/ write_as_property stats_api_service_app_home return 0 } clean_stats_api_webapp_subsystem() { init local doit="N" if [ -e ${stats_api_service_app_home} ]; then read -p "remove ESGF STATS APIs web service? (${stats_api_service_app_home}) [y/N]: " doit if [ "doit" = "Y" ] || [ "$doit" = "y" ]; then echo "removing ${stats_api_service_app_home}" if [ -n ${stats_api_service_app_home} ]; then rm -rf ${stats_api_service_app_home} [ $? != 0 ] && echo "ERROR: Unable to remove ${stats_api_service_app_home}" && return 1 perl -n -i -e'print unless m!webapp:esgf-stats-api!' ${install_manifest} fi fi fi if [ ! -e ${stats_api_service_app_home} ]; then debug_print "removing stats-api associated properties..." remove_property stats_api_service_endpoint remove_property stats_api_service_app_home fi return 0 }