#!/bin/sh
#
# Startup script for the XReg Daemon
#
# /etc/init.d/novell-xregd
#
# description: xregd provides registry services
# for applications that leverage the Novell
# XTier libraries.
#
# processname: novell-xregd
# pidfile: None
# config utility: None.


### BEGIN INIT INFO
# Provides: novell-xregd
# Required-Start: $local_fs $network
# Should-Start: namcd
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: XReg Daemon
# Description: Start XReg Daemon
### END INIT INFO

#
# LSB and RH have killproc and pidofproc in common


if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
  START_DAEMON=daemon
  START_DAEMON_FLAG=--user
#  STATUS=status
  LOG_SUCCESS=success
  LOG_FAILURE=failure
  LOG_WARNING=passed
  ECHO=echo
elif [ -f /lib/lsb/init-functions ]; then
  . /lib/lsb/init-functions
  START_DAEMON=start_daemon
  START_DAEMON_FLAG=-u
#  STATUS=MyStatus
  LOG_SUCCESS=log_success_msg
  LOG_FAILURE=log_failure_msg
  LOG_WARNING=log_warning_msg
  ECHO=
else
  echo "Error: your platform is not supported by $0" > /dev/stderr
  $ECHO
  exit 1
fi

if [ -f /etc/opt/novell/xtier/envvars ]; then
  . /etc/opt/novell/xtier/envvars 
fi

DAEMON=/opt/novell/xtier/bin/novell-xregd
DAEMON_USER=novlxregd
DAEMON_GROUP=novlxtier

StartDAEMON()
{
  # Source the environments file for xregd
  #. /etc/opt/novell/xtier/xregd/envvars

  # Force ownership of all directories and files required for
  # smooth running. This is to get around possible LUM induced
  # ID mismatch
  chown ${DAEMON_USER}:${DAEMON_GROUP} /var/opt/novell/xtier 2> /dev/null
  chown -R ${DAEMON_USER}:${DAEMON_GROUP} /var/opt/novell/xtier/xregd 2> /dev/null
  
  # Update the limit parameters
  ulimit -c unlimited
  ulimit -f unlimited
  
  # Start the daemon
  echo -n "Starting novell-xregd..."
  $START_DAEMON $START_DAEMON_FLAG $DAEMON_USER $DAEMON -d
  RVAL=$?
  rc_status -v
  $ECHO
}

StopDAEMON()
{
  echo -n "Stopping novell-xregd..."
  killproc $DAEMON
  RVAL=$?
  rc_status -v
  $ECHO
}

case "$1" in
start)
  StartDAEMON
  ;;
stop)
  StopDAEMON
  ;;
restart|reload|force-reload)
  StopDAEMON
  sleep 1
  StartDAEMON
  ;;
status)
  ps ax | grep "$DAEMON" | grep -v grep 2>&1 > /dev/null
  if [ "x$?" = "x0" ]; then
    rc_failed 0
    rc_status -v
    rc_exit
  else
    rc_failed 3
    rc_status -v
  fi
  ;;
*)
  echo -n "Usage: $0 <start|stop|restart|reload|force-reload>" > /dev/stderr
  RVAL=1
  $ECHO
  ;;
esac


if [ -f /etc/SuSE-release ]; then
  rc_failed $RVAL
  #rc_status -v
  rc_exit
else
  exit $RVAL
fi
