mongodb 自动启动
在etc/init.d目录下建立文件mongodb
#!/bin/sh #chkconfig: 2345 93 18 #description:auto_run #MogoDB home directory MONGODB_HOME=/usr/local/mongodb #mongodb command MONGODB_BIN=$MONGODB_HOME/bin/mongod #mongodb config file MONGODB_CONF=$MONGODB_HOME/conf/start.conf #mongodb PID MONGODB_PID=/mongodbdata/mongo.pid #set open file limit SYSTEM_MAXFD=65535 MONGODB_NAME="mongodb" . /etc/rc.d/init.d/functions if [ ! -f $MONGODB_BIN ] then echo "$MONGODB_NAME startup: $MONGODB_BIN not exists! " exit fi start(){ ulimit -HSn $SYSTEM_MAXFD su - mongouser -c "$MONGODB_BIN --config="$MONGODB_CONF" --fork" ##added @20160901 ret=$? if [ $ret -eq 0 ]; then action $"Starting $MONGODB_NAME: " /bin/true else action $"Starting $MONGODB_NAME: " /bin/false fi } stop(){ PID=$(ps aux |grep "$MONGODB_NAME" |grep "$MONGODB_CONF" |grep -v grep |wc -l) if [[ $PID -eq 0 ]];then action $"Stopping $MONGODB_NAME: " /bin/false exit fi kill -HUP `cat $MONGODB_PID` ret=$? if [ $ret -eq 0 ]; then action $"Stopping $MONGODB_NAME: " /bin/true rm -f $MONGODB_PID else action $"Stopping $MONGODB_NAME: " /bin/false fi } restart() { stop sleep 2 start } case "$1" in start) start ;; stop) stop ;; status) status $prog ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart}" esac
完成后 使用 chkconfig mongodb on 设置为生效
然后开机自动启动 su - mongouser 说明使用了mongouser 来启动服务
浙公网安备 33010602011771号