Blame SOURCES/mongos.init

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