Blame SOURCES/mongos.init

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