#!/bin/sh
#
# drizzled      Drizzle Database Server
#
# chkconfig:    - 65 37
# description:  Drizzle Database Server
#

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysqld
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind ldap ntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop drizzled
# Description: Drizzle Database Server
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/sbin/drizzled7"
prog="Drizzle"
config="/etc/drizzle/drizzled.cnf"
pid_file="/var/run/drizzle/drizzled.pid"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    gprintf "Starting %s: " "$prog"
    daemon "$exec --daemon >/dev/null 2>&1"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    gprintf "Stopping %s: " "$prog"
    killproc -p $pid_file $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status -p $pid_file $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        gprintf "Usage: %s {start|stop|status|restart|condrestart|try-restart|reload|force-reload}\n" "$0"
        exit 2
esac
exit $?
