#!/bin/bash
##############################################################################
# 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_cream_stop
#
# DESCRIPTION : This function runs the CREAM CE service.
#
# AUTHORS :     grid-release@infn.it
#
# YAIM MODULE:  glite.yaim.cream-ce
#
##############################################################################

function config_cream_start_check () {

  requires $1  

}

function config_cream_start_setenv () {

  yaimlog DEBUG "No enviroment variables to set."

}

function config_cream_start () {


  GLITE_CREAM_LOCATION_ETC=/etc

  ps ax | grep -v grep |grep blparser > /dev/null 2>&1
  if [ ! $? = 0 ]; then
    yaimlog INFO "Starting blparser"
    ${GLITE_CREAM_LOCATION_ETC}/init.d/glite-ce-blah-parser start
  fi

  ps ax | grep -v grep |grep BUpdater > /dev/null 2>&1  
  bupdater_running=$?
  ps ax | grep -v grep |grep BNotifier > /dev/null 2>&1
  bnotifier_running=$?
  if [ ! ${bupdater_running} = 0 ] && [ ! ${bnotifier_running} = 0 ]; then
    yaimlog INFO "Starting blah"
    ${GLITE_CREAM_LOCATION_ETC}/init.d/glite-ce-blah-parser start
  else 
    yaimlog INFO "blah not running"
  fi

  #workaround for bug #101108
  sleep 5
  
  /sbin/service ${TOMCAT_VERSION} status > /dev/null 2>&1
  tomcat_running=$?
  if [ ! $tomcat_running = 0 ]; then
    yaimlog INFO "Starting tomcat"
    /sbin/service ${TOMCAT_VERSION} start
  fi  

  return 0

}

