2009-12-03 20:20:35 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# mongod - Startup script for mongod
|
|
|
|
|
|
|
|
# chkconfig: 35 85 15
|
|
|
|
# description: Mongo is a scalable, document-oriented database.
|
|
|
|
# processname: mongod
|
|
|
|
# config: /etc/mongod.conf
|
2013-10-05 01:08:27 +02:00
|
|
|
# pidfile: /var/run/mongodb/mongod.pid
|
2009-12-03 20:20:35 +01:00
|
|
|
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
|
|
|
# things from mongod.conf get there by mongod reading it
|
|
|
|
|
2010-03-16 15:05:32 +01:00
|
|
|
|
2011-06-23 23:41:14 +02:00
|
|
|
# NOTE: if you change any OPTIONS here, you get what you pay for:
|
|
|
|
# this script assumes all options are in the config file.
|
|
|
|
CONFIGFILE="/etc/mongod.conf"
|
|
|
|
OPTIONS=" -f $CONFIGFILE"
|
2010-03-16 15:05:32 +01:00
|
|
|
SYSCONFIG="/etc/sysconfig/mongod"
|
2009-12-03 20:20:35 +01:00
|
|
|
|
2014-05-09 22:29:57 +02:00
|
|
|
DBPATH=`awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*dbpath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d '[:blank:]'`
|
|
|
|
PIDFILEPATH=`awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d '[:blank:]'`
|
2014-07-25 12:09:58 +02:00
|
|
|
PIDDIR=`dirname $PIDFILEPATH`
|
2014-05-09 22:29:57 +02:00
|
|
|
|
2009-12-03 20:20:35 +01:00
|
|
|
mongod=${MONGOD-/usr/bin/mongod}
|
2010-03-16 15:05:32 +01:00
|
|
|
|
2014-03-04 19:00:11 +01:00
|
|
|
MONGO_USER=mongod
|
|
|
|
MONGO_GROUP=mongod
|
2010-03-16 15:05:32 +01:00
|
|
|
|
2012-02-28 18:10:49 +01:00
|
|
|
if [ -f "$SYSCONFIG" ]; then
|
|
|
|
. "$SYSCONFIG"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Handle NUMA access to CPUs (SERVER-3574)
|
|
|
|
# This verifies the existence of numactl as well as testing that the command works
|
|
|
|
NUMACTL_ARGS="--interleave=all"
|
|
|
|
if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
|
|
|
|
then
|
|
|
|
NUMACTL="numactl $NUMACTL_ARGS"
|
|
|
|
else
|
|
|
|
NUMACTL=""
|
|
|
|
fi
|
2009-12-03 20:20:35 +01:00
|
|
|
|
|
|
|
start()
|
|
|
|
{
|
2014-07-25 12:09:58 +02:00
|
|
|
# Make sure the default pidfile directory exists
|
|
|
|
if [ ! -d $PIDDIR ]; then
|
|
|
|
install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR
|
|
|
|
fi
|
|
|
|
|
2013-11-07 00:25:39 +01:00
|
|
|
# Recommended ulimit values for mongod or mongos
|
|
|
|
# See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
|
|
|
|
#
|
|
|
|
ulimit -f unlimited
|
|
|
|
ulimit -t unlimited
|
|
|
|
ulimit -v unlimited
|
|
|
|
ulimit -n 64000
|
|
|
|
ulimit -m unlimited
|
|
|
|
ulimit -u 32000
|
|
|
|
|
2009-12-03 20:20:35 +01:00
|
|
|
echo -n $"Starting mongod: "
|
2013-12-11 20:24:00 +01:00
|
|
|
daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
|
2009-12-03 20:20:35 +01:00
|
|
|
RETVAL=$?
|
2010-06-01 22:08:47 +02:00
|
|
|
echo
|
|
|
|
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
|
2009-12-03 20:20:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
|
|
|
echo -n $"Stopping mongod: "
|
2014-08-20 21:09:46 +02:00
|
|
|
mongo_killproc "$PIDFILEPATH" $mongod
|
2010-03-16 15:05:32 +01:00
|
|
|
RETVAL=$?
|
2010-06-01 22:08:47 +02:00
|
|
|
echo
|
|
|
|
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
|
2010-03-16 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
restart () {
|
|
|
|
stop
|
|
|
|
start
|
2009-12-03 20:20:35 +01:00
|
|
|
}
|
|
|
|
|
2013-04-03 23:01:28 +02:00
|
|
|
# Send TERM signal to process and wait up to 300 seconds for process to go away.
|
|
|
|
# If process is still alive after 300 seconds, send KILL signal.
|
|
|
|
# Built-in killproc() (found in /etc/init.d/functions) is on certain versions of Linux
|
|
|
|
# where it sleeps for the full $delay seconds if process does not respond fast enough to
|
|
|
|
# the initial TERM signal.
|
|
|
|
mongo_killproc()
|
|
|
|
{
|
2014-08-20 21:09:46 +02:00
|
|
|
local pid_file=$1
|
|
|
|
local procname=$2
|
2013-04-03 23:01:28 +02:00
|
|
|
local -i delay=300
|
|
|
|
local -i duration=10
|
2014-08-20 21:09:46 +02:00
|
|
|
local pid=`pidofproc -p "${pid_file}" ${procname}`
|
2013-04-03 23:01:28 +02:00
|
|
|
|
|
|
|
kill -TERM $pid >/dev/null 2>&1
|
|
|
|
usleep 100000
|
|
|
|
local -i x=0
|
|
|
|
while [ $x -le $delay ] && checkpid $pid; do
|
|
|
|
sleep $duration
|
|
|
|
x=$(( $x + $duration))
|
|
|
|
done
|
|
|
|
|
|
|
|
kill -KILL $pid >/dev/null 2>&1
|
|
|
|
usleep 100000
|
|
|
|
|
2014-08-20 21:09:46 +02:00
|
|
|
rm -f "${pid_file}"
|
2013-04-03 23:01:28 +02:00
|
|
|
|
|
|
|
checkpid $pid
|
|
|
|
local RC=$?
|
|
|
|
[ "$RC" -eq 0 ] && failure "${procname} shutdown" || success "${procname} shutdown"
|
|
|
|
RC=$((! $RC))
|
|
|
|
return $RC
|
|
|
|
}
|
2013-11-07 00:25:39 +01:00
|
|
|
|
2009-12-03 20:20:35 +01:00
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
2010-03-16 15:05:32 +01:00
|
|
|
restart|reload|force-reload)
|
|
|
|
restart
|
|
|
|
;;
|
|
|
|
condrestart)
|
2010-12-15 19:23:11 +01:00
|
|
|
[ -f /var/lock/subsys/mongod ] && restart || :
|
2010-03-16 15:05:32 +01:00
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status $mongod
|
2010-10-26 22:31:32 +02:00
|
|
|
RETVAL=$?
|
2009-12-03 20:20:35 +01:00
|
|
|
;;
|
|
|
|
*)
|
2010-03-16 15:05:32 +01:00
|
|
|
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
|
2009-12-03 20:20:35 +01:00
|
|
|
RETVAL=1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|