#!/bin/sh
#
# Author: Carlos Cesario <carloscesario@gmail.com>
#
# init.d/fedora-ds-admin
#
#   and symbolic its link
#
# /usr/sbin/rcfedora-ds-admin
#
# System startup script for the Fedora Directory Admin Server
# Based from http://www.directory.fedora.redhat.com/download/fedora-ds-admin-init.d
#
### BEGIN INIT INFO
# Provides: fedora-ds-admin
# Required-Start: $network $remote_fs
# Required-Stop:
# Default-Start:  2 3 5
# Default-Stop:
# Description:    Start Fedora Directory Admin Server
### END INIT INFO

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

# Source our configuration file for these variables.
FLAGS=
RETVAL=0
ulimit -n 8192

# Set up some common variables before we launch into what might be
#Path FDS
APP_PATH=/opt/fedora-ds

# {start|stop} admin scripts
START_CMD=$APP_PATH/start-admin
STOP_CMD=$APP_PATH/start-admin

#Geral command control
GERAL_CMD="httpd.worker"

#Program Name
PRG_NAME="Fedora Admin Server"

#################################################################
# INIT SCRIPT
#################################################################



case "$1" in
     start)

	echo -n "Starting $PRG_NAME "
	checkproc $GERAL_CMD
        
	if [ $? -eq 0 ] ; then
	    echo -e -n "\nWarning: $GERAL_CMD already running ! "
            rc_failed
	else
	    startproc $START_CMD
	fi
	rc_status -v
     ;;
     stop)
	echo "Shutting down $PRG_NAME"
	if checkproc $GERAL_CMD ; then
	     killproc -TERM $GERAL_CMD
             echo -n "Warning: $PRG_NAME killed ! "
	else
	     echo -n "Warning: $PRG_NAME not running ! "
	     rc_failed 7
	fi
	rc_status -v
     ;;
     status)
	echo -n "Checking for $PRG_NAME application "
	checkproc $GERAL_CMD
	rc_status -v
     ;;
     restart)
	$0 stop
	$0 start
	rc_status
     ;;
     *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
     ;;
esac
rc_exit
