summaryrefslogtreecommitdiff
path: root/rpm
diff options
context:
space:
mode:
authorAlexis Midon <alexismidon@gmail.com>2013-04-03 17:01:28 -0400
committerBenety Goh <benety@mongodb.com>2014-08-20 12:06:34 -0400
commitfb1e82a243bc7c2b96ea1cfa78370f08a4c59bc6 (patch)
treee5a4d4cce7a03e6416b3236b61296184b7fc68b8 /rpm
parent8f9c2e19ae3131e1aebb64d8ab46ac9bb4a5eae3 (diff)
downloadmongo-fb1e82a243bc7c2b96ea1cfa78370f08a4c59bc6.tar.gz
SERVER-9253 fixed init.d/mongod so that it does not sleep for 5 minutes unnecessarily.
In some version of Linux, killproc() provided in /etc/init.d/functions has a bug where it will sleep the full duration of the delay (-d). Closes #411 Signed-off-by: Benety Goh <benety@mongodb.com>
Diffstat (limited to 'rpm')
-rwxr-xr-x[-rw-r--r--]rpm/init.d-mongod33
1 files changed, 32 insertions, 1 deletions
diff --git a/rpm/init.d-mongod b/rpm/init.d-mongod
index 3d27fc8f29e..824ff68f164 100644..100755
--- a/rpm/init.d-mongod
+++ b/rpm/init.d-mongod
@@ -72,7 +72,7 @@ start()
stop()
{
echo -n $"Stopping mongod: "
- killproc -p "$PIDFILEPATH" -d 300 /usr/bin/mongod
+ mongo_killproc $mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
@@ -83,6 +83,37 @@ restart () {
start
}
+# 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()
+{
+ local procname=$1
+ local -i delay=300
+ local -i duration=10
+ local pid=`pidofproc -p "$PIDFILEPATH" $procname`
+
+ 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
+
+ rm -f "$PIDFILEPATH"
+
+ checkpid $pid
+ local RC=$?
+ [ "$RC" -eq 0 ] && failure "${procname} shutdown" || success "${procname} shutdown"
+ RC=$((! $RC))
+ return $RC
+}
RETVAL=0