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