#! Binbaslif [-z $1]; thenechoUsage: $0 [start | stop | restart] exit1fiSourcethecommonsetupfunctionsforstartupscriptstest-retcrc.common | exit1.etcrc. commonsetupsomedefaultsdbpathusrlocal1_dbdbdblo
#! /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 ults
DBPATH = '/usr/local/mongodb/db'
LOGPATH = '/usr/local/mongodb/log/mongod. Log'
Export d_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 PIDif [ -e $pidfile ]; then pid=`cat $pidfile`fi# If we don't have a PID, check for itif [ "$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 itif [ "$pid" != "" ]; then kill -15 $pidfi
}
RestartService (){
StopService
Sleep 3
StartService
}
RunService $1
Original article address: [Note] Mac OS MongoDB STARTUP script. Thank you for sharing it with me.