#!/bin/bash
#
# chkconfig:    345 51 59
# description:  A cherrypy framework
#
### BEGIN INIT INFO
# Provides:          wokd wok
# Required-Start:    $syslog $network $remote_fs
# Required-Stop:     $syslog $network $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 4 6
# Short-Description: A cherrypy framework
# Description:       Wok is a cherrypy-based web framework with HTML5 support
#                    originated from Kimchi. It can be extended by plugins which
#                    expose functionality through REST APIs.
### END INIT INFO

WOKD_BIN=/usr/bin/wokd
WOKD_PID=/var/run/wokd.pid

if [ -r /etc/rc.status ]
then
  source /etc/rc.status
  START="/sbin/startproc"
  STATUS="/sbin/checkproc"
  SUCCESS="echo \$rc_done"
  FAILURE="echo \$rc_failed"
else
  source /etc/rc.d/init.d/functions
  START="daemon"
  STATUS="status"
  SUCCESS="success; echo"
  FAILURE="failure; echo"
fi

RETVAL=0

case "$1" in
  start)
    echo -n "Starting wokd: "
    ${START} ${WOKD_BIN}
    RETVAL=$?
    ;;
  stop)
    echo -n "Stopping wokd: "
    killproc ${WOKD_BIN} > /dev/null 2>&1
    RETVAL=$?
    ;;
  restart)
    $0 stop
    $0 start
    unset RETVAL
    ;;
  reload)
    echo -n "Reloading configuration of wokd: "
    ${WOKD_BIN} -s reload 2> /dev/null
    RETVAL=$?
    ;;
  status)
    echo -n "Status of wokd: "
    ${STATUS} ${WOKD_BIN} > /dev/null 2>&1
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reload|checkconf}"
    exit 1
    ;;
esac
[ -z ${RETVAL} ] && exit
[ ${RETVAL} -eq 0 ] && eval "${SUCCESS}" || eval "${FAILURE}"
exit ${RETVAL}
