Mongodb database adding System Service tutorial, mongodb System Service

Source: Internet
Author: User

Mongodb database adding System Service tutorial, mongodb System Service
1. Create the mongod file in the/etc/init. d directory and grant the correct permissions:

root@ubuntu:/etc/init.d# touch mongodroot@ubuntu:/etc/init.d# chmod 755 mongod
2. Edit the mongod File
#!/bin/sh### BEGIN INIT INFO# Provides:     mongod# Required-Start:   $local_fs $syslog# Required-Stop:    $local_fs $syslog# Default-Start:    2 3 4 5# Default-Stop:     # Short-Description:   mongodb service### END INIT INFOstart_mongodb() {    ps -ef | grep -v "grep" | grep "/usr/local/mongodb/bin/mongod"    if [ $? -eq 0 ];then        echo "mongodb is in running!"        return 0    fi    /usr/local/mongodb/bin/mongod --auth &}stop_mongodb(){    /usr/local/mongodb/bin/mongod --shutdown    if [ $? -eq 0 ];then        echo "stop mongodb service successfully!"    else        echo "stop mongodb service failed!"    fi}query_status(){    ps -ef | grep -v "grep" | grep "/usr/local/mongodb/bin/mongod"    if [ $? -eq 0 ];then        echo "mongodb is in running!"    else        echo "mongodb is not in running!"    fi}case "$1" in    start)        start_mongodb        ;;    stop)        stop_mongodb        ;;    restart)        stop_mongodb        start_mongodb        ;;    status)        query_status        ;;    *)        echo "usage: service mongodb start|stop|restart|status"        ;;esacexit 0
3. Add to System Service
root@ubuntu:/etc/init.d# update-rc.d mongod defaults

You can use the command to manage the mongod service.

root@ubuntu:/etc/init.d# service mongod start

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.