Why is --pidfilepath useful for mongod?

329 views
Skip to first unread message

Arkadiy

unread,
Nov 19, 2013, 3:54:25 PM11/19/13
to mongod...@googlegroups.com
mongod process already writes its pid to the lockfile, why is a separate pidfile needed? Is there any reason why giving e.g. start-stop-daemon the lockfile as --pidfile is not desirable?

陆峰

unread,
Nov 19, 2013, 9:37:32 PM11/19/13
to mongod...@googlegroups.com
one reason I think is that you can put u MongoDB into /var/run directory and allows someone to write a script really easy to check if it is running and issue a plain kill command if one wants to end it. especially in distributed environment. 

在 2013年11月20日星期三UTC+8上午4时54分25秒,Arkadiy写道:

Arkadiy

unread,
Nov 19, 2013, 9:49:33 PM11/19/13
to mongod...@googlegroups.com
But I can also check the mongod.lock file in the data dir (instead of /var/run) and stop it the same way, for example with 

start-stop-daemon --background --stop --pidfile /path/to/mongod.lock

You still need one lockfile per mongo process, etc.

I guess this could be useful if you had a standardized process manager/watchdog tool that would expect pids to live in /var/run, or didn't have access to the data dir?

陆峰

unread,
Nov 19, 2013, 9:58:47 PM11/19/13
to mongod...@googlegroups.com
yes, u are right, I check the mongodb start script in Centos /etc/init.d/mongodb

start() {
        checkpath
-d -m 0750 -o "${MONGODB_USER}":mongodb "${MONGODB_RUN}"


       
# Listen to MONGODB_IP if configured
       
[ -z "${MONGODB_IP}" ] || MONGODB_OPTIONS="--bind_ip ${MONGODB_IP} ${MONGODB_OPTIONS}"


       
# Baselayout-1 user should use --chuid instead of --user
       
local USEROPT="--user"
       
if [ ! -f /etc/init.d/sysfs ]; then
                USEROPT
="--chuid"
       
fi


        ebegin
"Starting ${SVCNAME}"
        start
-stop-daemon --background --start --make-pidfile \
               
--pidfile ${MONGODB_RUN:-/var/run/mongodb}/${SVCNAME}.pid \
                $
{USEROPT} ${MONGODB_USER:-mongodb} \
               
--exec ${MONGODB_EXEC:-/usr/bin/mongod} \
               
-- \
               
--port ${MONGODB_PORT:-27017} \
               
--dbpath ${MONGODB_DATA:-/var/lib/mongodb} \
               
--unixSocketPrefix ${MONGODB_RUN:-/var/run/mongodb} \
               
--logappend --logpath /var/log/mongodb/${SVCNAME}.log \
                $
{MONGODB_OPTIONS}
        eend $
?
}


stop
() {
        ebegin
"Stopping ${SVCNAME}"
        start
-stop-daemon --stop --pidfile ${MONGODB_RUN:-/var/run/mongodb}/${SVCNAME}.pid
        eend $
?
}

it put all pid file input /var/run/mongodb

another reason is that if run many MonogDB daemons in one machine, you can put all pid into /var/run/mongodb, it is very easy for manage. 

在 2013年11月20日星期三UTC+8上午10时49分33秒,Arkadiy写道:

Arkadiy

unread,
Nov 20, 2013, 4:39:59 PM11/20/13
to mongod...@googlegroups.com
The difference here is that the pidfile is generated by start-stop-daemon ( start-stop-daemon --background --start --make-pidfile ) and not by mongodb itself (--pidfilepath isn't passed). It seems you can use either approach to make the file (though not both together)

I'm asking because of an issue I encountered with a puppet deployment module here:

Reply all
Reply to author
Forward
0 new messages