Skip to content

Instantly share code, notes, and snippets.

@andersab
Last active December 11, 2015 18:48
Show Gist options
  • Select an option

  • Save andersab/4644215 to your computer and use it in GitHub Desktop.

Select an option

Save andersab/4644215 to your computer and use it in GitHub Desktop.
Packaging and Deploying / Managing Mongodb Process
#! /bin/bash
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon
### END INIT INFO
USER=mongouser
PATH=/opt/mongodb/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt//mongodb/bin/mongod
PIDFILE=/opt/mongodb/mongod.pid
LOGFILE=/opt/mongodb/mongod.log
CONFIGFILE=/opt//mongodb/mongod.conf
NAME=mongodb
DESC=mongodb
MONGO_OPT="--fork --config $CONFIGFILE --pidfilepath $PIDFILE"
. /etc/rc.status
test -x $DAEMON || exit 0
#set -e
rc_reset
case "$1" in
start)
echo -n "Starting $DESC: "
startproc -u $USER -p $PIDFILE $DAEMON $MONGO_OPT >> $LOGFILE&
rc_status -v
echo "$DESC Started."
;;
stop)
echo -n "Stopping $DESC: "
killproc -TERM $DAEMON
echo "$NAME."
rc_status -v
;;
status)
echo -n "Status for $DESC: "
checkproc -p $PIDFILE $DAEMON
rc_status -v
;;
restart|force-reload)
echo -n "Restarting $DESC: "
$0 stop
$0 start
echo -n "Restarted $DESC."
rc_status
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
fork = true
bind_ip = 127.0.0.1
port = 27017
quiet = true
dbpath = /var/mongodb/db
logpath = /var/mongodb/mongod.log
logappend = true
journal = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment