Blame SOURCES/mongos.init

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