#!/bin/bash
#
#
# ovirt-db-omatic       startup script for ovirt-db-omatic
#
# chkconfig: - 97 03
# description: ovirt-db-omatic is an essential component of the \
#    ovirt VM manager.
#

[ -r /etc/sysconfig/ovirt-rails ] && . /etc/sysconfig/ovirt-rails

export RAILS_ENV="${RAILS_ENV:-production}"

DAEMON=/usr/share/ovirt-server/db-omatic/db_omatic.rb
DBOMATIC_LOCKFILE="${DBOMATIC_LOCKFILE:-/var/lock/subsys/ovirt-db-omatic }"

. /etc/init.d/functions

start() {
    echo -n "Starting ovirt-db-omatic: "
    daemon $DAEMON
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        touch  $DBOMATIC_LOCKFILE
    fi
}

stop() {
    echo -n "Shutting down ovirt-db-omatic: "
    killproc db_omatic.rb
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm  $DBOMATIC_LOCKFILE
    fi
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	stop
	start
	;;
    reload)
        ;;
    force-reload)
        restart
        ;;
    status)
	status $DAEMON
	RETVAL=$?
	;;
    *)
      echo "Usage: ovirt-db-omatic {start|stop|restart|status}"
      exit 1
  ;;
esac
exit $RETVAL
