You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
3.3 KiB
171 lines
3.3 KiB
9 months ago
|
#!/bin/sh
|
||
|
#
|
||
|
# mongos init file for starting up the mongoDB shard server
|
||
|
#
|
||
|
# chkconfig: - 90 10
|
||
|
# description: Starts and stops the mongoDB shard daemon that handles all \
|
||
|
# database requests.
|
||
|
|
||
|
# Source function library.
|
||
|
. /etc/rc.d/init.d/functions
|
||
|
|
||
|
prog="mongos"
|
||
|
exec="/usr/bin/$prog"
|
||
|
logfile=${LOGFILE-/var/log/mongodb/$prog.log}
|
||
|
|
||
|
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
|
||
|
|
||
|
pidfile=${PIDFILE-/var/run/mongodb/$prog.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
|
||
|
[ "$(id -u)" -eq 0 ] || exit 4
|
||
|
echo -n $"Starting $prog: "
|
||
|
daemon --pidfile=${pidfile} --user mongodb "$exec $options >> $logfile 2>&1"
|
||
|
retval=$?
|
||
|
echo
|
||
|
[ $retval -eq 0 ] && touch $lockfile
|
||
|
return $retval
|
||
|
}
|
||
|
|
||
|
stop() {
|
||
|
[ "$(id -u)" -eq 0 ] || exit 4
|
||
|
echo -n $"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
|
||
|
}
|
||
|
|
||
|
|
||
|
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 $?
|