Skip to content

Instantly share code, notes, and snippets.

@christiannelson
Created January 26, 2011 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannelson/796189 to your computer and use it in GitHub Desktop.
Save christiannelson/796189 to your computer and use it in GitHub Desktop.
MongoDB init.d startup script
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mongodb
# Description: mongodb
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/mongodb/bin/mongod
NAME=mongodb
DESC=mongodb
PIDFILE=/var/run/mongodb.pid
test -x $DAEMON || exit 0
test -x $DAEMONBOOTSTRAP || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
touch $PIDFILE
chown mongodb:mongodb $PIDFILE
if start-stop-daemon --start --background --quiet --umask 007 --chuid mongodb:mongodb --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- -f /etc/mongodb.conf
then
echo "$NAME."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if start-stop-daemon --stop --retry 10/TERM/10/TERM/10/KILL --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
then
echo "$NAME."
else
echo "failed"
fi
rm -f $PIDFILE
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment