Blame SOURCES/mongodb.init

6b52aa
#!/bin/sh
6b52aa
#
6b52aa
# mongodb      init file for starting up the MongoDB server
6b52aa
#
6b52aa
# chkconfig:   - 90 10
6b52aa
# description: Starts and stops the MongDB daemon that handles all \
6b52aa
#              database requests.
6b52aa
6b52aa
# Source function library.
6b52aa
. /etc/rc.d/init.d/functions
6b52aa
6b52aa
exec="/usr/bin/mongod"
6b52aa
prog="mongodb"
6b52aa
logfile="/var/log/mongodb/mongodb.log"
6b52aa
6b52aa
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
6b52aa
6b52aa
pidfile=${PIDFILE-/var/run/mongodb/mongodb.pid}
6b52aa
options="$OPTIONS"
6b52aa
lockfile="/var/lock/subsys/$prog"
6b52aa
6b52aa
# Nicer version of killproc that does not kill mongodb when it takes
6b52aa
# a long time to shut down and does not hang for a long time when mongo
6b52aa
# shuts down quickly
6b52aa
killproc_nice() {
6b52aa
	local RC base pid pid_file= delay i
6b52aa
6b52aa
	RC=0; delay=3
6b52aa
	# Test syntax.
6b52aa
	if [ "$#" -eq 0 ]; then
6b52aa
		echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
6b52aa
		return 1
6b52aa
	fi
6b52aa
	if [ "$1" = "-p" ]; then
6b52aa
		pid_file=$2
6b52aa
		shift 2
6b52aa
	fi
6b52aa
	if [ "$1" = "-d" ]; then
6b52aa
		delay=$2
6b52aa
		shift 2
6b52aa
	fi
6b52aa
6b52aa
	# Save basename.
6b52aa
	base=${1##*/}
6b52aa
6b52aa
	# Find pid.
6b52aa
	__pids_var_run "$1" "$pid_file"
6b52aa
	RC=$?
6b52aa
	if [ -z "$pid" ]; then
6b52aa
		if [ -z "$pid_file" ]; then
6b52aa
			pid="$(__pids_pidof "$1")"
6b52aa
		else
6b52aa
			[ "$RC" = "4" ] && { failure $"$base shutdown" ; return $RC ;}
6b52aa
		fi
6b52aa
	fi
6b52aa
6b52aa
	# Kill it.
6b52aa
	if [ -n "$pid" ] ; then
6b52aa
		[ "$BOOTUP" = "verbose" -a -z "${LSB:-}" ] && echo -n "$base "
6b52aa
		if checkpid $pid 2>&1; then
6b52aa
			# TERM first, then KILL if not dead
6b52aa
			kill -TERM $pid >/dev/null 2>&1
6b52aa
			usleep 100000
6b52aa
6b52aa
			# Check every one second if the program is stopped.
6b52aa
			# Do so for a maximum of $delay seconds
6b52aa
			for ((i = 0 ; i < $delay; i++))
6b52aa
			do
6b52aa
				if checkpid $pid; then
6b52aa
					sleep 1
6b52aa
				else
6b52aa
					break
6b52aa
				fi
6b52aa
			done
6b52aa
6b52aa
			# If the program is not stopped, kill it
6b52aa
			if checkpid $pid ; then
6b52aa
				kill -KILL $pid >/dev/null 2>&1
6b52aa
				usleep 100000
6b52aa
			fi
6b52aa
		fi
6b52aa
		checkpid $pid
6b52aa
		RC=$?
6b52aa
		[ "$RC" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
6b52aa
		RC=$((! $RC))
6b52aa
	else
6b52aa
		failure $"$base shutdown"
6b52aa
		RC=0
6b52aa
	fi
6b52aa
6b52aa
	# Remove pid file if any.
6b52aa
	rm -f "${pid_file:-/var/run/$base.pid}"
6b52aa
	return $RC
6b52aa
}
6b52aa
6b52aa
start() {
6b52aa
    [ -x $exec ] || exit 5
6b52aa
    printf '%s' $"Starting $prog: "
6b52aa
    # why the hell is this not checked in /etc/rc.d/init.d/functions ?
6b52aa
    [ "$(id -u)" -eq 0 ] || exit 4
6b52aa
    # FIXME check mongod source - if parent waits after forking for childs
6b52aa
    #   message about proper initialization
6b52aa
    daemon --pidfile="$pidfile" --user mongodb \
6b52aa
            "$exec $options run >> $logfile 2>&1"
6b52aa
    retval=$?
6b52aa
    echo
6b52aa
    [ $retval -eq 0 ] && touch $lockfile
6b52aa
    return $retval
6b52aa
}
6b52aa
6b52aa
stop() {
6b52aa
    printf '%s' $"Stopping $prog: "
6b52aa
    killproc_nice -p ${pidfile} -d 300 $prog
6b52aa
    retval=$?
6b52aa
    echo
6b52aa
    [ $retval -eq 0 ] && rm -f $lockfile
6b52aa
    return $retval
6b52aa
}
6b52aa
6b52aa
restart() {
6b52aa
    stop
6b52aa
    start
6b52aa
}
6b52aa
6b52aa
reload() {
6b52aa
    restart
6b52aa
}
6b52aa
6b52aa
force_reload() {
6b52aa
    restart
6b52aa
}
6b52aa
6b52aa
rh_status() {
6b52aa
    # run checks to determine if the service is running or use generic status
6b52aa
    status -p ${pidfile} $prog
6b52aa
}
6b52aa
6b52aa
rh_status_q() {
6b52aa
    rh_status >/dev/null 2>&1
6b52aa
}
6b52aa
6b52aa
. __SCL_SCRIPTS__/service-environment
6b52aa
. scl_source enable __list of scls__
6b52aa
6b52aa
case "$1" in
6b52aa
    start)
6b52aa
        rh_status_q && exit 0
6b52aa
        $1
6b52aa
        ;;
6b52aa
    stop)
6b52aa
        rh_status_q || exit 0
6b52aa
        $1
6b52aa
        ;;
6b52aa
    restart)
6b52aa
        $1
6b52aa
        ;;
6b52aa
    reload)
6b52aa
        rh_status_q || exit 7
6b52aa
        $1
6b52aa
        ;;
6b52aa
    force-reload)
6b52aa
        force_reload
6b52aa
        ;;
6b52aa
    status)
6b52aa
        rh_status
6b52aa
        ;;
6b52aa
    condrestart|try-restart)
6b52aa
        rh_status_q || exit 0
6b52aa
        restart
6b52aa
        ;;
6b52aa
    *)
6b52aa
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
6b52aa
        exit 2
6b52aa
esac
6b52aa
exit $?