--fork not returning

154 views
Skip to first unread message

Dan Yamins

unread,
Aug 4, 2010, 11:16:03 AM8/4/10
to mongod...@googlegroups.com
In a somewhat older version of mongo, the --fork option caused the mongodb command to return, e.g.:

# mongod --fork --logfile /path/to/my/logfile
forked process: 4018
all output going to : /path/to/my/logfile
#

But now, when I use the repo version, the --fork command fails to return:

# mongod --fork --logfile /path/to/my/logfile
forked process: 4018
all output going to : /path/to/my/logfile
** NOTE: This is a development version (1.5.9-pre-) of MongoDB.
**       Not recommended for production.
[waits here for user input]

Perhaps this has to do with the printing of the "NOTE" ... anyway, this obvious the point of using the fork option for me, which is that I need to have an automated process start mongo over a remote connection and then complete.     Is there some way to resolve this easily? 

Thanks,
Dan


Dan Yamins

unread,
Aug 4, 2010, 11:20:02 AM8/4/10
to mongod...@googlegroups.com
Sorry ... in the below question, I meant "--logpath" instead of "--logfile"
Dan

Eliot Horowitz

unread,
Aug 4, 2010, 11:21:20 AM8/4/10
to mongod...@googlegroups.com
What OS?
Seems to be working for me on linux&mac

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>

Dan Yamins

unread,
Aug 4, 2010, 11:41:27 AM8/4/10
to mongod...@googlegroups.com
On Wed, Aug 4, 2010 at 11:21 AM, Eliot Horowitz <elioth...@gmail.com> wrote:
What OS?
Seems to be working for me on linux&mac

ubuntu karmic

 

Eliot Horowitz

unread,
Aug 4, 2010, 11:42:43 AM8/4/10
to mongod...@googlegroups.com
On ubuntu as well.

After the NOTE screen - you have to hit enter to get a prompt - did
you try that?

Dan Yamins

unread,
Aug 4, 2010, 11:44:23 AM8/4/10
to mongod...@googlegroups.com
On Wed, Aug 4, 2010 at 11:42 AM, Eliot Horowitz <elioth...@gmail.com> wrote:
On ubuntu as well.

After the NOTE screen - you have to hit enter to get a prompt - did
you try that?


Sorry, I should have been more clear. it's not that the process fails to start mongo.  The DB is started, and if I press enter the process returns.   It's just that this step of having to press a key IS the problem ... and before (e.g. mongo 1.2) when I used "fork", I did not have to press enter.   

 

Kristina Chodorow

unread,
Aug 4, 2010, 11:47:01 AM8/4/10
to mongod...@googlegroups.com
That's just a shell thing, a script won't have a problem with it.

Richard Kreuter

unread,
Aug 4, 2010, 11:49:06 AM8/4/10
to mongod...@googlegroups.com
There's no mongod process waiting for input, it's just that the Unixy
division of labor between the terminal and the shell doesn't allow the
shell to redisplay its prompt when some async process writes to the
terminal. Cf.

$ (sleep 5; echo "foo") &
[1] 14533
$ foo

--
Richard

Dan Yamins

unread,
Aug 4, 2010, 1:35:42 PM8/4/10
to mongod...@googlegroups.com
On Wed, Aug 4, 2010 at 11:47 AM, Kristina Chodorow <kris...@10gen.com> wrote:
That's just a shell thing, a script won't have a problem with it.


That's what I figured too ... but none of the scripts I wrote seem to solve the problem.

for instance:

######file mongo-start.sh####
#!/bin/sh
/usr/bin/mongod --config=/home/mongo/conf --fork --logpath /home/mongo/logfile &
#####end file


Running ./mongo-start.sh prodcues exactly the same result ....   Sorry for being so ignorant, but what should I put in the script so that upon execution it does not require any further input in the terminal?   Ideally it would also still print to the screen the message that it currently does. 

Thanks,
Dan


 

Richard Kreuter

unread,
Aug 4, 2010, 1:51:54 PM8/4/10
to mongod...@googlegroups.com
Dan Yamins writes:
> On Wed, Aug 4, 2010 at 11:47 AM, Kristina Chodorow <kris...@10gen.com>wrote:
>
> > That's just a shell thing, a script won't have a problem with it.
> >
> >
> That's what I figured too ... but none of the scripts I wrote seem to solve
> the problem.
>
> for instance:
>
> ######file mongo-start.sh####
> #!/bin/sh
> /usr/bin/mongod --config=/home/mongo/conf --fork --logpath /home/mongo/logfile &
> #####end file
>
>
> Running ./mongo-start.sh prodcues exactly the same result .... Sorry for
> being so ignorant, but what *should* I put in the script so that upon

> execution it does not require any further input in the terminal? Ideally
> it would also still print to the screen the message that it currently does.

Here's what happening:

(1) your shell forks and execs a new mongod process, and waits for that
process to exit.
(2) The new mongod process forks itself and exits.
(3) The shell now resumes and prints its prompt.
(4) The remaining mongod process prints some stuff as part of its
execution.

