Blame SOURCES/mongos.init

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