#!/bin/sh

###############################################################################
#
# /etc/init.d/sys - control script for the xcp daemons.
# Also accessed via a symbolic links named /usr/local/sbin/rcxcpserver  
# Also accessed via a symbolic links named /usr/local/sbin/rcxcpserver
#
# Copyright (c) 2006, all rights reserved
# License- GPL
# Author-  David Olave, template obtained from sys script 
# Company- Adtec Digital, Inc.
# Date-    2007-02-07   
#
###############################################################################


readonly SERVERDAEMON="/usr/local/sbin/xcpServerd"
readonly CLIENTDAEMON="/usr/local/sbin/xcpClientd"


# Indicate whether reloads are supported via signals (usually SIGHUP (1)).
# If so, define RELOAD_SIGNAL to the signal. If not, comment out.
#RELOAD_SIGNAL="1"

# Include the common script for all service scripts.
source /etc/init.d/rcservices

#------------------------------------------------------------------------------
# Start the service.
do_start ()
{
  echo -n "Starting $SERVERDAEMON daemon "
  start-stop-daemon --quiet --start --exec $SERVERDAEMON
  case $? in
    0) RESULT=$SUCCESS;;             # Started OK
    1) RESULT=$PROGRAM_IS_RUNNING;;  # Already running
    *) RESULT=$FAILED;;              # Trouble
  esac

  print_result
  
  echo -n "Starting $CLIENTDAEMON daemon "
  start-stop-daemon --quiet --start --exec $CLIENTDAEMON
  case $? in
    0) RESULT=$SUCCESS;;             # Started OK
    1) RESULT=$PROGRAM_IS_RUNNING;;  # Already running
    *) RESULT=$FAILED;;              # Trouble
  esac

  print_result
  return $RESULT
}

#------------------------------------------------------------------------------
# Stop the service.
do_stop ()
{
  echo -n "Stopping $CLIENTDAEMON daemon "
  start-stop-daemon --quiet --stop --exec $CLIENTDAEMON

  case $? in
    0) RESULT=$SUCCESS;;              # Stopped OK
    1) RESULT=$PROGRAM_NOT_RUNNING;;  # No process running
    *) RESULT=$FAILED;;               # Trouble
  esac
  print_result
  
  echo -n "Stopping $SERVERDAEMON daemon "
  start-stop-daemon --quiet --stop --exec $SERVERDAEMON

  case $? in
    0) RESULT=$SUCCESS;;              # Stopped OK
    1) RESULT=$PROGRAM_NOT_RUNNING;;  # No process running
    *) RESULT=$FAILED;;               # Trouble
  esac
  print_result


  return $RESULT
}

# Do the service.
dispatch_service $1