If you key in command into that terminal and hit enter, you should find
that the shell has been waiting for your input, even though the prompt
got lost somewhere. If you try connecting to the mongod from another
terminal, you should find that the mongod is running. If both of these
two things turn out to be the case, then we're just talking about a
goofy aesthetic issue. (Otherwise, something's really amiss.)

Regards,
Richard

Dan Yamins

unread,
Aug 4, 2010, 2:08:24 PM8/4/10
to mongod...@googlegroups.com

terminal, you should find that the mongod is running.  If both of these
two things turn out to be the case, then we're just talking about a
goofy aesthetic issue.  (Otherwise, something's really amiss.)


Richard, thanks for your email.  

So, you're correct that mongod IS running and that "enter" will release the prompt.

However, for my purposes it's NOT a goofy aesthetic issue.  In particular, I'm having mongod started by an automatic process that is triggered when new nodes are (automatically) added to my cluster (on amazon EC2).      The way this works is basically that a certain python script opens an ssh session to the EC2, and then executes the mongod start command over that ssh connection.   Whatever is causing "the prompt to get lost" is also causing this ssh connection to think that the command that I execute over it has not completed ... so it hangs.    There's no way I can "press enter" to get it to move forward.    This problem occurs whether or not the script runs the mongod start command from a script or at the prompt directly.

What I can do is use an "execute_async" method instead of "execute", so that the ssh connection doesn't wait for any response.   This is not great, since I'd really like to get the printed message from mongod command, so that it can be printed by the python script to a local log, so I can look back to see whether the start executed successfully (and get the PID of the mongod as well).   Alternatively -- and what I'm doing now -- is to execute the mongo command directing the output to a file, and then read that file remotely:

>>> ssh.execute("mongod --fork --logpath logfile > startlog")
>>> message = ssh.remote_file("startlog").read()

This works OK, but what I'd really like is the behavior to be like it was when I used mongo 1.2, where

>>> message = ssh.execute("mongod --fork --logpath logfile > startlog")

works fine, without hanging.   Is this difference in behavior between the dev version and 1.2 the fact that that "NOTE" is being printed?  And if so, is there some way to print this message without requiring a key press?

thanks!
Dan



Richard Kreuter

unread,
Aug 4, 2010, 5:39:20 PM8/4/10
to mongod...@googlegroups.com
Dan,

What Python library are you using for ssh? I wonder if it's doing
something odd. By inspection, this invocation returns straightaway:

$ ssh localhost 'mongod --logpath /tmp/mongod.log --fork > /tmp/start.log'

--
Richard

Dan Yamins writes:

> So, you're correct that mongod IS running and that "enter" will
> release the prompt.
>
> However, for my purposes it's NOT a goofy aesthetic issue. In particular,
> I'm having mongod started by an automatic process that is triggered when new
> nodes are (automatically) added to my cluster (on amazon EC2). The way
> this works is basically that a certain python script opens an ssh session to
> the EC2, and then executes the mongod start command over that ssh
> connection. Whatever is causing "the prompt to get lost" is also causing
> this ssh connection to think that the command that I execute over it has not
> completed ... so it hangs. There's no way I can "press enter" to get it
> to move forward. This problem occurs whether or not the script runs the
> mongod start command from a script or at the prompt directly.
>

> What I *can* do is use an "execute_async" method instead of "execute", so

Dan Yamins

unread,
Aug 5, 2010, 9:18:13 AM8/5/10
to mongod...@googlegroups.com
On Wed, Aug 4, 2010 at 5:39 PM, Richard Kreuter <ric...@10gen.com> wrote:
Dan,

What Python library are you using for ssh?  I wonder if it's doing
something odd.  By inspection, this invocation returns straightaway:

$ ssh localhost 'mongod --logpath /tmp/mongod.log --fork > /tmp/start.log'

I'm using what is (essentially) paramiko.    The object is subclassed from paramiko by a third-party library I'm using called "Starcluster", which (among other things) makes available ssh objects for each node in an amazon EC2 cluster.

thanks,
Dan

 

Dan Yamins

unread,
Aug 5, 2010, 9:20:54 AM8/5/10
to mongod...@googlegroups.com
On Thu, Aug 5, 2010 at 9:18 AM, Dan Yamins <dya...@gmail.com> wrote:


On Wed, Aug 4, 2010 at 5:39 PM, Richard Kreuter <ric...@10gen.com> wrote:
Dan,

What Python library are you using for ssh?  I wonder if it's doing
something odd.  By inspection, this invocation returns straightaway:


But I should also add, that something like this:
 
$ ssh localhost 'mongod --logpath /tmp/mongod.log --fork > /tmp/start.log'


also works for me (that's what I described in my previous email) -- if I direct the output to a file, like /tmp/start.log, then I'm OK.    I can read the file remotely to get a local copy of the startup output of mongod.   
 
Reply all
Reply to author
Forward
0 new messages