Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Created August 15, 2015 05:41
Show Gist options
  • Save bertrandmartel/a3865fa441248f23d51e to your computer and use it in GitHub Desktop.
Save bertrandmartel/a3865fa441248f23d51e to your computer and use it in GitHub Desktop.
mongod service init.d launcher script
#!/bin/sh
#title :mongod
#author :Bertrand Martel
#date :15/08/2015
#description :start/stop/restart mongod
#########################################
### install : cp mongod /etc/init.d/
# update-rc.d mongod defaults
### uninstall : update-rc.d -f mongodb remove
PATH_TO_MONGO=/usr/bin/mongod
#file containing all mongodb pid
PID_FILE=/tmp/mongodb.pid
case "$1" in
start)
echo "Starting mongodb service..."
COMMAND_TO_RUN=`start-stop-daemon -S -b -m -p $PID_FILE -x $PATH_TO_MONGO& :`
setsid sh -c $COMMAND_TO_RUN> /dev/null 2>&1 < /dev/null
echo -e "\E[31;33m[ OK ]\E[0m"
;;
stop)
echo "Stopping mongodb service..."
start-stop-daemon -K -q -p $PID_FILE
echo -e "\E[31;33m[ OK ]\E[0m"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment