Last active
January 12, 2017 22:04
-
-
Save thattommyhall/971056 to your computer and use it in GitHub Desktop.
Automatically run --repair if necessary when starting MongoDB via Upstart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
limit nofile 20000 20000 | |
kill timeout 300 | |
env MONGO_DATA=/var/lib/mongodb/ | |
env MONGO_LOGS=/var/log/mongodb/ | |
env MONGO_EXE=/usr/bin/mongod | |
env MONGO_CONF=/etc/mongodb.conf | |
pre-start script | |
mkdir -p $MONGO_DATA | |
mkdir -p $MONGO_LOGS | |
if [ -f $MONGO_DATA/mongod.lock ]; then | |
mongo_pid=`cat $MONGO_DATA/mongod.lock` | |
if [ ! -z $mongo_pid ]; then | |
if [ ! `pgrep mongo | grep "$mongo_pid" | wc -l` -gt 0 ]; then | |
rm $MONGO_DATA/mongod.lock | |
sudo -u mongodb /usr/bin/mongod --config /etc/mongodb.conf --repair | |
touch $MONGO_DATA/repaired-`date "+%Y%m%d-%H%M%S"` | |
fi | |
fi | |
fi | |
end script | |
start on runlevel [2345] | |
stop on runlevel [06] | |
script | |
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi | |
exec start-stop-daemon --start --quiet --chuid mongodb --exec $MONGO_EXE -- --config $MONGO_CONF | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment