#!/bin/bash ##### # ESGF Dashboard Services # description: Dashboard Services # #**************************************************************************** #* * #* 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. * #* * #**************************************************************************** ##### #uses: perl, awk, ifconfig, tar, wget, curl, su, useradd, groupadd, # id, chmod, chown, chgrp, cut, svn, mkdir, killall, java, egrep, # lsof, unlink, ln, pax, keytool, openssl #note: usage of readlink not macosx friendly :-( usage of useradd / # groupadd is RedHat/CentOS dependent :-( DEBUG=${DEBUG:-0} VERBOSE=${VERBOSE:-0} envfile="/etc/esg.env" #-------------- #User Defined / Setable (public) #-------------- install_prefix=${install_prefix:-"/usr/local"} cdat_home=${cdat_home:-${install_prefix}/cdat} esg_root_dir=${esg_root_dir:-"/esg"} installer_home=${installer_home:-/usr/local/src/esgf} workdir=${workdir:-${installer_home}/workbench/esg} install_logfile=${install_logfile:-"/etc/esg.install_log"} compress_extensions=${compress_extensions:-".tar.gz|.tar.bz2|.tgz|.bz2|.tar"} #-------------- 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} python_version=${python_version:-"2.7"} config_file=${esg_root_dir}/config/esgf.properties esgf_dashboard_ip_install_dir=${install_prefix}/esgf-dashboard-ip geoip_install_dir=${install_prefix}/geoip geoip_workdir=${workdir}/extra/geoip geoip_dist_url=${esg_dist_url}/geoip/GeoIP.tar.gz geoip_dat_dist_url=${esg_dist_url}/geoip/GeoLiteCity.dat.gz geoip_version=1.4.8 dashboard_log_dir=${dashboard_log_dir:-"/var/log"} dashboard_log_file=${dashboard_log_file:-"${dashboard_log_dir}/esgf-dashboard-ip.log"} word_size=${word_size:-$(file /bin/bash | perl -ple 's/^.*ELF\s*(32|64)-bit.*$/$1/g')} init() { debug_print "esgf-dashoard->init()..." #[ -n "${envfile}" ] && [ -e "${envfile}" ] && source ${envfile} && ((VERBOSE)) && printf "dashboard services: sourcing environment from: ${envfile} \n" dashboard_dist_url=${esg_dist_url}/esgf-dashboard/esgf-dashboard.war dashboard_app_context_root=esgf-dashboard dashboard_app_home=${tomcat_install_dir}/webapps/${dashboard_app_context_root} esgf_dashboard_version=${esgf_dashboard_version:-"1.5"} esgf_dashboard_db_version=${esgf_dashboard_db_version:-"0.0.2"} esgf_dashboard_egg_file=esgf_dashboard-${esgf_dashboard_db_version}-py${python_version}.egg #Database information.... node_db_name=${node_db_name:-"esgcet"} node_db_dashboard_schema_name="esgf_dashboard" postgress_driver=${postgress_driver:-org.postgresql.Driver} postgress_protocol=${postgress_protocol:-jdbc:postgresql:} postgress_host=${PGHOST:-localhost} postgress_port=${PGPORT:-5432} postgress_user=${PGUSER:-dbsuper} pg_sys_acct_passwd=${pg_sys_acct_passwd:=${pg_secret:=changeme}} postgress_install_dir=${PGHOME:-${install_prefix}/pgsql} #Dashboard Information Provider... esgf_dashboard_ip_version=${esgf_dashboard_ip_version:-${esgf_dashboard_version:-"1.5"}} esgf_dashboard_ip_dist_url=${esg_dist_url}/esgf-dashboard/esgf-dashboard-ip-${esgf_dashboard_ip_version}.tar.gz esgf_dashboard_ip_workdir=${esgf_dashboard_ip_workdir:-${workdir}/esgf-dashboard-ip} echo "$(prefix_to_path PATH ${geoip_install_dir}/bin ${esgf_dashboard_ip_install_dir}/bin)" echo "$(prefix_to_path LD_LIBRARY_PATH ${geoip_install_dir}/lib ${postgress_install_dir}/lib)" prefix_to_path PATH ${geoip_install_dir}/bin ${esgf_dashboard_ip_install_dir}/bin >> ${envfile} prefix_to_path LD_LIBRARY_PATH ${geoip_install_dir}/lib ${postgress_install_dir}/lib >> ${envfile} dedup ${envfile} && source ${envfile} ((DEBUG)) && echo ${envfile} ((DEBUG)) && cat ${envfile} debug_print "(PATH = $PATH)" debug_print "(LD_LIBRARY_PATH = $LD_LIBRARY_PATH)" write_as_property dashboard_service_app_home ${dashboard_app_home} write_as_property dashboard_ip_app_home ${esgf_dashboard_ip_install_dir} mkdir -p /esg/config/dashboard write_as_property esgf_registration_xml_download_url "http://${esgf_host}/esgf-nm/registration.xml" write_as_property esgf_registration_xml_path /esg/config/dashboard setup_esgf_stats_api } setup_esgf_stats_api(){ ############################ #Download the esgf-stats-api.war file home site (or use value of esgf_stats_api_dist_file if already set) ############################ esgf_stats_api_dist_file=${esgf_stats_api_file:-${esgf_stats_api_dist_url##*/}} #There is this pesky case of having a zero sized dist file... if [ -e ${esgf_stats_api_dist_file} ]; then ls -l ${esgf_stats_api_dist_file} local size=$(stat -c%s ${esgf_stats_api_dist_file} >& /dev/null) (( size == 0 )) && rm -v ${esgf_stats_api_dist_file} fi checked_get ${esgf_stats_api_dist_file} ${esgf_stats_api_dist_url} $((force_install)) (( $? > 1 )) && echo " ERROR: Could not download ${esgf_stats_api_dist_url} either" && popd && checked_done 1 stop_tomcat #------------------------------------------- #installing the esgf-stats-api web app ("manually") //zoiks echo "Installing esgf-stats-api app..." mkdir -p ${tomcat_install_dir}/webapps pwd cp -v $(readlink -f ${esgf_stats_api_dist_file}) ${tomcat_install_dir}/webapps/ pushd ${tomcat_install_dir}/webapps [ $? != 0 ] && echo " Error: could not go to ${tomcat_install_dir}/webapps directory be sure tomcat is installed!" && checked_done 1 mkdir -p esgf-stats-api cd esgf-stats-api #move the current web.xml file out of the way local webapp_config_file=${tomcat_install_dir}/webapps/esgf-stats-api/WEB-INF/web.xml if ((upgrade)) && [ -e ${webapp_config_file} ]; then cp -v ${webapp_config_file} ${webapp_config_file}.saved fi jar xf ../${esgf_stats_api_dist_file} cd .. chown -R ${tomcat_user} esgf_stats_api* chgrp -R ${tomcat_group} esgf_stats_api* rm ${esgf_stats_api_dist_file} if ((upgrade)) ; then local version_property="Implementation-Version" local current_version=$(sed -n '/^'${version_property}':[ ]*\(.*\)/p' ${tomcat_install_dir}/webapps/esgf_stats_api/META-INF/MANIFEST.MF | awk '{print $2}' | xargs 2> /dev/null) cp -v ${webapp_config_file}.saved ${webapp_config_file} && echo "esgf_stats_api upgraded to ${current_version} $([OK])" && popd >& /dev/null && return 0 fi popd >& /dev/null #------------------------------------------- } ##### # Install The ESGF Dashboard Services ##### # - 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_dashboard() { init setup_dashboard_database $@ #setup_dashboard_webapp $@ setup_geoip && setup_geoip_data && (LD_LIBRARY_PATH=/usr/lib${word_size}:$LD_LIBRARY_PATH setup_dashboard_provider $@) && write_geolocation_properties } setup_dashboard_webapp() { echo -n "Checking for dashboard services ${esgf_dashboard_version}" check_webapp_version "${dashboard_app_context_root}" "${esgf_dashboard_version}" local ret=$? ((ret == 0)) && (( ! force_install )) && echo " [OK]" && return 0 echo echo "*******************************" echo "Setting up The ESGF Dashboard Services" echo "*******************************" echo local upgrade=${1:-0} local default="Y" local dosetup if [ -d ${dashboard_app_home} ]; then echo "Detected an existing dashboard services installation..." read -p "Do you want to continue with dashboard services installation and setup? $([ "$default" = "N" ] && echo "[y/N]" || echo "[Y/n]") " dosetup [ -z "${dosetup}" ] && dosetup=${default} if [ "${dosetup}" != "Y" ] && [ "${dosetup}" != "y" ]; then echo "Skipping dashboard services 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 $dashboard_app_home" backup ${dashboard_app_home} fi echo dobackup="Y" default="N" if [ -n "$(postgres_list_db_schemas ${node_db_dashboard_schema_name})" ]; then read -p "Do you want to make a back up of the existing database schema [${node_db_name}:${node_db_dashboard_schema_name}]? $([ "$default" = "N" ] && echo "[y/N]" || echo "[Y/n]") " dobackup [ -z "${dobackup}" ] && dobackup=${default} if [ "${dobackup}" = "Y" ] || [ "${dobackup}" = "y" ]; then echo "Creating a backup archive of the dashboard database [${node_db_name}:${node_db_dashboard_schema_name}]" backup_db -db ${node_db_name} -s dashboard fi else postgres_clean_schema_migration "ESGF Dashboard" fi unset dobackup unset default echo fi mkdir -p ${workdir} [ $? != 0 ] && return 1 pushd ${workdir} >& /dev/null # local dashboard_dist_file=$(pwd)/${dashboard_dist_url##*/} # checked_get ${dashboard_dist_file} ${dashboard_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 ${dashboard_app_home} # mkdir -p ${dashboard_app_home} # [ $? != 0 ] && echo "Could not create dir ${dashboard_app_home}" && popd >& /dev/null && checked_done 1 # cd ${dashboard_app_home} # echo "Expanding war ${dashboard_dist_file} in $(pwd)" # $JAVA_HOME/bin/jar xf ${dashboard_dist_file} # set_aside_web_app_cleanup ${dashboard_app_home} $? # chown -R ${tomcat_user} ${dashboard_app_home} # chgrp -R ${tomcat_group} ${dashboard_app_home} # popd >& /dev/null #---------------------------- # popd >& /dev/null # write_dashboard_install_log checked_done 0 } write_dashboard_install_log() { echo "$(date ${date_format}) webapp:${dashboard_app_context_root}=${esgf_dashboard_version} ${dashboard_app_home}" >> ${install_logfile} dedup ${install_logfile} return 0 } setup_geoip() { if [ ! -e ${geoip_install_dir} ]; then mkdir -p ${geoip_workdir} [ $? != 0 ] && checked_done 1 chmod a+rw ${geoip_workdir} pushd $geoip_workdir >& /dev/null local geoip_dist_file #------ #For installing geoip 1.4.8 #http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz # #(Note: unzipping the file gives you a dir that is not just this simple because that added a # the version number to the naming of the top level directory. So appending it here below) geoip_dist_file=${geoip_dist_url##*/} geoip_dist_dir=$(echo ${geoip_dist_file} | awk 'gsub(/('$compress_extensions')/,"")')-"${geoip_version}" #------ #There is this pesky case of having a zero sized dist file... WTF!? if [ -e ${geoip_dist_file} ]; then ls -l ${geoip_dist_file} #NOTE: I know there must be a cleaner way to get this, maybe stat? local size=$(ls -l | grep ${geoip_dist_file} | tr -s " " | cut -d " " -f 5) (( size == 0 )) && rm -v ${geoip_dist_file} fi #Check to see if we have postgres distribution directory if [ ! -e ${geoip_dist_dir} ]; then echo "Don't see geoip distribution dir ${geoip_dist_dir}" if [ ! -e ${geoip_dist_file} ]; then echo "Don't see geoip distribution file ${geoip_dist_file} either" echo "Downloading geoip from ${geoip_dist_url}" checked_get ${geoip_dist_file} ${geoip_dist_url} (( $? > 1 )) && echo " ERROR: Could not download GeoIP:${geoip_dist_file}" && popd && checked_done 1 echo "unpacking ${geoip_dist_file}..." tar xzf ${geoip_dist_file} [ $? != 0 ] && echo " ERROR: Could not extract GeoIP: ${geoip_dist_file}" && popd && checked_done 1 fi fi #If you don't see the directory but see the tar.gz distribution #then expand it and go from there.... if [ -e ${geoip_dist_file} ] && [ ! -e ${geoip_dist_dir} ]; then echo "unpacking ${geoip_dist_file}..." tar xzf ${geoip_dist_file} fi pwd pushd ${geoip_dist_dir} >& /dev/null ((force_install)) && (echo "Cleaning the source tree.. $(pwd) " && gmake clean && echo "[OK]" || echo "[FAIL]") echo "./configure --prefix=${geoip_install_dir}" if ./configure --prefix=${geoip_install_dir} \ && make \ && make install then echo "Successfully Configured and Built geoip in: ${geoip_install_dir}" echo "$(date ${date_format}) geoip=${geoip_version} ${geoip_install_dir}" >> ${install_manifest} dedup ${install_manifest} else echo " ERROR: Could NOT successfully build geoip!" popd >& /dev/null checked_done 1 fi popd >& /dev/null popd >& /dev/null write_geoip_paths else echo "Detected a geoip installation... will not re-install geoip" fi return 0 } write_geoip_paths() { ((show_summary_latch++)) prefix_to_path PATH ${geoip_install_dir}/bin >> ${envfile} prefix_to_path LD_LIBRARY_PATH ${geoip_install_dir}/lib ${postgress_install_dir}/lib >> ${envfile} dedup ${envfile} && source ${envfile} } # NOTE: The C code is explicitly looking for the file # "GeoLiteCity.dat" so regardless of what it may be at the url The # file that we write is going to be this one. setup_geoip_data() { echo -n "Installing GeoIP data file: " [ ! -d ${geoip_install_dir} ] && echo "[FAIL]" && return 2 local geoip_dat_dist_file=${geoip_install_dir}/share/GeoIP/GeoLiteCity.dat echo -n "[${geoip_dat_dist_file}]... " if [ ! -e ${geoip_dat_dist_file} ] || (( $(stat -c%s ${geoip_dat_dist_file}) == 0 )); then mkdir -p ${geoip_dat_dist_file%/*} >& /dev/null echo -n "fetching... " curl -s -L --insecure ${geoip_dat_dist_url} | (cd ${geoip_dat_dist_file%/*}; zcat - > ${geoip_dat_dist_file}) fi diff <(md5sum ${geoip_dat_dist_file} | tr -s " " | cut -d " " -f 1) <(curl -s -L --insecure ${geoip_dat_dist_url}.md5 | tr -s " " | cut -d " " -f 1) >& /dev/null [ $? != 0 ] && echo "(verified) - [OK]" && return 0 echo "[FAIL]" return 1 } setup_dashboard_provider() { echo -n "Checking for esgf-dashboard-ip ${esgf_dashboard_version} " check_version esgf-dashboard-ip ${esgf_dashboard_version} [ $? == 0 ] && (( ! force_install )) && echo " [OK]" && return 0 echo echo "*******************************" echo "Setting up ESGF Dashboard IP v${esgf_dashboard_ip_version}" echo "*******************************" echo local default="Y" ((force_install)) && default="N" local dosetup if [ -x ${esgf_dashboard_ip_install_dir}/bin/esgf-dashboard-ip ]; then echo "Detected an existing ESGF Dashboard IP installation..." read -p "Do you want to continue with ESGF Dashboard IP installation and setup? $([ "$default" = "N" ] && echo "[y/N]" || echo "[Y/n]") " dosetup [ -z ${dosetup} ] && dosetup=${default} if [ "${dosetup}" != "Y" ] && [ "${dosetup}" != "y" ]; then echo "Skipping ESGF Dashboard IP installation and setup - will assume ESGF Dashboard IP is setup properly" return 0 fi echo fi mkdir -p ${workdir} [ $? != 0 ] && checked_done 1 chmod a+rw ${workdir} pushd ${workdir} >& /dev/null local esgf_dashboard_ip_dist_file=${esgf_dashboard_ip_dist_url##*/} #strip off .tar.gz at the end local esgf_dashboard_ip_dist_dir=$(echo ${esgf_dashboard_ip_dist_file} | awk 'gsub(/('$compress_extensions')/,"")') #There is this pesky case of having a zero sized dist file... WTF!? if [ -e ${esgf_dashboard_ip_dist_file} ]; then ls -l ${esgf_dashboard_ip_dist_file} local size=$(stat -c%s ${esgf_dashboard_ip_dist_file}) (( size == 0 )) && rm -v ${esgf_dashboard_ip_dist_file} fi #Check to see if we have postgres distribution directory if [ ! -e ${esgf_dashboard_ip_dist_dir} ]; then echo "Don't see ESGF Dashboard IP distribution dir ${esgf_dashboard_ip_dist_dir}" if [ ! -e ${esgf_dashboard_ip_dist_file} ]; then echo "Don't see ESGF Dashboard IP distribution file ${esgf_dashboard_ip_dist_file} either" echo "Downloading ESGF Dashboard IP from ${esgf_dashboard_ip_dist_url}" checked_get ${esgf_dashboard_ip_dist_file} ${esgf_dashboard_ip_dist_url} (( $? > 1 )) && echo " ERROR: Could not download ESGF Dashboard IP:${esgf_dashboard_ip_dist_file}" && popd && checked_done 1 echo "unpacking ${esgf_dashboard_ip_dist_file}..." tar xzf ${esgf_dashboard_ip_dist_file} [ $? != 0 ] && echo " ERROR: Could not extract ESGF Dashboard IP: ${esgf_dashboard_ip_dist_file}" && popd && checked_done 1 fi fi #If you don't see the directory but see the tar.gz distribution #then expand it and go from there.... if [ -e ${esgf_dashboard_ip_dist_file} ] && [ ! -e ${esgf_dashboard_ip_dist_dir} ]; then echo "unpacking ${esgf_dashboard_ip_dist_file}..." tar xzf ${esgf_dashboard_ip_dist_file} fi local ip_props_filename=infoprovider.properties pushd ${esgf_dashboard_ip_dist_dir} ((force_install)) && (echo "Cleaning the source tree.. $(pwd) " && make clean && echo "[OK]" || echo "(Hmmm... not respecting \"make clean\" - eh, no worries)") echo "./configure --prefix=${esgf_dashboard_ip_install_dir}" if ./configure --prefix=${esgf_dashboard_ip_install_dir} --with-postgres-path=${postgress_install_dir} --with-geoip-prefix-path=${geoip_install_dir} \ && make \ && make install then #Install the configuration for for ip run services... if [ ! -e ${esg_config_dir}/dashboard/${ip_props_filename} ] || ((force_install)); then mkdir -p ${esg_config_dir}/dashboard mv ${esg_config_dir}/dashboard/${ip_props_filename}{,.bak} >& /dev/null \cp -v etc/${ip_props_filename} ${esg_config_dir}/dashboard/${ip_props_filename} fi echo "Successfully Configured and Built ESGF Dashboard IP in: ${esgf_dashboard_ip_install_dir}" if [ ! -e "${esgf_dashboard_ip_install_dir}/bin/esgf-dashboard-ip" ]; then echo" ERROR: Did NOT successfully build ESGF Dashboard IP Executable!!" && popd >& /dev/null && checked_done 1 setup_dashboard_logrotate fi else echo" ERROR: Could NOT successfully build ESGF Dashboard IP!!" popd >& /dev/null checked_done 1 fi popd >& /dev/null popd >& /dev/null write_esgf_dashboard_ip_env write_esgf_dashboard_ip_install_log checked_done 0 } write_esgf_dashboard_ip_env() { ((show_summary_latch++)) echo "export ESGF_DASHBOARD_IP_HOME=${esgf_dashboard_ip_install_dir}" >> ${envfile} prefix_to_path PATH ${esgf_dashboard_ip_install_dir}/bin >> ${envfile} dedup ${envfile} && source ${envfile} return 0 } write_esgf_dashboard_ip_install_log() { echo "$(date ${date_format}) esgf_dashboard_ip=$(${esgf_dashboard_ip_install_dir}/bin/esgf-dashboard-ip --version) ${esgf_dashboard_ip_install_dir}" >> ${install_manifest} dedup ${install_manifest} return 0 } #NOTES: #./esgf-iplookup esgf-node3.llnl.gov 52 2>/dev/null #OUTPUT_CITY=Livermore #OUTPUT_LATITUDE=37.503799 #OUTPUT_LONGITUDE=-121.525299 write_geolocation_properties() { debug_print "write_geolocation_properties() ... " get_property node_geolocation_city get_property node_geolocation_lat get_property node_geolocation_lon if [ -z "${node_geolocation_city}" -o -z "${node_geolocation_lat}" -o -z "${node_geolocation_lon}" ]; then $(prefix_to_path PATH ${geoip_install_dir}/bin) $(prefix_to_path LD_LIBRARY_PATH ${geoip_install_dir}/lib) local command="${esgf_dashboard_ip_install_dir}/bin/esgf-iplookup ${esgf_host_ip} 52 2>/dev/null" debug_print "${esgf_dashboard_ip_install_dir}/bin/esgf-iplookup ${esgf_host_ip} 52 2>/dev/null" $command (eval $(awk 'BEGIN {FS="=";} {print $1"=\""$2"\""}' <(${command})) node_geolocation_city=${OUTPUT_CITY} debug_print "node_geolocation_city = ${node_geolocation_city}" [ -n "{node_geolocation_city}" ] && write_as_property node_geolocation_city node_geolocation_lat=${OUTPUT_LATITUDE} debug_print "node_geolocation_lat = ${node_geolocation_lat}" [ -n "{node_geolocation_lat}" ] && write_as_property node_geolocation_lat node_geolocation_lon=${OUTPUT_LONGITUDE} debug_print "node_geolocation_lon = $node_geolocation_lon" [ -n "{node_geolocation_lon}" ] && write_as_property node_geolocation_lon) echo "OUTPUT_CITY = ${OUTPUT_CITY}" fi return 0 } start_dashboard_services() { echo -n "Starting dashboard provider... " $(prefix_to_path PATH ${geoip_install_dir}/bin ${esgf_dashboard_ip_install_dir}/bin) $(prefix_to_path LD_LIBRARY_PATH ${geoip_install_dir}/lib ${postgress_install_dir}/lib) pgrep esgf-dashboard && echo " -> Detected already running dashboard service (must explicitly stop or restart to start new instance)" && return 0 echo ${esgf_dashboard_ip_install_dir}/bin/ip.service start 2>&1 | tee ${dashboard_log_file}.last >(cat >> ${dashboard_log_file}) >& /dev/null & [ $? != 0 ] && echo " ERROR: Could not start esgf dashboard provider" && return 1 return 0 } stop_dashboard_services() { echo "Stopping dashboard provider..." $(prefix_to_path PATH ${geoip_install_dir}/bin ${esgf_dashboard_ip_install_dir}/bin) $(prefix_to_path LD_LIBRARY_PATH ${geoip_install_dir}/lib ${postgress_install_dir}/lib) ${esgf_dashboard_ip_install_dir}/bin/ip.service stop [ $? != 0 ] && echo " ERROR: Could not stop esgf dashboard provider" && popd && return 1 return 0 } restart_dashboard_services() { stop_dashboard_services start_dashboard_services } setup_dashboard_logrotate() { [ ! -e /usr/sbin/logrotate ] && echo "Not able to find logrotate here [/usr/local/logrotate] [FAIL]" && return 1 #TODO: Make these vars properties that can be set by user. # Check property values against values in the logrotate file values to know when to rewrite. local log_rot_size="512M" local log_rot_num_files="20" local dashboard_log_dir=${dashboard_log_dir:-"/var/log"} local dashboard_log_file=${dashboard_log_file:-"${dashboard_log_dir}/esgf-dashboard-ip.log"} local dashboard_logrotate_config="/etc/logrotate.d/esgf_dashboard" local dashboard_user=${dashboard_user:-"root"} local dashboard_group=${dashboard_group:-"root"} [ ! -e "${dashboard_log_dir}" ] && echo "Sorry, could not find log dir [${dashboard_install_dir}] [FAIL]" && return 2 if [ ! -e "${dashboard_logrotate_config}" ] || ((force_install)); then echo "Installing dashboard log rotation... [${dashboard_logrotate_config}]" cat >> ${dashboard_logrotate_config} <& /dev/null [ $? != 0 ] && echo " ERROR: Could not find node distribution dir ${workdir}/${node_dist_dir}" && checked_done 1 #------------------------------------------------------------------------ #Based on the node type selection we build the appropriate database tables #------------------------------------------------------------------------ #download the egg file from the distribution server is necessary.... checked_get ${esgf_dashboard_egg_file} ${esg_dist_url}/esgf-dashboard/${esgf_dashboard_egg_file} $((force_install)) (( $? > 1 )) && return 0 #install the egg.... source ${cdat_home}/bin/activate esgf-pub easy_install ${esgf_dashboard_egg_file} [ $? != 0 ] && echo "ERROR: Could not create esgf dashboard python module" && checked_done 1 #run the code to build the database and install sql migration... ((DEBUG)) && echo "esgf_dashboard_initialize --dburl ${postgress_user}:${pg_sys_acct_passwd}@${postgress_host}:${postgress_port}/${node_db_name} -c" esgf_dashboard_initialize --dburl ${postgress_user}:${pg_sys_acct_passwd}@${postgress_host}:${postgress_port}/${node_db_name} -c [ $? != 0 ] && echo "ERROR: Could not create esgf dashboard database tables in ${node_db_name}" && checked_done 1 source deactivate write_dashboard_db_install_log echo popd >& /dev/null echo echo checked_done 0 } write_dashboard_db_install_log() { echo "$(date ${date_format}) python:esgf_dashboard=${esgf_dashboard_db_version} " >> ${install_logfile} dedup ${install_logfile} return 0 } #-------------------------------------- # Clean / Uninstall this module... #-------------------------------------- clean_dashboard_webapp_subsystem() { init local doit="N" if [ -e ${dashboard_app_home} ]; then read -p "remove ESGF Dashboard web service? (${dashboard_app_home}) [y/N]: " doit if [ "doit" = "Y" ] || [ "$doit" = "y" ]; then echo "removing ${tomcat_install_dir}/webapps/${dashboard_app_context_root}" if [ -n ${dashboard_app_home} ]; then rm -rf ${dashboard_app_home} [ $? != 0 ] && echo "ERROR: Unable to remove ${tomcat_install_dir}/webapps/${dashboard_app_context_root}" && return 1 perl -n -i -e'print unless m!webapp:esgf-dashboard!' ${install_logfile} clean_geoip fi fi fi return 0 } clean_geoip() { echo "cleaning out geoip software... " ([ -n "${geoip_install_dir}" ] && [ -d "${geoip_install_dir}" ] && grep ${install_prefix} <(echo "${geoip_install_dir}") >& /dev/null && rm -rf ${geoip_install_dir} && perl -n -i -e'print unless m!geoip!' ${install_logfile} && echo "[OK]") || echo "[FAIL]" } #NOTE: There are certain fields that we are not pulling from (node_db_name and postgress_host). # If the fit hits the shan I want to make it clear that we are not nuking anyone else's database, etc. # strictly the "esgcet" database on "localhost" clean_dashboard_database_subsystem_installation() { init local doit="N" if $(psql -U ${postgress_user} esgcet -c "\dt esgf_dashboard.;" | egrep '^\([1-9]* row[s]?\)' >& /dev/null); then read -p "remove ESGF Dashboard database, database subsystem AND DATA? (esgf_dashboard.*) [y/N]: " doit if [ "doit" = "Y" ] || [ "$doit" = "y" ]; then #Call me paranoid but I want some integrity check that this code is what is meant to be straight from the distribution. diff <(md5sum ${scripts_dir}/esg-dashboard | tr -s " " | cut -d " " -f 1) <(curl -s -L --insecure ${esg_dist_url}/esgf-dashboard/esg-dashboard.md5 | tr -s " " | cut -d " " -f 1) >& /dev/null [ $? != 0 ] && echo " WARNING: Could not verify ${scripts_dir}/esg-dashboard, aborting this uninstall" && return 3 echo "[VERIFIED]" backup_db -db ${node_db_name} -s dashboard echo "removing esgf_dashboard.* schema and tables and DATA" ${cdat_home}/bin/esgf_dashboard_initialize --dburl ${postgress_user}:${pg_sys_acct_passwd}@localhost:${postgress_port}/esgcet -d 0 [ $? != 0 ] && echo "ERROR: Unable to remove ${tomcat_install_dir}/webapps/${dashboard_app_context_root}" && return 1 rm -rvf ${cdat_home}/envs/esgf-pub/bin/esgf_dashboard_initialize && \ rm -rf ${cdat_home}/envs/esgf-pub/lib/python${python_version}/${esgf_dashboard_egg_file} && \ perl -n -i -e'print unless m!python:esgf_dashboard!' ${install_logfile} && echo "[REMOVED]" fi fi return 0 }