MongoDB rc.d script fails when authentication is required

Solution Verified - Updated -

Issue

the MongoDb rc.d script relies on the mongostat tool to check whether the daemon starts up, but does not support authentication. This is the offending code inside /etc/init.d/mongod:

rh_status() {
    local p a
    # run checks to determine if the service is running or use generic status
    status -p ${pidfile} $prog

    # Grab address
    a=$(grep '^[[:space:]]*bind_ip' $configfile)
    a=$(_trim "$a")
    [ -z "$a" || "$a" = "0.0.0.0" ] && a=127.0.0.1

    # Grab port
    p=$(grep '^[[:space:]]*port' $configfile)
    p=$(_trim "$p")
    [ -z "$p" ] && p=27017

    netstat -ln | grep -q "$a:$p"
    [ $? -eq 0 ] || return 1

    echo "listening on $a:$p"

    # Check db
    mongostat -n 1 -h $a --port $p &> /dev/null
    [ $? -ne 0 ] && return 1

    echo "connection test successful"
}

The problem lies in the call to mongostat.

Environment

  • Red Hat Enterprise Linux OpenStack Platform 4.0 (Havana) for RHEL 6.
  • mongodb version before mongodb-2.4.6-8.el6ost.

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content