#!/bin/bash
#
# cdispd        Configuration Dispatch Daemon
#
# Copyright (c) 2003 EU DataGrid.
# For license conditions see http://www.eu-datagrid.org/license.html
#
# #
# Current developer(s):
#   Luis Fernando Muñoz Mejías <Luis.Munoz@UGent.be>
#   Michel Jouvin <jouvin@lal.in2p3.fr>
#   Nick Williams <nick.williams@morganstanley.com>
#

# #
# Author(s): Germán Cancio Meliá, Marco Emilio Poleggi
#


service=/sbin/service
daemon=ncm-cdispd

#echo Checking $daemon status...
${service} $daemon status > /dev/null
status=$?
if [ $status -eq 2 -o $status -eq 1 ]         # Daemon is dead
then
  echo "Restarting $daemon..."
  # First ensure that we have a good profile in the expected format in case of a problem before
  ccm-fetch --force
  ${service} $daemon start
elif [ $status -eq 3 ]
then
  echo "Daemon $daemon has been intentionally stopped. Not restarted."
elif [ $status -ne 0 ]
then
  echo "$0: internal error during daemon $daemon check ($service returned unhandled status $status)"
fi

