blob: 69902c6c114a6feabe6e34d8ef223439e95d93cc [file] [log] [blame]
#! /bin/sh
# init fragment for cancd
#
# chkconfig: 2345 29 20
# description: Start cancd at system boot
#
### BEGIN INIT INFO
# Provides: cancd
# Required-Start: network
# Should-Start:
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Description: start cancd driver at system boot
### END INIT INFO
# Force LC_ALL=C
export LC_ALL=C
if [ -f /etc/redhat-release ]
then
. /etc/init.d/functions
init_status()
{
return 0
}
success_status()
{
success
echo
}
failure_status()
{
failure $1
echo
}
exit_status()
{
exit $?
}
elif [ -f /etc/SuSE-release -o -f /etc/UnitedLinux-release ]
then
. /etc/rc.status
init_status()
{
rc_reset
}
success_status()
{
/bin/true
rc_status -v
}
failure_status()
{
/bin/false
rc_status -v
}
exit_status()
{
rc_exit
}
else
init_status()
{
return 0
}
success_status()
{
echo "OK"
return 0
}
failure_status()
{
echo "Failed"
return 0
}
exit_status()
{
exit $?
}
fi
# Source configuration
[ -f /etc/sysconfig/cancd ] && . /etc/sysconfig/cancd
init_status
#
# if_fail()
#
# Evaluates return codes. If 0, prints "OK", if 1, prints "Failed"
# and exits. If 2, status is "already done" and nothing is printed.
# The rest of the functions in here all honor this convention.
#
if_fail()
{
RC="$1"
REASON="$2"
if [ "$RC" = "0" ]
then
success_status
return
elif [ "$RC" = "2" ]
then
return
fi
failure_status ${REASON}
exit 1
}
find_running()
{
ps -ef | awk '/awk/{next}/\/usr\/sbin\/cancd/{print $2}'
}
start()
{
OPT_PORT=
if [ -n "$CANCD_PORT" ]
then
OPT_PORT="-p ${CANCD_PORT}"
fi
OPT_PATH=
if [ -n "$CANCD_PATH" ]
then
OPT_PATH="-l ${CANCD_PATH}"
fi
echo -n "Starting cancd server: "
OUTPUT="`find_running 2>/dev/null`"
if [ -z "$OUTPUT" ]
then
if [ -n "$CANCD_USER" ]
then
su - "$CANCD_USER" -c "/usr/sbin/cancd $OPT_PORT $OPT_PATH"
else
/usr/sbin/cancd $OPT_PORT $OPT_PATH
fi
if_fail $? "Unable to start cancd"
else
if_fail 0 "Already running"
fi
}
stop()
{
echo -n "Stopping cancd: "
OUTPUT="`find_running 2>/dev/null`"
if [ -z "$OUTPUT" ]
then
if_fail 0 "Not running"
else
kill $OUTPUT
if_fail $? "Unable to kill cancd"
fi
}
status()
{
OUTPUT="`find_running 2>/dev/null`"
if [ -n "$OUTPUT" ]
then
echo "cancd is running"
else
echo "cancd is not running"
fi
}
case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0