Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /bin/sh
# start / stop script for mongodb
### BEGIN INIT INFO
# Provides: mongod
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start mongod at boot time
# Description: Enable service provided by mongod.
### END INIT INFO
# Source function library.
. /lib/lsb/init-functions
retval=0
pidfile=/var/run/mongodb.pid
exec="/opt/mongodb/bin/mongod"
prog="mongod"
config="/etc/mongodb/mongodb.conf"
lockfile="/var/lock/mongod"
mongo_user="mongod"
#[ -e $config ] && . $config
start() {
if [ ! -x $exec ]
then
echo $exec not found
exit 5
fi
log_daemon_msg "Starting mongoDB daemon"
log_progress_msg $prog
start-stop-daemon --start --pidfile $pidfile -m -c $mongo_user \
--exec $exec -- -f $config > /dev/null 2>&1 &
retval=$?
if [ $retval -eq 0 ]
then
log_end_msg 0
else
log_end_msg 1
fi
return $retval
}
stop() {
log_daemon_msg "Stopping mongoDB daemon"
log_progress_msg $prog
start-stop-daemon --stop --pidfile $pidfile --retry 10 \
--exec $exec
retval=$?
if [ $retval -eq 0 ] && rm -f $lockfile
then
log_end_msg 0
else
log_end_msg 1
fi
rm -f $pidfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
# See how we were called.
case "$1" in
start)
$1
;;
stop)
$1
;;
restart)
$1
;;
reload)
$1
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload}"
exit 2
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment