##############################################################################
# Copyright (c) Members of the EGEE Collaboration. 2004.
# See http://www.eu-egee.org/partners/ for details on the copyright
# holders.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################
#
# NAME :        config_glexec_wn_log
#
# DESCRIPTION : This function creates the glexec log and logroate in the WN.
#
# AUTHORS :     Maria.Alandes.Pradillo@cern.ch
#               Dennis.van.Dok@nikhef.nl
#
# NOTES :       
#
# YAIM MODULE:  glite-yaim-clients
#
##############################################################################

config_glexec_wn_log_check () {

  requires $1 GLEXEC_WN_LCASLCMAPS_LOG GLEXEC_WN_OPMODE GLEXEC_WN_LOG_DESTINATION
  if [ $? -eq 1 ]; then
    exit 1
  fi

  if [ "x${GLEXEC_WN_LOG_DESTINATION}" == "xfile" ]; then
    requires $1 GLEXEC_WN_LOG_FILE
    if [ $? -eq 1 ]; then
      exit 1
    fi
  fi

}

config_glexec_wn_log_setenv () {
 yaimlog DEBUG "Currently this function doesn't set any environment variables."
 return 0
}


config_glexec_wn_log () {

  ####@ Creating lcas/lcmaps glexec log file
  dir=`dirname ${GLEXEC_WN_LCASLCMAPS_LOG}`
  if [ ! -d ${dir} ]; then
      yaimlog DEBUG "creating ${dir}"
      mkdir -p ${dir}
  fi
  if [ ! -f ${GLEXEC_WN_LCASLCMAPS_LOG} ]; then
      yaimlog DEBUG "Creating lcas/lcmaps glexec log file"
      touch ${GLEXEC_WN_LCASLCMAPS_LOG}
      # make sure it is not world-readable
      chmod 640 ${GLEXEC_WN_LCASLCMAPS_LOG}
  fi

  if [ "x${GLEXEC_WN_LOG_DESTINATION}" == "xfile" ]; then
  ####@ Creating glexec log file
      yaimlog DEBUG "Creating glexec log file"
      dir=`dirname ${GLEXEC_WN_LOG_FILE}`
      if [ ! -d ${dir} ]; then
	  yaimlog DEBUG "Creating ${dir}"
	  mkdir -p ${dir}
      fi
      if [ ! -f ${GLEXEC_WN_LOG_FILE} ]; then
	  touch ${GLEXEC_WN_LOG_FILE}
	  chmod 640 ${GLEXEC_WN_LOG_FILE}
      fi
      if [ "x${GLEXEC_WN_OPMODE}" == "xlog-only" ]; then
	  yaimlog WARNING "glexec is configured to work in logging only mode. GLEXEC_WN_LOG_DESTINATION should be 'syslog'."
	  yaimlog WARNING "glexec may fail since GLEXEC_WN_LOG_DESTINATION is set to 'file' !"
      fi

  fi

  return 0

}

