>  기사  >  데이터 베이스  >  [Note]Mac OS MongoDB 启动脚本

[Note]Mac OS MongoDB 启动脚本

WBOY
WBOY원래의
2016-06-07 16:30:541039검색

#!/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/mongodb/db' LO

#!/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/mongodb/db'
LOGPATH='/usr/local/mongodb/log/mongod.log'
MONGOD_PORT=27017

StartService(){
/usr/local/mongodb/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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.