#!/bin/bash

# mongod - Startup script for mongod

# chkconfig: 35 85 15
# description: Mongo is a scalable, document-oriented database.
# processname: mongod
# config: /etc/mongo/mongod.conf
# pidfile: /var/run/mongo/mongo.pid

. /etc/init.d/functions

# things from mongod.conf get there by mongod reading it

SYSCONFIG="/etc/sysconfig/mongod"
CONFIGFILE="/etc/mongod.conf"

. "$SYSCONFIG" || true

OPTIONS="$OPTIONS -f /etc/mongo/mongod.conf"

LOCKFILE=/var/lock/subsys/mongod
RETVAL=0

start()
{
	start_daemon --lockfile "$LOCKFILE" --set-user mongod -- mongod $OPTIONS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --lockfile "$LOCKFILE" -- mongod
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		restart
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --expect-user mongod -- mongod
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
