-
-
Save soomtong/fb352256b75a7373167f to your computer and use it in GitHub Desktop.
mongo db manage script use /usr/local/bin/mdb with excution flag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ -z $1 ] ; then | |
| echo "Usage: $0 [start|stop|restart] " | |
| exit 1 | |
| fi | |
| # Source the common setup functions for startup scripts | |
| test -r /etc/rc.common || exit 1 | |
| . /etc/rc.common | |
| # Set up some defaults | |
| DBPATH='/usr/local/var/mongodb' | |
| LOGPATH='/usr/local/var/log/mongodb/mongod.log' | |
| MONGOD_PORT=27017 | |
| StartService(){ | |
| /usr/local/bin/mongod run --dbpath=$DBPATH --logpath=$LOGPATH --port $MONGOD_PORT > /dev/null 2>&1 & | |
| } | |
| StopService() { | |
| pidfile=$DBPATH/mongod.lock | |
| # If the lockfile exists, it contains the PID | |
| if [ -e $pidfile ]; then | |
| pid=`cat $pidfile` | |
| fi | |
| # If we don't have a PID, check for it | |
| if [ "$pid" == "" ]; then | |
| pid=`/usr/sbin/lsof -i tcp:$MONGOD_PORT | tail -1 | awk '{print $2}'` | |
| fi | |
| # If we've found a PID, let's kill it | |
| if [ "$pid" != "" ]; then | |
| kill -15 $pid | |
| fi | |
| } | |
| RestartService() { | |
| StopService | |
| sleep 3 | |
| StartService | |
| } | |
| RunService $1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment