mongod, configsvr, and mongos init.d and .conf files
mongos
/etc/mongos.conf
#mongos config file #config servers configdb=host1:27019,host2:27019,host3:27019 #where to log logpath=/var/log/mongo/mongos.log #log overwritten or appended to logappend=true #fork and run in background fork=true #override port port=27017
/etc/init.d/mongos
source: https://github.com/ClarityServices/mongo/blob/ed56c993214ac80065788444d3e8a30a9763d63a/rpm/mongos.conf
#!/bin/bash # mongos - Startup script for mongos # chkconfig: 35 85 15 # description: Mongo Router Process for sharding # processname: mongos # config: /etc/mongos.conf # pidfile: /var/run/mongo/mongos.pid . /etc/rc.d/init.d/functions # mongos will read mongos.conf for configuration settings # Add variable to support multiple instances of mongos # The instance name is by default the name of this init script # In this way another instance can be created by just copying this init script # and creating a config file with the same name and a .conf extension # For Example: # /etc/init.d/mongos2 # /etc/mongos2.conf # Optionally also create a sysconfig file to override env variables below # /etc/sysconfig/mongos2 INSTANCE=`basename $0` # By default OPTIONS just points to the /etc/mongod.conf config file # This can be overriden in /etc/sysconfig/mongod OPTIONS=" -f /etc/${INSTANCE}.conf" PID_PATH=/var/run/mongo PID_FILE=${PID_PATH}/${INSTANCE}.pid MONGO_BIN=/usr/bin/mongos MONGO_USER=mongod MONGO_GROUP=mongod MONGO_ULIMIT=12000 MONGO_LOCK_FILE=/var/lock/subsys/${INSTANCE} # Source sysconfig options so that above values can be overriden SYSCONFIG="/etc/sysconfig/${INSTANCE}" if [ -f "$SYSCONFIG" ]; then . "$SYSCONFIG" || true fi # Create mongo pids path if it does not exist if [ ! -d "${PID_PATH}" ]; then mkdir -p "${PID_PATH}" chown "${MONGO_USER}:${MONGO_GROUP}" "${PID_PATH}" fi start() { echo -n $"Starting ${INSTANCE}: " daemon --user "$MONGO_USER" --pidfile $PID_FILE $MONGO_BIN $OPTIONS --pidfilepath=$PID_FILE RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $MONGO_LOCK_FILE return $RETVAL } stop() { echo -n $"Stopping ${INSTANCE}: " killproc -p $PID_FILE -t30 -TERM $MONGO_BIN RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $MONGO_LOCK_FILE [ $RETVAL -eq 0 ] && rm -f $PID_FILE return $RETVAL } restart () { stop start } ulimit -n $MONGO_ULIMIT RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f $MONGO_LOCK_FILE ] && restart || : ;; status) status -p $PID_FILE $MONGO_BIN RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL
EDIT: The previous /etc/init.d/mongos script would not start my mongos process on boot in RHEL 6.1. I wrote a simpler script below that seems to do the trick. It doesn't allow for multiple instances however. I think the previous script was failing due to the extra directory creation and sysconfig checks. Be sure to:
sudo touch /etc/sysconfig/mongos sudo touch /var/log/mongo/mongos.log
new /etc/init.d/mongos
#!/bin/bash # mongos - Startup script for mongos # chkconfig: 35 85 15 # description: Mongo Router Process for sharding # processname: mongos # config: /etc/mongos.conf # pidfile: /var/run/mongo/mongos.pid . /etc/rc.d/init.d/functions # mongos will read mongos.conf for configuration settings # NOTE: if you change any OPTIONS here, you get what you pay for: # this script assumes all options are in the config file. CONFIGFILE="/etc/mongos.conf" OPTIONS=" -f $CONFIGFILE" SYSCONFIG="/etc/sysconfig/mongos" PID_PATH=/var/run/mongo PID_FILE=${PID_PATH}/mongos.pid MONGO_BIN=/usr/bin/mongos MONGO_ULIMIT=12000 MONGO_LOCK_FILE=/var/lock/subsys/mongos MONGO_USER=mongod MONGO_GROUP=mongod . "$SYSCONFIG" || true start() { echo -n $"Starting mongos: " daemon --user "$MONGO_USER" --pidfile $PID_FILE $MONGO_BIN $OPTIONS --pidfilepath=$PID_FILE RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $MONGO_LOCK_FILE } stop() { echo -n $"Stopping mongos: " killproc -p $PID_FILE -t30 -TERM $MONGO_BIN RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $MONGO_LOCK_FILE [ $RETVAL -eq 0 ] && rm -f $PID_FILE } restart () { stop start } ulimit -n $MONGO_ULIMIT RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f $MONGO_LOCK_FILE ] && restart || : ;; status) status -p $PID_FILE $MONGO_BIN RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL
mongod
/etc/mongod.conf
#mongod config file #replica set replSet=replA #start mongod in shardsvr mode shardsvr=true #where to log logpath=/var/log/mongo/mongod.log #log overwritten or appended to logappend=true #fork and run in background fork=true #override port port=27018 #path to data files dbpath=/ebs/mongo
/etc/init.d/mongod
#!/bin/bash # mongod - Startup script for mongod # chkconfig: 35 85 15 # description: Mongo is a scalable, document-oriented database. # processname: mongod # config: /etc/mongod.conf # pidfile: /var/run/mongo/mongo.pid . /etc/rc.d/init.d/functions # things from mongod.conf get there by mongod reading it # NOTE: if you change any OPTIONS here, you get what you pay for: # this script assumes all options are in the config file. CONFIGFILE="/etc/mongod.conf" OPTIONS=" -f $CONFIGFILE" SYSCONFIG="/etc/sysconfig/mongod" # FIXME: 1.9.x has a --shutdown flag that parses the config file and # shuts down the correct running pid, but that's unavailable in 1.8 # for now. This can go away when this script stops supporting 1.8. DBPATH=`awk -F= '/^dbpath=/{print $2}' "$CONFIGFILE"` mongod=${MONGOD-/usr/bin/mongod} MONGO_USER=mongod MONGO_GROUP=mongod . "$SYSCONFIG" || true start() { echo -n $"Starting mongod: " daemon --user "$MONGO_USER" $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod } stop() { echo -n $"Stopping mongod: " killproc -p "$DBPATH"/mongod.lock -t30 -TERM /usr/bin/mongod RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod } restart () { stop start } ulimit -n 12000 RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f /var/lock/subsys/mongod ] && restart || : ;; status) status $mongod RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL
configsvr
/etc/mongod.conf
#configsvr config file #start mongod in configsvr mode configsvr=true #where to log logpath=/var/log/mongo/mongod.log #log overwritten or appended to logappend=true #fork and run in background fork=true #override port port=27019 #path to data files dbpath=/ebs/mongo
/etc/init.d/mongod
#!/bin/bash # mongod - Startup script for mongod # chkconfig: 35 85 15 # description: Mongo is a scalable, document-oriented database. # processname: mongod # config: /etc/mongod.conf # pidfile: /var/run/mongo/mongo.pid . /etc/rc.d/init.d/functions # things from mongod.conf get there by mongod reading it # NOTE: if you change any OPTIONS here, you get what you pay for: # this script assumes all options are in the config file. CONFIGFILE="/etc/mongod.conf" OPTIONS=" -f $CONFIGFILE" SYSCONFIG="/etc/sysconfig/mongod" # FIXME: 1.9.x has a --shutdown flag that parses the config file and # shuts down the correct running pid, but that's unavailable in 1.8 # for now. This can go away when this script stops supporting 1.8. DBPATH=`awk -F= '/^dbpath=/{print $2}' "$CONFIGFILE"` mongod=${MONGOD-/usr/bin/mongod} MONGO_USER=mongod MONGO_GROUP=mongod . "$SYSCONFIG" || true start() { echo -n $"Starting mongod: " daemon --user "$MONGO_USER" $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod } stop() { echo -n $"Stopping mongod: " killproc -p "$DBPATH"/mongod.lock -t30 -TERM /usr/bin/mongod RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod } restart () { stop start } ulimit -n 12000 RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f /var/lock/subsys/mongod ] && restart || : ;; status) status $mongod RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL
mongod arbiter
/etc/mongod.conf
#arbiter config file #replica set replSet=replA #start mongod in shardsvr mode shardsvr=true #where to log logpath=/var/log/mongo/mongod.log #log overwritten or appended to logappend=true #fork and run in background fork=true #override port port=27018 #path to data files dbpath=/var/lib/mongo #set oplog size oplogSize=1
/etc/init.d/mongod
#!/bin/bash # mongod - Startup script for mongod # chkconfig: 35 85 15 # description: Mongo is a scalable, document-oriented database. # processname: mongod # config: /etc/mongod.conf # pidfile: /var/run/mongo/mongo.pid . /etc/rc.d/init.d/functions # things from mongod.conf get there by mongod reading it # NOTE: if you change any OPTIONS here, you get what you pay for: # this script assumes all options are in the config file. CONFIGFILE="/etc/mongod.conf" OPTIONS=" -f $CONFIGFILE" SYSCONFIG="/etc/sysconfig/mongod" # FIXME: 1.9.x has a --shutdown flag that parses the config file and # shuts down the correct running pid, but that's unavailable in 1.8 # for now. This can go away when this script stops supporting 1.8. DBPATH=`awk -F= '/^dbpath=/{print $2}' "$CONFIGFILE"` mongod=${MONGOD-/usr/bin/mongod} MONGO_USER=mongod MONGO_GROUP=mongod . "$SYSCONFIG" || true start() { echo -n $"Starting mongod: " daemon --user "$MONGO_USER" $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod } stop() { echo -n $"Stopping mongod: " killproc -p "$DBPATH"/mongod.lock -t30 -TERM /usr/bin/mongod RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod } restart () { stop start } ulimit -n 12000 RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f /var/lock/subsys/mongod ] && restart || : ;; status) status $mongod RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL











