Skip to content

Instantly share code, notes, and snippets.

@fccoelho
Forked from onedesign/mongodb-upstart.sh
Created March 8, 2012 13:45
Show Gist options
  • Save fccoelho/2001039 to your computer and use it in GitHub Desktop.
Save fccoelho/2001039 to your computer and use it in GitHub Desktop.
Ubuntu upstart script for MongoDB with automatic repair
# Ubuntu upstart file at /etc/init/mongodb.conf
pre-start script
mkdir -p /var/lib/mongodb/
mkdir -p /var/log/mongodb/
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then
if [ -f /var/lib/mongodb/mongod.lock ]; then
rm /var/lib/mongodb/mongod.lock
sudo -u mongodb $(which mongod) --config /etc/mongodb.conf --repair
fi
exec start-stop-daemon --start --quiet --chuid mongodb --exec $(which mongod) -- --config /etc/mongodb.conf
fi
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment