MongoDB [Note] Mac OS MongoDB 启动脚本

匿名 · 2013年07月08日 · 最后由 huacnlee 回复于 2013年07月25日 · 3397 次阅读

#!/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

Are you joking? why not use launchctl

不是已经有 mongodb mac 的启动插件了么。为何还要写脚本。。

#1 楼 @xds2000 他是在练习写启动脚本 哈哈

用 Homebrew 安装,一切搞定

需要 登录 后方可回复, 如果你还没有账号请 注册新账号